aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_data.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_data.lua')
-rw-r--r--test/test_data.lua38
1 files changed, 4 insertions, 34 deletions
diff --git a/test/test_data.lua b/test/test_data.lua
index df6775b..9066241 100644
--- a/test/test_data.lua
+++ b/test/test_data.lua
@@ -20,30 +20,6 @@ local function read(path)
return s
end
--- === Cache files ==========================================================
--- du -sh: total first, then children largest-first. The suffixes must be
--- converted, not string-sorted: '1.1G' outranks '245M' numerically and loses
--- to it alphabetically.
-local cache = data.du_parse(read('test/fixtures/du_output'))
-assert(cache.total, 'a total is parsed')
-assert(cache.total.label == '1.6G', 'total label, got ' .. tostring(cache.total.label))
-assert(#cache.items == 4, 'four children, got ' .. tostring(#cache.items))
-assert(cache.items[1].name == 'mozilla', 'largest child, got ' .. tostring(cache.items[1].name))
-assert(cache.items[1].label == '1.1G', 'its label, got ' .. tostring(cache.items[1].label))
-assert(cache.items[2].name == 'pip', 'second child, got ' .. tostring(cache.items[2].name))
-
--- Sizes are compared as bytes, which is what makes 'biggest' meaningful.
-assert(cache.items[1].bytes > cache.items[2].bytes, '1.1G must outrank 245M')
-assert(cache.items[1].bytes > 1e9, 'a G suffix is about a billion bytes')
-assert(cache.items[4].bytes < 1e8, 'an M suffix is far smaller')
-
--- Share of the total drives the highlight colour.
-assert(cache.items[1].bytes / cache.total.bytes > 0.5,
- 'mozilla dominates this fixture, which is what the highlight keys on')
-
-assert(data.du_parse('') == nil, 'empty input gives nil')
-assert(data.du_parse(nil) == nil, 'nil gives nil')
-
-- === card.truncate ========================================================
-- Truncation is by CHARACTER, not byte: slicing a UTF-8 string mid-sequence
-- emits an invalid byte that Cairo draws as a replacement box, and the name
@@ -66,16 +42,10 @@ assert(card.truncate(nil, 10) == '', 'nil truncates to empty')
assert(card.truncate('abc', 0) == '', 'a zero limit gives empty')
-- === 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))
+-- Samplers write 'key value' lines; only the FIRST space is the separator.
+local kv = data.kv_parse('title Long break\nremain 125\n')
+assert(kv.title == 'Long break', 'value keeps its spaces, got ' .. tostring(kv.title))
+assert(kv.remain == '125', 'remain, got ' .. tostring(kv.remain))
-- 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".