aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_data.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 19:08:13 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 19:08:13 +0200
commit9b18e17eee451a9a900f792add2c4c2eeb2af533 (patch)
tree7466a0953c5a4c9d7b3200723baf4d21a9bf225d /test/test_data.lua
parentf1be1bef9c3563fd78f811f54e5a64b1d993e4da (diff)
downloadconky-theme-udt-9b18e17eee451a9a900f792add2c4c2eeb2af533.tar.gz
conky-theme-udt-9b18e17eee451a9a900f792add2c4c2eeb2af533.zip
feat: parse the CPU and motherboard model strings
Stripping by rule rather than by a table of known parts: a leading vendor word, trademark noise, a trailing core count or clock. The Intel fixture exists to keep it a rule. DMI placeholders read as no board at all. 'To Be Filled By O.E.M.' on the dashboard is worse than a blank row. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'test/test_data.lua')
-rw-r--r--test/test_data.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/test_data.lua b/test/test_data.lua
index fdf0e2f..3e741e6 100644
--- a/test/test_data.lua
+++ b/test/test_data.lua
@@ -239,4 +239,39 @@ 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')
+-- === Hardware identification ==============================================
+-- Both strings are constant for the machine's life, so the widget memoizes
+-- them. What is tested here is the stripping, which must be a rule rather
+-- than a special case for one host: the Intel fixture exists to prove it.
+assert(data.cpu_model(read('test/fixtures/proc_cpuinfo')) == 'Ryzen 7 9700X',
+ 'amd cpu, got ' .. tostring(data.cpu_model(read('test/fixtures/proc_cpuinfo'))))
+assert(data.cpu_model(read('test/fixtures/proc_cpuinfo_intel')) == 'Core i7-8700K',
+ 'intel cpu, got ' .. tostring(data.cpu_model(read('test/fixtures/proc_cpuinfo_intel'))))
+
+-- Unparseable input yields nil, so the card shows nothing rather than a
+-- half-stripped string.
+assert(data.cpu_model('') == nil, 'empty cpuinfo gives nil')
+assert(data.cpu_model(nil) == nil, 'nil cpuinfo gives nil')
+assert(data.cpu_model('processor\t: 0\n') == nil, 'cpuinfo with no model name gives nil')
+
+-- The board is two sysfs files joined, with the vendor's corporate suffix
+-- dropped: it is boilerplate on every board and costs a third of the row.
+assert(data.board_name('Gigabyte Technology Co., Ltd.\n', 'X870 EAGLE WIFI7\n')
+ == 'Gigabyte X870 EAGLE WIFI7',
+ 'board, got ' .. tostring(data.board_name('Gigabyte Technology Co., Ltd.\n', 'X870 EAGLE WIFI7\n')))
+assert(data.board_name('ASUSTeK COMPUTER INC.\n', 'PRIME B650-PLUS\n')
+ == 'ASUSTeK PRIME B650-PLUS',
+ 'asus board, got ' .. tostring(data.board_name('ASUSTeK COMPUTER INC.\n', 'PRIME B650-PLUS\n')))
+
+-- A machine that reports one and not the other shows what it has.
+assert(data.board_name(nil, 'X870 EAGLE WIFI7\n') == 'X870 EAGLE WIFI7',
+ 'name alone, got ' .. tostring(data.board_name(nil, 'X870 EAGLE WIFI7\n')))
+assert(data.board_name('Gigabyte\n', nil) == 'Gigabyte', 'vendor alone')
+assert(data.board_name(nil, nil) == nil, 'neither gives nil')
+
+-- A virtual machine reports placeholder DMI strings. Showing 'To be filled by
+-- O.E.M.' as the motherboard is worse than showing nothing.
+assert(data.board_name('To Be Filled By O.E.M.\n', 'To Be Filled By O.E.M.\n') == nil,
+ 'placeholder DMI gives nil')
+
print('test_data: all assertions passed')