summary refs log tree commit diff stats
path: root/tests/js
diff options
context:
space:
mode:
authorDean Thompson <deansherthompson@gmail.com>2019-01-21 16:40:04 -0500
committerGitHub <noreply@github.com>2019-01-21 16:40:04 -0500
commita6de0274ee768d135bab280d2b2700a0bb475300 (patch)
tree176b91e837ab7d2217713665c16fc28163017960 /tests/js
parent5b39c7aca91c1d20eb81425cf8f3854876aed475 (diff)
parentee89ba6bdb664fe4972f2917499cff1afdac0bab (diff)
downloadNim-a6de0274ee768d135bab280d2b2700a0bb475300.tar.gz
Merge pull request #1 from nim-lang/devel
Getting the latest from nim-lang
Diffstat (limited to 'tests/js')
-rw-r--r--tests/js/t9410.nim37
-rw-r--r--tests/js/tclosures.nim44
-rw-r--r--tests/js/test1.nim32
-rw-r--r--tests/js/test2.nim3
-rw-r--r--tests/js/testobjs.nim17
-rw-r--r--tests/js/tjsffi.nim16
6 files changed, 139 insertions, 10 deletions
diff --git a/tests/js/t9410.nim b/tests/js/t9410.nim
index 9aca6d45b..78c329a24 100644
--- a/tests/js/t9410.nim
+++ b/tests/js/t9410.nim
@@ -1,13 +1,3 @@
-template doAssert(exp: untyped) =
-  when defined(echot9410):
-    let r = exp
-    echo $(instantiationInfo().line) & ":\n  " & astToStr(exp) & "\n  was " & repr(r)
-    when not defined(noassertt9410):
-      system.doAssert r
-  else:
-    when not defined(noassertt9410):
-      system.doAssert exp
-
 template tests =
   block:
     var i = 0
@@ -428,6 +418,33 @@ template tests =
 
     let xptr2 = cast[type(xptr)](p2)
     doAssert xptr == xptr2
+  
+  block: # var types
+    block t10202:
+      type Point = object
+        x: float
+        y: float
+
+      var points: seq[Point]
+
+      points.add(Point(x:1, y:2))
+
+      for i, p in points.mpairs:
+        p.x += 1
+
+      doAssert points[0].x == 2
+    
+    block:
+      var ints = @[1, 2, 3]
+      for i, val in mpairs ints:
+        val *= 10
+      doAssert ints == @[10, 20, 30]
+    
+    block:
+      var seqOfSeqs = @[@[1, 2], @[3, 4]]
+      for i, val in mpairs seqOfSeqs:
+        val[0] *= 10
+      doAssert seqOfSeqs == @[@[10, 2], @[30, 4]]
 
   when false:
     block: # openarray
diff --git a/tests/js/tclosures.nim b/tests/js/tclosures.nim
index 659c60092..70037f4bf 100644
--- a/tests/js/tclosures.nim
+++ b/tests/js/tclosures.nim
@@ -49,3 +49,47 @@ for i in 1 .. 10:
 let results = runCallbacks()
 
 doAssert(expected == $results)
+
+block issue7048:
+  block:
+    proc foo(x: seq[int]): auto =
+      proc bar: int = x[1]
+      bar
+
+    var stuff = @[1, 2]
+    let f = foo(stuff)
+    stuff[1] = 321
+    doAssert f() == 2
+
+  block:
+    proc foo(x: tuple[things: string]; y: array[3, int]): auto =
+      proc very: auto = 
+        proc deeply: auto =
+          proc nested: (char, int) = (x.things[0], y[1])
+          nested
+        deeply
+      very()
+
+    var
+      stuff = (things: "NIM")
+      stuff2 = [32, 64, 96]
+    let f = foo(stuff, stuff2)
+    stuff.things = "VIM"
+    stuff2[1] *= 10
+    doAssert f()() == ('N', 64)
+    doAssert (stuff.things[0], stuff2[1]) == ('V', 640)
+
+  block:
+    proc foo(x: ptr string): auto =
+      proc bar(): int = len(x[])
+      bar
+    
+    var 
+      s1 = "xyz"
+      s2 = "stuff"
+      p = addr s1
+    
+    let f = foo(p)
+    p = addr s2
+    doAssert len(p[]) == 5
+    doAssert f() == 3
\ No newline at end of file
diff --git a/tests/js/test1.nim b/tests/js/test1.nim
index 7f1d346f0..73e7a37ed 100644
--- a/tests/js/test1.nim
+++ b/tests/js/test1.nim
@@ -20,3 +20,35 @@ proc onButtonClick(inputElement: string) {.exportc.} =
 
 onButtonClick(inputElement)
 
+block:
+  var s: string
+  s.add("hi")
+  doAssert(s == "hi")
+
+block:
+  var s: string
+  s.insert("hi", 0)
+  doAssert(s == "hi")
+
+block:
+  var s: string
+  s.setLen(2)
+  s[0] = 'h'
+  s[1] = 'i'
+  doAssert(s == "hi")
+
+block:
+  var s: seq[int]
+  s.setLen(2)
+  doAssert(s == @[0, 0])
+
+block:
+  var s: seq[int]
+  s.insert(2, 0)
+  doAssert(s == @[2])
+
+block:
+  var s: seq[int]
+  s.add(2)
+  doAssert(s == @[2])
+
diff --git a/tests/js/test2.nim b/tests/js/test2.nim
index 0bfb99139..9ecdbb35c 100644
--- a/tests/js/test2.nim
+++ b/tests/js/test2.nim
@@ -9,6 +9,9 @@ js 3.14
 
 # This file tests the JavaScript generator
 
+doAssert getCurrentException() == nil
+doAssert getCurrentExceptionMsg() == ""
+
 #  #335
 proc foo() =
   var bar = "foo"
diff --git a/tests/js/testobjs.nim b/tests/js/testobjs.nim
index 78f0b4766..b61d06471 100644
--- a/tests/js/testobjs.nim
+++ b/tests/js/testobjs.nim
@@ -54,3 +54,20 @@ let test2 = test1
 
 echo toJSON(test1)
 echo toJSON(test2)
+
+block issue10005:
+  type
+    Player = ref object of RootObj
+      id*: string
+      nickname*: string
+      color*: string
+
+  proc newPlayer(nickname: string, color: string): Player =
+    let pl = Player(color: "#123", nickname: nickname)
+    return Player(
+        id: "foo",
+        nickname: nickname,
+        color: color,
+    )
+
+  doAssert newPlayer("foo", "#1232").nickname == "foo"
diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim
index 2420c60f6..8bd40a3c4 100644
--- a/tests/js/tjsffi.nim
+++ b/tests/js/tjsffi.nim
@@ -22,6 +22,13 @@ true
 Event { name: 'click: test' }
 Event { name: 'reloaded: test' }
 Event { name: 'updates: test' }
+true
+true
+true
+true
+true
+true
+true
 '''
 """
 
@@ -317,3 +324,12 @@ block:
   jslib.subscribe("updates"):
     console.log jsarguments[0]
 
+block:
+
+  echo jsUndefined == jsNull
+  echo jsUndefined == nil
+  echo jsNull == nil
+  echo jsUndefined.isNil
+  echo jsNull.isNil
+  echo jsNull.isNull
+  echo jsUndefined.isUndefined