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/tasync.nim3
-rw-r--r--tests/js/tasync_pragma.nim27
-rw-r--r--tests/js/trepr.nim90
-rw-r--r--tests/js/tstring_assignment.nim12
-rw-r--r--tests/js/tstringitems.nim9
-rw-r--r--tests/js/ttimes.nim7
6 files changed, 100 insertions, 48 deletions
diff --git a/tests/js/tasync.nim b/tests/js/tasync.nim
index 34ef97b8b..318237651 100644
--- a/tests/js/tasync.nim
+++ b/tests/js/tasync.nim
@@ -1,5 +1,4 @@
 discard """
-  disabled: true
   output: '''
 x
 e
@@ -18,6 +17,8 @@ proc e: int {.discardable.} =
 
 proc x(e: int): Future[void] {.async.} =
   var s = await y(e)
+  if e > 2:
+    return
   echo s
   e()
 
diff --git a/tests/js/tasync_pragma.nim b/tests/js/tasync_pragma.nim
new file mode 100644
index 000000000..916769fad
--- /dev/null
+++ b/tests/js/tasync_pragma.nim
@@ -0,0 +1,27 @@
+discard """
+  output: '''
+0
+t
+'''
+"""
+
+import asyncjs, macros
+
+macro f*(a: untyped): untyped =
+  assert a.kind == nnkProcDef
+  result = nnkProcDef.newTree(a.name, a[1], a[2], a.params, a.pragma, a[5], nnkStmtList.newTree())
+  let call = quote:
+    echo 0
+  result.body.add(call)
+  for child in a.body:
+    result.body.add(child)
+  #echo result.body.repr
+
+proc t* {.async, f.} =
+  echo "t"
+
+proc t0* {.async.} =
+  await t()
+
+discard t0()
+
diff --git a/tests/js/trepr.nim b/tests/js/trepr.nim
index 06dbbca22..366d247c5 100644
--- a/tests/js/trepr.nim
+++ b/tests/js/trepr.nim
@@ -3,7 +3,7 @@ discard """
 """
 
 block ints:
-  let 
+  let
     na: int8 = -120'i8
     nb: int16 = -32700'i16
     nc: int32 = -2147483000'i32
@@ -12,9 +12,9 @@ block ints:
     pa: int8 = 120'i8
     pb: int16 = 32700'i16
     pc: int32 = 2147483000'i32
-    pd: int64 = 9223372036854775000'i64 
+    pd: int64 = 9223372036854775000'i64
     pe: int = 1234567
-  
+
   doAssert(repr(na) == "-120")
   doAssert(repr(nb) == "-32700")
   doAssert(repr(nc) == "-2147483000")
@@ -27,13 +27,13 @@ block ints:
   doAssert(repr(pe) == "1234567")
 
 block uints:
-  let 
+  let
     a: uint8 = 254'u8
     b: uint16 = 65300'u16
     c: uint32 = 4294967290'u32
     # d: uint64 = 18446744073709551610'u64  -> unknown node type
     e: uint = 1234567
-  
+
   doAssert(repr(a) == "254")
   doAssert(repr(b) == "65300")
   doAssert(repr(c) == "4294967290")
@@ -41,26 +41,26 @@ block uints:
   doAssert(repr(e) == "1234567")
 
 block floats:
-  let 
+  let
     a: float32 = 3.4e38'f32
     b: float64 = 1.7976931348623157e308'f64
     c: float = 1234.567e89
-  
-  when defined js: 
+
+  when defined js:
     doAssert(repr(a) == "3.4e+38") # in C: 3.399999952144364e+038
     doAssert(repr(b) == "1.7976931348623157e+308") # in C: 1.797693134862316e+308
     doAssert(repr(c) == "1.234567e+92") # in C: 1.234567e+092
 
 block bools:
-  let 
+  let
     a: bool = true
     b: bool = false
-  
-  doAssert(repr(a) == "true") 
+
+  doAssert(repr(a) == "true")
   doAssert(repr(b) == "false")
 
 block enums:
-  type 
+  type
     AnEnum = enum
       aeA
       aeB
@@ -69,53 +69,59 @@ block enums:
       heA = -12
       heB = 15
       heC = 123
-  
-  doAssert(repr(aeA) == "aeA") 
+
+  doAssert(repr(aeA) == "aeA")
   doAssert(repr(aeB) == "aeB")
-  doAssert(repr(aeC) == "aeC") 
+  doAssert(repr(aeC) == "aeC")
   doAssert(repr(heA) == "heA")
-  doAssert(repr(heB) == "heB") 
+  doAssert(repr(heB) == "heB")
   doAssert(repr(heC) == "heC")
 
+block emums_and_unicode: #6741
+  type K = enum Kanji = "漢字"
+  let kanji = Kanji
+  doAssert(kanji == Kanji, "Enum values are not equal")
+  doAssert($kanji == $Kanji, "Enum string values are not equal")
+
 block chars:
   let
     a = 'a'
     b = 'z'
     one = '1'
     nl = '\x0A'
-  
+
   doAssert(repr(a) == "'a'")
   doAssert(repr(b) == "'z'")
   doAssert(repr(one) == "'1'")
   doAssert(repr(nl) == "'\\10'")
 
 block strings:
-  let 
+  let
     a: string = "12345"
     b: string = "hello,repr"
     c: string = "hi\nthere"
   when defined js: # C prepends the pointer, JS does not.
     doAssert(repr(a) == "\"12345\"")
     doAssert(repr(b) == "\"hello,repr\"")
-    doAssert(repr(c) == "\"hi\nthere\"")
+    doAssert(repr(c) == "\"hi\\10there\"")
 
 block sets:
   let
     a: set[int16] = {1'i16, 2'i16, 3'i16}
     b: set[char] = {'A', 'k'}
-    
+
   doAssert(repr(a) == "{1, 2, 3}")
   doAssert(repr(b) == "{'A', 'k'}")
 
 block ranges:
-  let 
+  let
     a: range[0..12] = 6
     b: range[-12..0] = -6
   doAssert(repr(a) == "6")
   doAssert(repr(b) == "-6")
 
 block tuples:
-  type 
+  type
     ATuple = tuple
       a: int
       b: float
@@ -124,7 +130,7 @@ block tuples:
     OtherTuple = tuple
       a: bool
       b: int8
-  
+
   let
     ot: OtherTuple = (a: true, b: 120'i8)
     t: ATuple = (a: 42, b: 12.34, c: "tuple", d: ot)
@@ -176,7 +182,7 @@ block arrays:
     o = AObj(x: 42, y: a)
     c = [o, o, o]
     d = ["hi", "array", "!"]
-    
+
   doAssert(repr(a) == "[0.0, 1.0, 2.0]\n")
   doAssert(repr(b) == "[[0.0, 1.0, 2.0], [0.0, 1.0, 2.0], [0.0, 1.0, 2.0]]\n")
   doAssert(repr(c) == """
@@ -198,7 +204,7 @@ block seqs:
     o = AObj(x: 42, y: a)
     c = @[o, o, o]
     d = @["hi", "array", "!"]
-    
+
   doAssert(repr(a) == "@[0.0, 1.0, 2.0]\n")
   doAssert(repr(b) == "@[@[0.0, 1.0, 2.0], @[0.0, 1.0, 2.0], @[0.0, 1.0, 2.0]]\n")
   doAssert(repr(c) == """
@@ -210,16 +216,16 @@ y = @[0.0, 1.0, 2.0]]]
   doAssert(repr(d) == "@[\"hi\", \"array\", \"!\"]\n")
 
 block ptrs:
-  type 
+  type
     AObj = object
       x: ptr array[2, AObj]
       y: int
-  var 
+  var
     a = [12.0, 13.0, 14.0]
     b = addr a[0]
     c = addr a[2]
     d = AObj()
-  
+
   doAssert(repr(a) == "[12.0, 13.0, 14.0]\n")
   doAssert(repr(b) == "ref 0 --> 12.0\n")
   doAssert(repr(c) == "ref 2 --> 14.0\n")
@@ -229,13 +235,13 @@ y = 0]
 """)
 
 block ptrs:
-  type 
+  type
     AObj = object
       x: ref array[2, AObj]
       y: int
-  var 
+  var
     a = AObj()
-  
+
   new(a.x)
 
   doAssert(repr(a) == """
@@ -248,10 +254,10 @@ y = 0]
 block procs:
   proc test(): int =
     echo "hello"
-  var 
+  var
     ptest = test
     nilproc: proc(): int
-  
+
   doAssert(repr(test) == "0\n")
   doAssert(repr(ptest) == "0\n")
   doAssert(repr(nilproc) == "nil\n")
@@ -262,7 +268,7 @@ block bunch:
       eA, eB, eC
     B = object
       a: string
-      b: seq[char] 
+      b: seq[char]
     A = object
       a: uint32
       b: int
@@ -281,17 +287,17 @@ block bunch:
       o: tuple[x: B, y: string]
       p: proc(b: B): ref B
       q: cstring
-      
+
   proc refB(b:B):ref B =
     new result
     result[] = b
-  
+
   var
     aa: A
     bb: B = B(a: "inner", b: @['o', 'b', 'j'])
     cc: A = A(a: 12, b: 1, c: 1.2, d: '\0', e: eC,
                 f: "hello", g: {'A'}, h: {2'i16},
-                i: ["hello", "world", "array"], 
+                i: ["hello", "world", "array"],
                 j: @["hello", "world", "seq"], k: -1,
                 l: bb, m: refB(bb), n: addr bb,
                 o: (bb, "tuple!"), p: refB, q: "cstringtest" )
@@ -344,12 +350,12 @@ q = "cstringtest"]
 """)
 
 block another:
-  type 
-    Size1 = enum 
+  type
+    Size1 = enum
       s1a, s1b
-    Size2 = enum 
+    Size2 = enum
       s2c=0, s2d=20000
-    Size3 = enum 
+    Size3 = enum
       s3e=0, s3f=2000000000
 
   doAssert(repr([s1a, s1b]) == "[s1a, s1b]\n")
@@ -357,7 +363,7 @@ block another:
   doAssert(repr([s3e, s3f]) == "[s3e, s3f]\n")
 
 block another2:
-  
+
   type
     AnEnum = enum
       en1, en2, en3, en4, en5, en6
diff --git a/tests/js/tstring_assignment.nim b/tests/js/tstring_assignment.nim
index bdd93e6b5..97ffa748f 100644
--- a/tests/js/tstring_assignment.nim
+++ b/tests/js/tstring_assignment.nim
@@ -1,5 +1,6 @@
 discard """
-  output: '''true'''
+  output: '''true
+asdfasekjkler'''
 """
 
 # bug #4471
@@ -9,3 +10,12 @@ when true:
   s2.setLen(0)
   # fails - s1.len == 0
   echo s1.len == 3
+
+# bug #4470
+proc main(s: cstring): string =
+  result = newString(0)
+  for i in 0..<s.len:
+    if s[i] >= 'a' and s[i] <= 'z':
+      result.add s[i]
+
+echo main("asdfasekjkleräöü")
diff --git a/tests/js/tstringitems.nim b/tests/js/tstringitems.nim
index 20aed6e8b..ff016642e 100644
--- a/tests/js/tstringitems.nim
+++ b/tests/js/tstringitems.nim
@@ -76,3 +76,12 @@ block: # String case of
   case s
   of "Привет!": discard
   else: doAssert(false)
+
+block: # String cmp
+  var a, b: string
+  doAssert(cmp(a, b) == 0)
+  doAssert(cmp("foo", "foo") == 0)
+  doAssert(cmp("foobar", "foo") == 3)
+  doAssert(cmp("foo", "foobar") == -3)
+  doAssert(cmp("fooz", "foog") == 19)
+  doAssert(cmp("foog", "fooz") == -19)
diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim
index 63a4bb04f..63972dd76 100644
--- a/tests/js/ttimes.nim
+++ b/tests/js/ttimes.nim
@@ -17,14 +17,14 @@ block localTime:
 
 let a = fromUnix(1_000_000_000)
 let b = fromUnix(1_500_000_000)
-doAssert b - a == 500_000_000
+doAssert b - a == initDuration(seconds = 500_000_000)
 
 # Because we can't change the timezone JS uses, we define a simple static timezone for testing.
 
 proc staticZoneInfoFromUtc(time: Time): ZonedTime =
   result.utcOffset = -7200
   result.isDst = false
-  result.adjTime = (time.toUnix + 7200).Time
+  result.adjTime = time + 7200.seconds
 
 proc staticZoneInfoFromTz(adjTime: Time): ZonedTIme =
   result.utcOffset = -7200
@@ -40,5 +40,4 @@ block timezoneTests:
   doAssert $dt.utc.inZone(utcPlus2) == $dt
 
 doAssert $initDateTime(01, mJan, 1911, 12, 00, 00, utc()) == "1911-01-01T12:00:00+00:00"
-# See #6752
-# doAssert $initDateTime(01, mJan, 1900, 12, 00, 00, utc()) == "0023-01-01T12:00:00+00:00"
\ No newline at end of file
+doAssert $initDateTime(01, mJan, 0023, 12, 00, 00, utc()) == "0023-01-01T12:00:00+00:00"
\ No newline at end of file