diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/fixtures/breaktimer_cache | 6 | ||||
| -rw-r--r-- | test/test_data.lua | 62 |
2 files changed, 0 insertions, 68 deletions
diff --git a/test/fixtures/breaktimer_cache b/test/fixtures/breaktimer_cache deleted file mode 100644 index 23a147a..0000000 --- a/test/fixtures/breaktimer_cache +++ /dev/null @@ -1,6 +0,0 @@ -generated 1758200000 -running yes -state running -phase working -remain 1471 -frozen no diff --git a/test/test_data.lua b/test/test_data.lua index 01a55cc..c33e5ae 100644 --- a/test/test_data.lua +++ b/test/test_data.lua @@ -125,68 +125,6 @@ assert(ndays == 30 and first == 2, 'september 2026, got ' .. ndays .. '/' .. fir assert((data.month_shape(2024, 2)) == 29, 'leap february has 29 days') assert((data.month_shape(2026, 12)) == 31, 'december rolls over correctly') --- === breaktimer =========================================================== --- The phase-to-word and phase-to-colour decisions live in breaktimer_parse so --- they can be checked here; the card only draws the result. -local bt = data.breaktimer_parse(read('test/fixtures/breaktimer_cache')) -assert(bt, 'breaktimer cache parses') -assert(bt.countdown == '24:31', 'countdown, got ' .. tostring(bt.countdown)) -assert(bt.phase_label == 'working', 'phase label, got ' .. tostring(bt.phase_label)) -assert(bt.next == 'pausa', 'next during work is a break, got ' .. tostring(bt.next)) -assert(bt.role == 'ok', 'working is ok, got ' .. tostring(bt.role)) - --- Every phase has its own word and colour role. Build caches rather than files: --- the sampler's output is six plain lines and the parse is the seam that --- matters. -local function bt_cache(fields) - local out = { 'generated 1', 'running ' .. (fields.running or 'yes'), - 'state ' .. (fields.state or 'running'), - 'phase ' .. (fields.phase or 'working'), - 'remain ' .. (fields.remain or 60), - 'frozen ' .. (fields.frozen or 'no') } - return table.concat(out, '\n') .. '\n' -end - -local b - -b = data.breaktimer_parse(bt_cache({ phase = 'breaking', remain = 125 })) -assert(b.phase_label == 'micro-pausa' and b.role == 'heading' and b.next == 'lavoro', - 'micro-pause: ' .. b.phase_label .. '/' .. b.role .. '/' .. b.next) -assert(b.countdown == '2:05', 'micro-pause countdown, got ' .. b.countdown) - -b = data.breaktimer_parse(bt_cache({ phase = 'longbreak', remain = 600 })) -assert(b.phase_label == 'pausa lunga' and b.role == 'highlight' and b.next == 'lavoro', - 'long pause: ' .. b.phase_label .. '/' .. b.role) - --- Paused freezes the number, but the phase underneath still decides what the --- countdown leads to. -b = data.breaktimer_parse(bt_cache({ state = 'paused', phase = 'working' })) -assert(b.phase_label == 'in pausa' and b.role == 'warning' and b.next == 'pausa', - 'paused: ' .. b.phase_label .. '/' .. b.role .. '/' .. b.next) - --- Frozen: the clock stopped while the phase stayed 'working'. Outside working --- hours, or a hung daemon; both read the same. -b = data.breaktimer_parse(bt_cache({ frozen = 'yes' })) -assert(b.phase_label == 'outside working hours' and b.role == 'label', - 'frozen: ' .. b.phase_label .. '/' .. b.role) -assert(b.next == 'pausa', 'frozen working still leads to a break') - --- A dead daemon: the sampler's liveness check sets running no even when the --- state file was left saying running. -b = data.breaktimer_parse(bt_cache({ running = 'no' })) -assert(b.countdown == '--' and b.phase_label == 'fermo' and b.next == '--' - and b.role == 'label', 'stopped reads as fermo, got ' .. b.phase_label) - --- A negative remain must clamp, not print '-1:59'. -b = data.breaktimer_parse(bt_cache({ remain = -5 })) -assert(b.countdown == '0:00', 'negative remain clamps, got ' .. b.countdown) - --- No 'generated' key means the sampler never ran, which is different from a --- stopped daemon (which still writes a cache). -assert(data.breaktimer_parse('running no\n') == nil, 'no generated key: nil') -assert(data.breaktimer_parse('') == nil, 'empty cache: nil') -assert(data.breaktimer_parse(nil) == nil, 'nil cache: nil') - -- immich_parse: one entry per photo line, place optional, garbage skipped. local im = data.immich_parse(read('test/fixtures/immich_index')) assert(im and #im == 3, 'immich photo count, got ' .. tostring(im and #im)) |
