tests.lua

changeset 0
44416491923e
child 2
bb0892bc9687
equal deleted inserted replaced
-1:000000000000 0:44416491923e
1 local when = require "ndp".when;
2
3 if not when then
4 print("No 'when' function ?!");
5 end
6
7 local all_ok = true;
8
9 local function check(input, output)
10 local ret = when(input, 0);
11 if ret ~= output then
12 print("FAIL: "..input.." [produces "..ret.."/"..os.date("!%c", ret).."]");
13 all_ok = false;
14 return false;
15 end
16 end
17
18 check("today", 0);
19 check("tomorrow", 86400);
20 check("tomorrow morning", 117000);
21 check("tomorrow noon", 126000);
22 check("tomorrow afternoon", 131400);
23 check("tomorrow evening", 145800);
24 check("tomorrow midnight", 82800); -- Correct, but expected? :)
25
26 check("in 1 hour", 3600);
27 check("in an hour", 3600);
28 check("in 2 hours", 7200);
29 check("in a couple of hours", 7200);
30 check("in 3 hours", 10800);
31 check("in a few hours", 10800);
32
33 check("in a day", 86400);
34 check("in 2 days", 172800);
35 check("in a couple of days", 172800);
36 check("in 3 days", 259200);
37 check("in a few days", 259200);
38
39 check("next week", 604800);
40 check("next year", 31536000);
41
42 if all_ok then
43 print("OK");
44 end

mercurial