summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-11-07 16:52:34 +0100
committerGitHub <noreply@github.com>2016-11-07 16:52:34 +0100
commit4c79583a95c863aba6d8e309ea612ecfac163d04 (patch)
tree10d98b7d4e204cd1fca46feceff5c859645da63f /tests/stdlib
parentbe296c3274a48af8049b940a0f016bbc80091f62 (diff)
parent63c450abdc132d2f402eceae4691872a703535c6 (diff)
downloadNim-4c79583a95c863aba6d8e309ea612ecfac163d04.tar.gz
Merge pull request #5002 from goldenreign/time-compare-nosideeffect
Add 'noSideEffect' pragma for Time type's operators. Fixes #4981
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/ttime.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/stdlib/ttime.nim b/tests/stdlib/ttime.nim
index 3a097cda5..5d3c8325e 100644
--- a/tests/stdlib/ttime.nim
+++ b/tests/stdlib/ttime.nim
@@ -179,3 +179,14 @@ let dstT1 = parse("2016-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss")
 let dstT2 = parse("2016-06-01 00:00:00", "yyyy-MM-dd HH:mm:ss")
 doAssert dstT1 == getLocalTime(toTime(dstT1))
 doAssert dstT2 == getLocalTime(toTime(dstT2))
+
+# Comparison between Time objects should be detected by compiler
+# as 'noSideEffect'.
+proc cmpTimeNoSideEffect(t1: Time, t2: Time): bool {.noSideEffect.} =
+  result = t1 == t2
+doAssert cmpTimeNoSideEffect(0.fromSeconds, 0.fromSeconds)
+# Additionally `==` generic for seq[T] has explicit 'noSideEffect' pragma
+# so we can check above condition by comparing seq[Time] sequences
+let seqA: seq[Time] = @[]
+let seqB: seq[Time] = @[]
+doAssert seqA == seqB