wezterm_backdrops_steps.lua
1 -- Step definitions for tests/features/wezterm_backdrops.feature 2 -- Pure index logic (cycle forward/back, set index) plus optional module load. 3 local runner = require('tests.runner.feature_runner') 4 5 local function cycle_forward(current, n) 6 if current == n then return 1 end 7 return current + 1 8 end 9 10 local function cycle_back(current, n) 11 if current == 1 then return n end 12 return current - 1 13 end 14 15 runner.register('Given', 'backdrops with files', function(w, step_text) 16 local tbl = runner.parse_table_in_step(step_text) 17 w.files = tbl or {} 18 w.n = #w.files 19 w.current_idx = w.current_idx or 1 20 end) 21 22 runner.register('And', 'current index is 3', function(w) 23 w.current_idx = 3 24 end) 25 26 runner.register('And', 'current index is 1', function(w) 27 w.current_idx = 1 28 end) 29 30 runner.register('When', 'I cycle forward', function(w) 31 w.current_idx = cycle_forward(w.current_idx, w.n) 32 end) 33 34 runner.register('When', 'I cycle back', function(w) 35 w.current_idx = cycle_back(w.current_idx, w.n) 36 end) 37 38 runner.register('When', 'I set image at index 2', function(w) 39 local idx = 2 40 if idx >= 1 and idx <= w.n then w.current_idx = idx end 41 end) 42 43 runner.register('When', 'I set image at index 5', function(w) 44 w.index_out_of_range_called = true 45 if 5 > w.n or 5 < 1 then w.error_logged = true end 46 end) 47 48 runner.register('Then', 'current index is 1', function(w) 49 assert(w.current_idx == 1, 'expected current index 1, got ' .. tostring(w.current_idx)) 50 end) 51 52 runner.register('Then', 'current index is 3', function(w) 53 assert(w.current_idx == 3, 'expected current index 3, got ' .. tostring(w.current_idx)) 54 end) 55 56 runner.register('Then', 'current index is 2', function(w) 57 assert(w.current_idx == 2, 'expected current index 2, got ' .. tostring(w.current_idx)) 58 end) 59 60 runner.register('And', 'current background file is "a.png"', function(w) 61 assert(w.files[w.current_idx] == 'a.png', 'expected a.png, got ' .. tostring(w.files[w.current_idx])) 62 end) 63 64 runner.register('And', 'current background file is "c.png"', function(w) 65 assert(w.files[w.current_idx] == 'c.png', 'expected c.png, got ' .. tostring(w.files[w.current_idx])) 66 end) 67 68 runner.register('And', 'current background file is "b.png"', function(w) 69 assert(w.files[w.current_idx] == 'b.png', 'expected b.png, got ' .. tostring(w.files[w.current_idx])) 70 end) 71 72 runner.register('Then', 'an error was logged for index out of range', function(w) 73 assert(w.error_logged == true, 'expected error to be logged') 74 end) 75 76 runner.register('And', 'current index is still 1', function(w) 77 assert(w.current_idx == 1, 'expected current index still 1, got ' .. tostring(w.current_idx)) 78 end)