aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_weather.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-18 14:44:56 +0200
committerDanilo M. <danix@danix.xyz>2026-10-18 14:44:56 +0200
commit1d8b815d10e33b53c4e7d3f2668b3529a6e11c22 (patch)
treec0a47f416d58a8c246232e29159eb0d98b7fbddd /test/test_weather.lua
parentb492fbb4011cc7890b6b218553809e247f506b71 (diff)
downloadconky-theme-udt-1d8b815d10e33b53c4e7d3f2668b3529a6e11c22.tar.gz
conky-theme-udt-1d8b815d10e33b53c4e7d3f2668b3529a6e11c22.zip
fix(weather): drop non-finite numbers at parse, add clock()
Parse now rejects inf and NaN fields, clock() wraps os.date so odd epochs read '--', age_str returns '--' for bad input, duration loses a redundant guard. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/test_weather.lua')
-rw-r--r--test/test_weather.lua21
1 files changed, 19 insertions, 2 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua
index e7d7614..2a77b43 100644
--- a/test/test_weather.lua
+++ b/test/test_weather.lua
@@ -76,7 +76,8 @@ for _, bad in ipairs({ NAN, INF, -INF, 1e300, math.maxinteger }) do
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.age_str(NAN, 0) == '--', 'NaN age is --')
+assert(weather.age_str(math.huge, 0) == '--', 'infinite dt is --')
assert(weather.num(77) == '77', 'plain number')
assert(weather.num(39.6, '%') == '40%', 'rounded with suffix')
@@ -206,6 +207,22 @@ assert(weather.age_str(1000, 1000 + 12 * 60) == '12m', 'minutes')
assert(weather.age_str(1000, 1000 + 3 * 3600) == '3h', 'hours')
assert(weather.age_str(1000, 1000 + 2 * 86400) == '2d', 'days')
assert(weather.age_str(2000, 1000) == '0m', 'a future dt reads as 0m')
-assert(weather.age_str(nil, 1000) == '?', 'missing dt')
+assert(weather.age_str(nil, 1000) == '--', 'missing dt')
+assert(weather.age_str(1000, nil) == '--', 'missing now')
+
+-- === Non-finite numbers at parse ==========================================
+-- tonumber('1e999') is inf; a reader that lets it through feeds %d and
+-- os.date, which raise.
+local fx = slurp('test/fixtures/weather.txt')
+assert(weather.parse((fx:gsub('current\t(%d+)\t[^\t]*', 'current\t%1\t1e999', 1))) == nil,
+ 'an infinite current temp is no temp, and temp is required')
+local inf_hour = weather.parse((fx:gsub('hour\t(%d+)\t[^\t]*', 'hour\t%1\t-1e999', 1)))
+assert(inf_hour and inf_hour.hours[1].temp == nil, 'an infinite hour temp is nil')
+
+-- === clock ================================================================
+assert(weather.clock(1.5) == '--', 'float epoch raises in os.date, so --')
+assert(weather.clock(1e17) == '--', 'huge epoch raises in os.date, so --')
+assert(weather.clock(nil) == '--', 'missing epoch')
+assert(weather.clock(0, '%H:%M') == os.date('%H:%M', 0), 'clock formats')
print('test_weather: all assertions passed')