aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--tests/config.nims1
-rw-r--r--tests/tconditions.nim16
-rw-r--r--tests/tests.nim1
-rw-r--r--tests/ttypechecker.nim77
5 files changed, 98 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 66126ea..83f77d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
then
-tests/
-!tests/*.nim?
+/tests/*
+!/tests/*.nim
+!/tests/*.nims
diff --git a/tests/config.nims b/tests/config.nims
new file mode 100644
index 0000000..80091ff
--- /dev/null
+++ b/tests/config.nims
@@ -0,0 +1 @@
+switch("path", "$projectDir/../src")
diff --git a/tests/tconditions.nim b/tests/tconditions.nim
new file mode 100644
index 0000000..4732546
--- /dev/null
+++ b/tests/tconditions.nim
@@ -0,0 +1,16 @@
+import then/conditions
+import std/[unittest]
+import std/[times]
+
+let date1 = dateTime(2025, mJan, 01, 00, 00, 00, 00, utc())
+let date2 = dateTime(2025, mJan, 01, 00, 00, 00, 00, local())
+let date3 = dateTime(2025, mDec, 31, 00, 00, 00, 00, utc())
+let date4 = dateTime(2024, mFeb, 29, 00, 00, 00, 00, local())
+let date5 = dateTime(0001, mJan, 01, 00, 00, 00, 00, local())
+let date6 = dateTime(9999, mDec, 31, 00, 00, 00, 00, local())
+
+
+test "Time (always true)":
+ check checkCond("00:00", date1) == true
+ check checkCond("23:59", date2) == true
+ check checkCond("25:00", date3) == true
diff --git a/tests/tests.nim b/tests/tests.nim
new file mode 100644
index 0000000..5b7f865
--- /dev/null
+++ b/tests/tests.nim
@@ -0,0 +1 @@
+include "tconditions.nim"
diff --git a/tests/ttypechecker.nim b/tests/ttypechecker.nim
new file mode 100644
index 0000000..ee81fc4
--- /dev/null
+++ b/tests/ttypechecker.nim
@@ -0,0 +1,77 @@
+import then/typechecker
+import std/[unittest]
+
+test "Testing typechecker":
+ for t in ["2024","0001","9999"]:
+ check checkType(t) == "year"
+
+ for t in ["01","1","31"]:
+ check checkType(t) == "day"
+
+ for t in ["1w","1W","9W"]:
+ check checkType(t) == "firstweek"
+
+ for t in ["1l","1L","9L"]:
+ check checkType(t) == "lastweek"
+
+ for t in [
+ "(jan 1 2024)",
+ "(Jan 31 2024)",
+ "(January 1 2024)",
+ "(2024 1 jan)",
+ "(1 jan 2024)",
+ "(jan 1)",
+ "(jan 31)",
+ "(january 1)"]:
+ check checkType(t) == "dategroup"
+
+ for t in ["2024-2025","0000-9999"]:
+ check checkType(t) == "rangeyear"
+
+ for t in ["1-2","01-2","01-02","1-02","1-31","10-31"]:
+ check checkType(t) == "rangeday"
+
+ for t in [
+ "00:00",
+ "23:23",
+ "00:00",
+ "23:00",
+ "01:00-12:30",
+ "1:30-12:30",
+ "1am",
+ "1pm",
+ "1AM",
+ "1PM",
+ "1am-2pm",
+ "1PM-2PM",
+ "1:00pm-2:00pm",
+ "12:00am-12:00pm"]:
+ check checkType(t) == "time"
+
+ for t in [
+ "j%2",
+ "J%2",
+ "J%999",
+ "j%2+1",
+ "j%2-1",
+ "(j%2-1)",
+ "(j % 2 - 1)"]:
+ check checkType(t) == "julian"
+
+ for t in ["Jan","jan","JANUARY","JAN","jAN"]:
+ check checkType(t) == "month"
+
+ for t in ["Mon","mon","MONDAY","MON","mON"]:
+ check checkType(t) == "weekday"
+
+ for t in ["jan-feb","JAN-FEB","Jan-Feb","january-february"]:
+ check checkType(t) == "rangemonth"
+
+ for t in ["mon-tue","MON-TUE","Mon-Tue","monday-tuesday"]:
+ check checkType(t) == "rangeweekday"
+
+ for t in ["(Jan 31 2024)-(Feb 2 2024)","(2024 1 december)-(2025 2 january)"]:
+ check checkType(t) == "rangedategroup"
+
+ for t in ["!@#$","foo",""]:
+ check checkType(t) == "unknown"