tests.lua

changeset 0
44416491923e
child 2
bb0892bc9687
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests.lua	Sun Jun 21 17:42:50 2009 +0100
@@ -0,0 +1,44 @@
+local when = require "ndp".when;
+
+if not when then
+	print("No 'when' function ?!");
+end
+
+local all_ok = true;
+
+local function check(input, output)
+	local ret = when(input, 0);
+	if ret ~= output then
+		print("FAIL: "..input.." [produces "..ret.."/"..os.date("!%c", ret).."]");
+		all_ok = false;
+		return false;
+	end
+end
+
+check("today", 0);
+check("tomorrow", 86400);
+check("tomorrow morning", 117000);
+check("tomorrow noon", 126000);
+check("tomorrow afternoon", 131400);
+check("tomorrow evening", 145800);
+check("tomorrow midnight", 82800); -- Correct, but expected? :)
+
+check("in 1 hour", 3600);
+check("in an hour", 3600);
+check("in 2 hours", 7200);
+check("in a couple of hours", 7200);
+check("in 3 hours", 10800);
+check("in a few hours", 10800);
+
+check("in a day", 86400);
+check("in 2 days", 172800);
+check("in a couple of days", 172800);
+check("in 3 days", 259200);
+check("in a few days", 259200);
+
+check("next week", 604800);
+check("next year", 31536000);
+
+if all_ok then
+	print("OK");
+end

mercurial