summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-02-15 04:28:11 -0600
committerGitHub <noreply@github.com>2021-02-15 11:28:11 +0100
commit240879bf3d746059accd73deacc7405c53aa0704 (patch)
treea1466ff3fb67d66316604e4de95303c7e6863345 /tests
parentc8d99631503b03266db14967495c0a1b250ab327 (diff)
downloadNim-240879bf3d746059accd73deacc7405c53aa0704.tar.gz
array literals uses typed arrays; fix a jsgen bug (#16850)
* array litterals uses typed arrays
* Update compiler/jsgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/js/tbigint_backend.nim5
-rw-r--r--tests/js/tseqops.nim21
-rw-r--r--tests/js/ttypedarray.nim21
3 files changed, 32 insertions, 15 deletions
diff --git a/tests/js/tbigint_backend.nim b/tests/js/tbigint_backend.nim
index db7ebb065..8f2f6c4f4 100644
--- a/tests/js/tbigint_backend.nim
+++ b/tests/js/tbigint_backend.nim
@@ -1,6 +1,5 @@
-proc jsTypeOf*[T](x: T): cstring {.importjs: "typeof(#)".}
-  ## Returns the name of the JsObject's JavaScript type as a cstring.
-  # xxx replace jsffi.jsTypeOf with this definition and add tests
+import std/private/jsutils
+
 
 type JsBigIntImpl {.importc: "bigint".} = int
 type JsBigInt = distinct JsBigIntImpl
diff --git a/tests/js/tseqops.nim b/tests/js/tseqops.nim
index af664222c..8cfb50886 100644
--- a/tests/js/tseqops.nim
+++ b/tests/js/tseqops.nim
@@ -1,11 +1,3 @@
-discard """
-  output: '''(x: 0, y: 0)
-(x: 5, y: 0)
-@[(x: "2", y: 4), (x: "4", y: 5), (x: "4", y: 5)]
-@[(a: "3", b: 3), (a: "1", b: 1), (a: "2", b: 2)]
-'''
-"""
-
 # bug #4139
 
 type
@@ -17,8 +9,8 @@ proc onLoad() =
   var foo = TestO(x: 0, y: 0)
   test.add(foo)
   foo.x = 5
-  echo(test[0])
-  echo foo
+  doAssert $test[0] == "(x: 0, y: 0)"
+  doAssert $foo == "(x: 5, y: 0)"
 
 onLoad()
 
@@ -34,7 +26,7 @@ proc foo(x: var seq[MyObj]) =
 
 var s = @[MyObj(x: "2", y: 4), MyObj(x: "4", y: 5)]
 foo(s)
-echo s
+doAssert $s == """@[(x: "2", y: 4), (x: "4", y: 5), (x: "4", y: 5)]"""
 
 # bug  #5933
 import sequtils
@@ -48,4 +40,9 @@ var test = @[Test(a: "1", b: 1), Test(a: "2", b: 2)]
 
 test.insert(@[Test(a: "3", b: 3)], 0)
 
-echo test
+doAssert $test == """@[(a: "3", b: 3), (a: "1", b: 1), (a: "2", b: 2)]"""
+
+proc hello(): array[5, int] = discard
+var x = @(hello())
+x.add(2)
+doAssert x == @[0, 0, 0, 0, 0, 2]
diff --git a/tests/js/ttypedarray.nim b/tests/js/ttypedarray.nim
new file mode 100644
index 000000000..222f66569
--- /dev/null
+++ b/tests/js/ttypedarray.nim
@@ -0,0 +1,21 @@
+import std/private/jsutils
+
+proc main()=
+  template fn(a): untyped = jsConstructorName(a)
+  doAssert fn(array[2, int8].default) == "Int8Array"
+  doAssert fn(array[2, uint8].default) == "Uint8Array"
+  doAssert fn(array[2, byte].default) == "Uint8Array"
+  # doAssert fn(array[2, char].default) == "Uint8Array" # xxx fails; bug?
+  doAssert fn(array[2, uint64].default) == "Array"
+    # pending https://github.com/nim-lang/RFCs/issues/187 maybe use `BigUint64Array`
+  doAssert fn([1'u8]) == "Uint8Array"
+  doAssert fn([1'u16]) == "Uint16Array"
+  doAssert fn([byte(1)]) == "Uint8Array"
+  doAssert fn([1.0'f32]) == "Float32Array"
+  doAssert fn(array[2, float32].default) == "Float32Array"
+  doAssert fn(array[2, float].default) == "Float64Array"
+  doAssert fn(array[2, float64].default) == "Float64Array"
+  doAssert fn([1.0]) == "Float64Array"
+  doAssert fn([1.0'f64]) == "Float64Array"
+
+main()