diff options
Diffstat (limited to 'test/test_data.lua')
| -rw-r--r-- | test/test_data.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_data.lua b/test/test_data.lua index 1b6c580..fdf0e2f 100644 --- a/test/test_data.lua +++ b/test/test_data.lua @@ -218,4 +218,25 @@ r5:sample(1000, 100) assert(r5:sample(3048, 100) == 2048 / 5, 'an explicit fallback interval must be used, got ' .. tostring(r5:sample(3048, 100))) +-- === kv_parse ============================================================= +-- The slackware sampler writes 'key value' lines. The format is deliberately +-- dumber than the data: epochs stay integers rather than becoming formatted +-- dates, so the widget decides how to render an age and the shell never +-- reconstructs a date string. +local kv = data.kv_parse(read('test/fixtures/slackware_cache')) +assert(kv.version == 'Slackware 15.0+', 'version, got ' .. tostring(kv.version)) +-- The value keeps its internal spaces: only the FIRST space is the separator. +assert(kv.packages == '1234', 'packages, got ' .. tostring(kv.packages)) +assert(kv.changelog == '1758000000', 'changelog, got ' .. tostring(kv.changelog)) +assert(kv.kernel == '6.12.1', 'kernel, got ' .. tostring(kv.kernel)) + +-- A key the sampler did not write reads nil, which is how the widget tells +-- "the sampler ran but this fact was unavailable" from "no sampler". +assert(kv.nonexistent == nil, 'a missing key is nil') + +-- Malformed input must not raise: a Lua error in conky is a blank screen. +assert(type(data.kv_parse('')) == 'table', 'empty input gives a table') +assert(type(data.kv_parse(nil)) == 'table', 'nil gives a table') +assert(data.kv_parse('keyonly\n').keyonly == nil, 'a line with no value is skipped') + print('test_data: all assertions passed') |
