js: improve tests + some docs (#16727)

* js: improve tests

* _

* _

* _

* fixup
This commit is contained in:
Timothee Cour
2021-01-16 03:08:40 -08:00
committed by GitHub
parent e4a529962e
commit 18e14f5920
5 changed files with 175 additions and 253 deletions

View File

@@ -92,8 +92,18 @@ func `==`*(x, y: JsBigInt): bool {.importjs: "(# == #)".} =
doAssert big"42" == big"42"
func `**`*(x, y: JsBigInt): JsBigInt {.importjs: "((#) $1 #)".} =
# (#) needed, refs https://github.com/nim-lang/Nim/pull/16409#issuecomment-760550812
runnableExamples:
doAssert (big"9" ** big"5") == big"59049"
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: