summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorSivchari <55221074+sivchari@users.noreply.github.com>2021-04-22 02:47:01 +0900
committerGitHub <noreply@github.com>2021-04-21 19:47:01 +0200
commitfb32fff8dcf2b15a469e5cce07b10d88aa6352ee (patch)
tree579c73d9a128a98845494774460c23c49c444e3d /tests
parent4471141a1d68158f3f23c6584d1f0434807c0203 (diff)
downloadNim-fb32fff8dcf2b15a469e5cce07b10d88aa6352ee.tar.gz
js generates spurious >>> on shr (#17767)
* js generates spurious >>> on shr
* Add shr arithmetic test
* fix variables from const to let during testing
Diffstat (limited to 'tests')
-rw-r--r--tests/stdlib/tarithmetics.nim49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/stdlib/tarithmetics.nim b/tests/stdlib/tarithmetics.nim
new file mode 100644
index 000000000..296ccd56e
--- /dev/null
+++ b/tests/stdlib/tarithmetics.nim
@@ -0,0 +1,49 @@
+discard """
+  targets: "c cpp js"
+"""
+
+# TODO: in future work move existing arithmetic tests (tests/arithm/*) into this file
+# FYI https://github.com/nim-lang/Nim/pull/17767
+
+template main =
+  # put all arithmetic tests
+
+  block tshr:
+    block: # Signed types
+      let
+        a1 = -3
+        a2 = -2
+        b1 = -4'i8
+        b2 = 1'i8
+        c1 = -5'i16
+        c2 = 1'i16
+        d1 = -7i32
+        d2 = 1'i32
+        e1 = -9'i64
+        e2 = 1'i64
+      doAssert a1 shr a2 == -1
+      doAssert b1 shr b2 == -2
+      doAssert c1 shr c2 == -3
+      doAssert d1 shr d2 == -4
+      doAssert e1 shr e2 == -5
+
+    block: # Unsigned types
+      let
+        a1 = 3'u
+        a2 = 2'u
+        b1 = 2'u8
+        b2 = 1'u8
+        c1 = 5'u16
+        c2 = 1'u16
+        d1 = 6'u32
+        d2 = 1'u32
+        e1 = 8'u64
+        e2 = 1'u64
+      doAssert a1 shr a2 == 0
+      doAssert b1 shr b2 == 1
+      doAssert c1 shr c2 == 2
+      doAssert d1 shr d2 == 3
+      doAssert e1 shr e2 == 4
+
+static: main()
+main()