diff options
Diffstat (limited to 'test/test_weather.lua')
| -rw-r--r-- | test/test_weather.lua | 21 |
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') |
