diff options
Diffstat (limited to 'test/test_weather.lua')
| -rw-r--r-- | test/test_weather.lua | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua index 4ea953f..739161b 100644 --- a/test/test_weather.lua +++ b/test/test_weather.lua @@ -196,4 +196,16 @@ assert(weather.parse(nil) == nil, 'nil input gives nil') assert(weather.parse('{"cod":401,"message":"Invalid API key."}') == nil, 'an API error body must give nil') +-- Negative temperatures are ordinary here for half the year, and a number in +-- exponent form must not be truncated at the 'e': reading 1.8e1 as 1.8 would +-- draw 2 degrees instead of 18, wrong in a way that still looks like weather. +local cold = weather.parse( + '{"weather":[{"id":600,"description":"snow"}],"main":{"temp":-12.5},' .. + '"sys":{"sunrise":100,"sunset":200},"name":"X","dt":150}') +assert(cold and cold.temp == -12.5, 'a negative temp, got ' .. tostring(cold and cold.temp)) +local exp = weather.parse( + '{"weather":[{"id":800}],"main":{"temp":1.8e1},' .. + '"sys":{"sunrise":100,"sunset":200}}') +assert(exp and exp.temp == 18, 'exponent form, got ' .. tostring(exp and exp.temp)) + print('test_weather: all assertions passed') |
