aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/tcolumnize.nim15
-rw-r--r--tests/tparsetime.nim99
2 files changed, 63 insertions, 51 deletions
diff --git a/tests/tcolumnize.nim b/tests/tcolumnize.nim
index 0e8e1c8..15f0171 100644
--- a/tests/tcolumnize.nim
+++ b/tests/tcolumnize.nim
@@ -3,6 +3,17 @@ import std/[unittest]
test "Testing columnize":
var table = newSeq[Line]()
- table.add(Line(columns: @["Jan 1", "(OVERDUE)", "Do the thing"], attachments: @[]))
- table.add(Line(columns: @["Feb 22", "(Due in 24 days)", "Do that other thing"], attachments: @[]))
+
+ table.add(Line(columns: @[
+ Column(text: "Jan 1", color: fgWhite),
+ Column(text: "(OVERDUE)", color: fgRed),
+ Column(text: "Do the thing", color: fgBlue)
+ ], attachments: @[]))
+
+ table.add(Line(columns: @[
+ Column(text: "Feb 22", color: fgWhite),
+ Column(text: "(Due in 24 days)", color: fgGreen),
+ Column(text: "Do that other thing", color: fgBlue)
+ ], attachments: @[]))
+
columnize.echo(table)
diff --git a/tests/tparsetime.nim b/tests/tparsetime.nim
index d60a5fa..aeb1b37 100644
--- a/tests/tparsetime.nim
+++ b/tests/tparsetime.nim
@@ -4,57 +4,58 @@ import std/[times]
# Everything has +1.days to easily sort all-day events before scheduled ones
-test "Parse single times":
- check toDateTime("9") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9:00") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9:30") == parse("0930", "HHmm", utc()) + 1.days
- check toDateTime("09:00") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("09:30") == parse("0930", "HHmm", utc()) + 1.days
- check toDateTime("9:00am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9:30pm") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("09:00am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("09:00pm") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("09:30am") == parse("0930", "HHmm", utc()) + 1.days
- check toDateTime("09:30pm") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("17") == parse("1700", "HHmm", utc()) + 1.days
- check toDateTime("24") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("17:00") == parse("1700", "HHmm", utc()) + 1.days
- check toDateTime("12:00") == parse("1200", "HHmm", utc()) + 1.days
- check toDateTime("24:00") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("00:00") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("01:00") == parse("0100", "HHmm", utc()) + 1.days
-
+proc expectedTime(time: string): DateTime =
+ parse(time, "HHmm", utc()) + 1.days
+test "Parse valid single time formats":
+ check toDateTime("9") == expectedTime("0900")
+ check toDateTime("9am") == expectedTime("0900")
+ check toDateTime("9:00") == expectedTime("0900")
+ check toDateTime("9:30") == expectedTime("0930")
+ check toDateTime("09:00") == expectedTime("0900")
+ check toDateTime("09:30") == expectedTime("0930")
+ check toDateTime("9:00am") == expectedTime("0900")
+ check toDateTime("9:30pm") == expectedTime("2130")
+ check toDateTime("09:00am") == expectedTime("0900")
+ check toDateTime("09:00pm") == expectedTime("2100")
+ check toDateTime("09:30am") == expectedTime("0930")
+ check toDateTime("09:30pm") == expectedTime("2130")
+ check toDateTime("17") == expectedTime("1700")
+ check toDateTime("24") == expectedTime("0000")
+ check toDateTime("17:00") == expectedTime("1700")
+ check toDateTime("12:00") == expectedTime("1200")
+ check toDateTime("24:00") == expectedTime("0000")
+ check toDateTime("00:00") == expectedTime("0000")
+ check toDateTime("01:00") == expectedTime("0100")
test "Parse time ranges":
- check toDateTime("9am-1am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9:00am-1:00am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9:30pm-01:00am") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("09:00am-01:00am") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("09:00pm-01:00am") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("09:30am-01:30am") == parse("0930", "HHmm", utc()) + 1.days
- check toDateTime("09:30pm-01:30am") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("11:00-13:00") == parse("1100", "HHmm", utc()) + 1.days
- check toDateTime("12:00-13:00") == parse("1200", "HHmm", utc()) + 1.days
- check toDateTime("11:00-24:00") == parse("1100", "HHmm", utc()) + 1.days
- check toDateTime("23:00-24:00") == parse("2300", "HHmm", utc()) + 1.days
- check toDateTime("24:00-23:00") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("9pm-12am") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("17-1am") == parse("1700", "HHmm", utc()) + 1.days
- check toDateTime("9-1am") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("9:00-1:00am") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("9:30-1:30am") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("09:00-01:00am") == parse("2100", "HHmm", utc()) + 1.days
- check toDateTime("09:30-01:30am") == parse("2130", "HHmm", utc()) + 1.days
- check toDateTime("17:00-1:00am") == parse("1700", "HHmm", utc()) + 1.days
- check toDateTime("12:00-1:00am") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("12-1:00am") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("00:00-01:00am") == parse("0000", "HHmm", utc()) + 1.days
- check toDateTime("11-12pm") == parse("1100", "HHmm", utc()) + 1.days
- check toDateTime("11-12am") == parse("2300", "HHmm", utc()) + 1.days
- check toDateTime("11-12") == parse("1100", "HHmm", utc()) + 1.days
- check toDateTime("9-1700") == parse("0900", "HHmm", utc()) + 1.days
- check toDateTime("9-1100") == parse("0900", "HHmm", utc()) + 1.days
+ check toDateTime("9am-1am") == expectedTime("0900")
+ check toDateTime("9:00am-1:00am") == expectedTime("0900")
+ check toDateTime("9:30pm-01:00am") == expectedTime("2130")
+ check toDateTime("09:00am-01:00am") == expectedTime("0900")
+ check toDateTime("09:00pm-01:00am") == expectedTime("2100")
+ check toDateTime("09:30am-01:30am") == expectedTime("0930")
+ check toDateTime("09:30pm-01:30am") == expectedTime("2130")
+ check toDateTime("11:00-13:00") == expectedTime("1100")
+ check toDateTime("12:00-13:00") == expectedTime("1200")
+ check toDateTime("11:00-24:00") == expectedTime("1100")
+ check toDateTime("23:00-24:00") == expectedTime("2300")
+ check toDateTime("24:00-23:00") == expectedTime("0000")
+ check toDateTime("9pm-12am") == expectedTime("2100")
+ check toDateTime("17-1am") == expectedTime("1700")
+ check toDateTime("9-1am") == expectedTime("2100")
+ check toDateTime("9:00-1:00am") == expectedTime("2100")
+ check toDateTime("9:30-1:30am") == expectedTime("2130")
+ check toDateTime("09:00-01:00am") == expectedTime("2100")
+ check toDateTime("09:30-01:30am") == expectedTime("2130")
+ check toDateTime("17:00-1:00am") == expectedTime("1700")
+ check toDateTime("12:00-1:00am") == expectedTime("0000")
+ check toDateTime("12-1:00am") == expectedTime("0000")
+ check toDateTime("00:00-01:00am") == expectedTime("0000")
+ check toDateTime("11-12pm") == expectedTime("1100")
+ check toDateTime("11-12am") == expectedTime("2300")
+ check toDateTime("11-12") == expectedTime("1100")
+ check toDateTime("9-1700") == expectedTime("0900")
+ check toDateTime("9-1100") == expectedTime("0900")