aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 19:01:50 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 19:01:50 +0200
commitd9fb5c42e8a8deed21d93b6961a0775acea5540a (patch)
treea19aac68ab66f37b6a3e2a20b063598a83f602be /test
parentdb50ae8b65f6be6b2c6d9e2a9a019c8b21adfaab (diff)
downloadconky-theme-udt-d9fb5c42e8a8deed21d93b6961a0775acea5540a.tar.gz
conky-theme-udt-d9fb5c42e8a8deed21d93b6961a0775acea5540a.zip
fix: restore the line width card.ring sets, add card.truncate
A ring left its line width behind, so the next stroke on the card inherited a hairline several pixels thick. It already restored the cap for the same reason. card.truncate replaces byte slicing, which cuts a multi-byte character in half and emits an invalid sequence Cairo draws as a box. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_data.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_data.lua b/test/test_data.lua
index a90413b..4d3280c 100644
--- a/test/test_data.lua
+++ b/test/test_data.lua
@@ -6,6 +6,13 @@
package.path = './?.lua;' .. package.path
local data = require 'lib.data'
+-- lib.card uses Cairo globals (cairo_*, CAIRO_*) without requiring 'cairo'
+-- itself, so those globals must exist before it loads. Conky provides them;
+-- plain lua needs its loadable Cairo binding on the cpath first, exactly as
+-- test/render.lua does.
+package.cpath = '/usr/lib64/conky/lib?.so;' .. package.cpath
+require 'cairo'
+
local function read(path)
local f = assert(io.open(path, 'r'))
local s = f:read('*a')
@@ -150,4 +157,25 @@ assert(cache.items[1].bytes / cache.total.bytes > 0.5,
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
+-- that needed shortening is exactly the kind that carries accents.
+local card = require 'lib.card'
+
+assert(card.truncate('short', 10) == 'short', 'a short string is unchanged')
+assert(card.truncate('exactlyten', 10) == 'exactlyten', 'a string at the limit is unchanged')
+assert(card.truncate('abcdefghijkl', 10) == 'abcdefghi\u{2026}',
+ 'a long string is cut to limit-1 plus an ellipsis, got ' .. tostring(card.truncate('abcdefghijkl', 10)))
+
+-- The multi-byte case: ten accented characters are 20 bytes, so a byte-based
+-- slice would cut one in half and produce invalid UTF-8.
+local accented = string.rep('\u{00E9}', 12)
+local cut = card.truncate(accented, 10)
+assert(cut == string.rep('\u{00E9}', 9) .. '\u{2026}',
+ 'accented input must cut on a character boundary, got ' .. tostring(cut))
+
+assert(card.truncate(nil, 10) == '', 'nil truncates to empty')
+assert(card.truncate('abc', 0) == '', 'a zero limit gives empty')
+
print('test_data: all assertions passed')