summary refs log tree commit diff stats
path: root/tests/js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/js')
-rw-r--r--tests/js/t7224.nim26
-rw-r--r--tests/js/t7249.nim21
-rw-r--r--tests/js/t7534.nim7
-rw-r--r--tests/js/t8914.nim12
-rw-r--r--tests/js/taddnilstr.nim4
-rw-r--r--tests/js/tmangle.nim8
-rw-r--r--tests/js/tstrconcat.nim5
-rw-r--r--tests/js/tstringitems.nim2
8 files changed, 80 insertions, 5 deletions
diff --git a/tests/js/t7224.nim b/tests/js/t7224.nim
new file mode 100644
index 000000000..2d7ee1336
--- /dev/null
+++ b/tests/js/t7224.nim
@@ -0,0 +1,26 @@
+discard """
+  cmd: "nim $target $options --stackTrace:on --lineTrace:on $file"
+  outputsub: '''
+t7224.aaa, line: 21
+t7224.bbb, line: 18
+t7224.ccc, line: 15
+t7224.ddd, line: 12
+'''
+"""
+  
+proc ddd() =
+  raise newException(IOError, "didn't do stuff")
+
+proc ccc() =
+  ddd()
+
+proc bbb() =
+  ccc()
+
+proc aaa() =
+  bbb()
+
+try:
+  aaa()
+except IOError as e:
+  echo getStackTrace(e)
diff --git a/tests/js/t7249.nim b/tests/js/t7249.nim
new file mode 100644
index 000000000..52eee2f7c
--- /dev/null
+++ b/tests/js/t7249.nim
@@ -0,0 +1,21 @@
+discard """
+  output: '''
+a -> 2
+a <- 2
+'''
+"""
+
+import jsffi
+
+var a = JsAssoc[cstring, int]{a: 2}
+
+for z, b in a:
+  echo z, " -> ", b
+
+proc f =
+  var a = JsAssoc[cstring, int]{a: 2}
+
+  for z, b in a:
+    echo z, " <- ", b
+
+f()
diff --git a/tests/js/t7534.nim b/tests/js/t7534.nim
new file mode 100644
index 000000000..64aadb8d6
--- /dev/null
+++ b/tests/js/t7534.nim
@@ -0,0 +1,7 @@
+proc f(x: int): int =
+  result = case x
+    of 1: 2
+    elif x == 2: 3
+    else: 1
+
+doAssert 2 == f(f(f(f(1))))
diff --git a/tests/js/t8914.nim b/tests/js/t8914.nim
new file mode 100644
index 000000000..ff716b42a
--- /dev/null
+++ b/tests/js/t8914.nim
@@ -0,0 +1,12 @@
+discard """
+  output: '''
+@[42]
+@[24, 42]
+'''
+"""
+
+var x = @[42,4242]
+x.delete(1)
+echo x
+x.insert(24)
+echo x
diff --git a/tests/js/taddnilstr.nim b/tests/js/taddnilstr.nim
new file mode 100644
index 000000000..f5b934fdd
--- /dev/null
+++ b/tests/js/taddnilstr.nim
@@ -0,0 +1,4 @@
+var x = "foo".cstring
+var y: string
+add(y, x)
+doAssert y == "foo"
diff --git a/tests/js/tmangle.nim b/tests/js/tmangle.nim
index c4167ba39..c97bf7029 100644
--- a/tests/js/tmangle.nim
+++ b/tests/js/tmangle.nim
@@ -27,10 +27,10 @@ block:
   var global = T(a: 11, b: "foo")
   proc test(): bool =
     var obj = T(a: 11, b: "foo")
-    {. emit: [result, " = (", obj.addr[], "[0].a == 11);"] .}
-    {. emit: [result, " = ", result, " && (", obj.addr[], "[0].b == \"foo\");"] .}
-    {. emit: [result, " = ", result, " && (", global, "[0].a == 11);"] .}
-    {. emit: [result, " = ", result, " && (", global, "[0].b == \"foo\");"] .}
+    {. emit: [result, " = (", obj.addr[], ".a == 11);"] .}
+    {. emit: [result, " = ", result, " && (", obj.addr[], ".b == \"foo\");"] .}
+    {. emit: [result, " = ", result, " && (", global, ".a == 11);"] .}
+    {. emit: [result, " = ", result, " && (", global, ".b == \"foo\");"] .}
   echo test()
 
 # Test addr of field:
diff --git a/tests/js/tstrconcat.nim b/tests/js/tstrconcat.nim
new file mode 100644
index 000000000..37c8db687
--- /dev/null
+++ b/tests/js/tstrconcat.nim
@@ -0,0 +1,5 @@
+var x: string
+var y = "foo"
+add(x, y)
+y[0] = 'm'
+doAssert y == "moo" and x == "foo"
diff --git a/tests/js/tstringitems.nim b/tests/js/tstringitems.nim
index ff016642e..f09793dde 100644
--- a/tests/js/tstringitems.nim
+++ b/tests/js/tstringitems.nim
@@ -45,7 +45,7 @@ block: # Test compile-time binary data generation, invalid unicode
 block: # Test unicode strings
   const constStr = "Привет!"
   var jsStr : cstring
-  {.emit: """`jsStr`[0] = "Привет!";""".}
+  {.emit: """`jsStr` = "Привет!";""".}
 
   doAssert($jsStr == constStr)
   var runtimeStr = "При"