diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-07-13 04:48:22 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-13 04:48:22 +0200 |
commit | 2b862b74e0b0b7b4a18f4262356289fb921eaf0c (patch) | |
tree | 8f41b7355f6d791d6485e8225d6a5cb2f80ca7d6 /tests/js | |
parent | a5695c13afabac6e67ff677d564b6d1a6aeb1af4 (diff) | |
parent | 0c271f54208c7ba0bac6ad2da87f60e7c6d8e37c (diff) | |
download | Nim-2b862b74e0b0b7b4a18f4262356289fb921eaf0c.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'tests/js')
-rw-r--r-- | tests/js/tbyvar.nim | 61 | ||||
-rw-r--r-- | tests/js/tcopying.nim | 24 | ||||
-rw-r--r-- | tests/js/testobjs.nim | 20 | ||||
-rw-r--r-- | tests/js/tjshello.nim | 10 | ||||
-rw-r--r-- | tests/js/trefbyvar.nim | 36 | ||||
-rw-r--r-- | tests/js/tseqops.nim | 51 | ||||
-rw-r--r-- | tests/js/ttimes.nim | 5 |
7 files changed, 204 insertions, 3 deletions
diff --git a/tests/js/tbyvar.nim b/tests/js/tbyvar.nim index f974049b9..705d62574 100644 --- a/tests/js/tbyvar.nim +++ b/tests/js/tbyvar.nim @@ -5,6 +5,12 @@ bar 12 foo 12 bar 12 2 +12.5 +(nums: @[5, 5, 10, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 50, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 45, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 9, 5, 5, 5, 5, 5, 5, 5]) +asd ''' """ @@ -59,3 +65,58 @@ block: # Test var arg inside case expression. #5244 var a = "ok" foo(a) doAssert(a == "ok") + + +proc mainowar = + var x = 9.0 + x += 3.5 + echo x + +mainowar() + + +# bug #5608 + +type Foo = object + nums : seq[float] + +proc newFoo(len : int, default = 0.0) : Foo = + result = Foo() + result.nums = newSeq[float](len) + for i in 0..(len - 1): + result.nums[i] = default + +proc `[]=`(f : var Foo, i : int, v : float) = + f.nums[i] = v + +proc `[]`(f : Foo, i : int) : float = f.nums[i] + +proc `[]`(f : var Foo, i : int) : var float = f.nums[i] + +var f = newFoo(10,5) + +f[2] += 5 +echo f +f[2] *= 5 +echo f +f[2] -= 5 +echo f +f[2] /= 5 +echo f + +# regression for #5608 +import tables + +type + SomeObj = ref object + s: cstring + +var a = initTable[cstring, Table[cstring, SomeObj]]() + +var b = initTable[cstring, SomeObj]() + +b.add(cstring"b", SomeObj(s: cstring"asd")) + +a.add(cstring"a", b) + +echo a[cstring"a"][cstring"b"].s diff --git a/tests/js/tcopying.nim b/tests/js/tcopying.nim index 4f72d6ada..387df9cd3 100644 --- a/tests/js/tcopying.nim +++ b/tests/js/tcopying.nim @@ -1,5 +1,7 @@ discard """ output: '''123 +2 9 +2 9 ''' """ @@ -11,3 +13,25 @@ proc changeArray(a: var MyArray) = var a : MyArray changeArray(a) echo a[0] + +# bug #4703 +# Test 1 +block: + let ary1 = [1, 2, 3] + var ary2 = ary1 + + ary2[1] = 9 + + echo ary1[1], " ", ary2[1] + +# Test 2 +block: + type TestObj = ref object of RootObj + ary2: array[3, int] + + let ary1 = [1, 2, 3] + var obj = TestObj(ary2:ary1) + + obj.ary2[1] = 9 + + echo ary1[1], " ", obj.ary2[1] diff --git a/tests/js/testobjs.nim b/tests/js/testobjs.nim index 0166c0f38..dd66825ec 100644 --- a/tests/js/testobjs.nim +++ b/tests/js/testobjs.nim @@ -1,5 +1,7 @@ discard """ - action: run + output: '''{"columns":[{"t":null},{"t":null}]} +{"columns":[{"t":null},{"t":null}]} +''' """ ## Tests javascript object generation @@ -36,3 +38,19 @@ doAssert test.name == "Jorden" doAssert knight.age == 19 doAssert knight.item.price == 50 doAssert recurse1.next.next.data == 3 + +# bug #6035 +proc toJson*[T](data: T): cstring {.importc: "JSON.stringify".} + +type + Column = object + t: ref Column + + Test2 = object + columns: seq[Column] + +var test1 = Test2(columns: @[Column(t: nil), Column(t: nil)]) +let test2 = test1 + +echo toJSON(test1) +echo toJSON(test2) diff --git a/tests/js/tjshello.nim b/tests/js/tjshello.nim new file mode 100644 index 000000000..19e0b90ae --- /dev/null +++ b/tests/js/tjshello.nim @@ -0,0 +1,10 @@ +discard """ + output: "Hello World" + maxcodesize: 1000 + ccodecheck: "!@'function'" +""" + +import jsconsole + +console.log "Hello World" + diff --git a/tests/js/trefbyvar.nim b/tests/js/trefbyvar.nim index 68dd36543..d440fcc64 100644 --- a/tests/js/trefbyvar.nim +++ b/tests/js/trefbyvar.nim @@ -2,7 +2,9 @@ discard """ output: '''0 5 0 -5''' +5 +@[1, 2] +~''' """ # bug #2476 @@ -33,3 +35,35 @@ proc main = echo t.m main() + +# bug #5974 +type + View* = object + data: ref seq[int] + +let a = View(data: new(seq[int])) +a.data[] = @[1, 2] + +echo a.data[] + +# bug #5379 +var input = newSeq[ref string]() +input.add(nil) +input.add(new string) +input[1][] = "~" +echo input[1][] + +# bug #5517 +type + TypeA1 = object of RootObj + a_impl: int + b_impl: string + c_impl: pointer + +proc initTypeA1(a: int; b: string; c: pointer = nil): TypeA1 = + result.a_impl = a + result.b_impl = b + result.c_impl = c + +let x = initTypeA1(1, "a") +doAssert($x == "(a_impl: 1, b_impl: a, c_impl: ...)") diff --git a/tests/js/tseqops.nim b/tests/js/tseqops.nim new file mode 100644 index 000000000..d10e1ca6a --- /dev/null +++ b/tests/js/tseqops.nim @@ -0,0 +1,51 @@ +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 + TestO = object + x, y: int + +proc onLoad() = + var test: seq[TestO] = @[] + var foo = TestO(x: 0, y: 0) + test.add(foo) + foo.x = 5 + echo(test[0]) + echo foo + +onLoad() + +# 'setLen' bug (part of bug #5933) +type MyObj = object + x: cstring + y: int + +proc foo(x: var seq[MyObj]) = + let L = x.len + x.setLen L + 1 + x[L] = x[1] + +var s = @[MyObj(x: "2", y: 4), MyObj(x: "4", y: 5)] +foo(s) +echo s + +# bug #5933 +import sequtils + +type + Test = object + a: cstring + b: int + +var test = @[Test(a: "1", b: 1), Test(a: "2", b: 2)] + +test.insert(@[Test(a: "3", b: 3)], 0) + +echo test diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim index 20ba14245..2868c6d0f 100644 --- a/tests/js/ttimes.nim +++ b/tests/js/ttimes.nim @@ -21,6 +21,9 @@ block timestampPersistenceTest: const timeString = "2017-03-21T12:34:56+03:00" timeStringGmt = "2017-03-21T09:34:56+00:00" + timeStringGmt2 = "2017-03-21T08:34:56+00:00" fmt = "yyyy-MM-dd'T'HH:mm:sszzz" + # XXX Check which one is the right solution here: - doAssert $timeString.parse(fmt).toTime().getGMTime() == timeStringGmt + let x = $timeString.parse(fmt).toTime().getGMTime() + doAssert x == timeStringGmt or x == timeStringGmt2 |