summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-01-16 03:08:40 -0800
committerGitHub <noreply@github.com>2021-01-16 12:08:40 +0100
commit18e14f59209d4c4319317baa1faa089bec9fe484 (patch)
treecedf86febea3f3d9ceea050cacc02d193607f067 /lib
parente4a529962e7df83d6297a68f5a1913358119b632 (diff)
downloadNim-18e14f59209d4c4319317baa1faa089bec9fe484.tar.gz
js: improve tests + some docs (#16727)
* js: improve tests

* _

* _

* _

* fixup
Diffstat (limited to 'lib')
-rw-r--r--lib/js/jsffi.nim1
-rw-r--r--lib/std/jsbigints.nim14
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/js/jsffi.nim b/lib/js/jsffi.nim
index 8220013c1..0734d891a 100644
--- a/lib/js/jsffi.nim
+++ b/lib/js/jsffi.nim
@@ -180,6 +180,7 @@ proc `<`  *(x, y: JsObject): JsObject {.importcpp: "(# < #)".}
 proc `>=` *(x, y: JsObject): JsObject {.importcpp: "(# >= #)".}
 proc `<=` *(x, y: JsObject): JsObject {.importcpp: "(# <= #)".}
 proc `**` *(x, y: JsObject): JsObject {.importcpp: "((#) ** #)".}
+  # (#) needed, refs https://github.com/nim-lang/Nim/pull/16409#issuecomment-760550812
 proc `and`*(x, y: JsObject): JsObject {.importcpp: "(# && #)".}
 proc `or` *(x, y: JsObject): JsObject {.importcpp: "(# || #)".}
 proc `not`*(x:    JsObject): JsObject {.importcpp: "(!#)".}
diff --git a/lib/std/jsbigints.nim b/lib/std/jsbigints.nim
index 733f3369b..edef6844f 100644
--- a/lib/std/jsbigints.nim
+++ b/lib/std/jsbigints.nim
@@ -92,8 +92,18 @@ func `==`*(x, y: JsBigInt): bool {.importjs: "(# == #)".} =
     doAssert big"42" == big"42"
 
 func `**`*(x, y: JsBigInt): JsBigInt {.importjs: "((#) $1 #)".} =
-  runnableExamples:
-    doAssert (big"9" ** big"5") == big"59049"
+  # (#) needed, refs https://github.com/nim-lang/Nim/pull/16409#issuecomment-760550812
+  runnableExamples:
+    doAssert big"2" ** big"64" == big"18446744073709551616"
+    doAssert big"-2" ** big"3" == big"-8"
+    doAssert -big"2" ** big"2" == big"4" # parsed as: (-2n) ** 2n
+    doAssert big"0" ** big"0" == big"1" # edge case
+    var ok = false
+    try: discard big"2" ** big"-1" # raises foreign `RangeError`
+    except: ok = true
+    doAssert ok
+  # pending https://github.com/nim-lang/Nim/pull/15940, simplify to:
+  # doAssertRaises: discard big"2" ** big"-1" # raises foreign `RangeError`
 
 func `xor`*(x, y: JsBigInt): JsBigInt {.importjs: "(# ^ #)".} =
   runnableExamples: