aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-18 14:30:54 +0200
committerDanilo M. <danix@danix.xyz>2026-10-18 14:30:54 +0200
commit57d52f2133edb97031fa578528cfce6717108654 (patch)
tree734b4319723b9848008400e3f191126b04952731 /test
parent13593649ac7086c451dd9c736b8dfd9de81f3406 (diff)
downloadconky-theme-udt-57d52f2133edb97031fa578528cfce6717108654.tar.gz
conky-theme-udt-57d52f2133edb97031fa578528cfce6717108654.zip
fix(weather): non-finite numbers no longer raise
deg, num, duration and moon_icon now return their missing-value placeholder for NaN, inf and out-of-range input instead of raising from %d or utf8.char. sun_t clamps NaN to 0 and age_str returns ? for a NaN age. Drops the dead -0 fold in deg and fixes a mislabelled assertion. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_weather.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua
index cea4645..e7d7614 100644
--- a/test/test_weather.lua
+++ b/test/test_weather.lua
@@ -64,9 +64,20 @@ assert(weather.describe(nil) == 'Unknown', 'nil code words')
assert(weather.deg(13.2) == '13\u{00B0}', 'rounds down')
assert(weather.deg(13.5) == '14\u{00B0}', 'rounds half up')
assert(weather.deg(-0.4) == '0\u{00B0}', 'just below zero reads 0')
-assert(weather.deg(-2.6) == '-3\u{00B0}', 'negative rounds away from zero')
+assert(weather.deg(-2.6) == '-3\u{00B0}', 'negative rounds to nearest')
assert(weather.deg(nil) == '--', 'missing temperature is --, never 0')
+-- Non-finite input must not raise (1e999 parses to inf from a cache line).
+local NAN, INF = 0/0, math.huge
+for _, bad in ipairs({ NAN, INF, -INF, 1e300, math.maxinteger }) do
+ assert(weather.deg(bad) == '--', 'deg non-finite ' .. tostring(bad))
+ assert(weather.num(bad) == '--', 'num non-finite ' .. tostring(bad))
+ assert(weather.duration(bad) == '--', 'duration non-finite ' .. tostring(bad))
+ assert(weather.moon_icon(bad) == weather.ICON.unknown, 'moon_icon non-finite ' .. tostring(bad))
+end
+assert(weather.sun_t(NAN, 1000, 2000) == 0, 'NaN now parks at 0')
+assert(weather.age_str(NAN, 0) == '?', 'NaN age is ?')
+
assert(weather.num(77) == '77', 'plain number')
assert(weather.num(39.6, '%') == '40%', 'rounded with suffix')
assert(weather.num(0, '%') == '0%', 'zero is a real reading')