diff options
author | hlaaftana <10591326+hlaaftana@users.noreply.github.com> | 2020-04-29 21:55:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 20:55:09 +0200 |
commit | 707367e1ca231d964ba82a92b642eb5efdc1aa7c (patch) | |
tree | 9c65a95fea503194c8aa804832944e4c91797d06 /tests/js | |
parent | a297c016fab069665aeb1125ff1c85b5e25e6a01 (diff) | |
download | Nim-707367e1ca231d964ba82a92b642eb5efdc1aa7c.tar.gz |
many bugfixes for js (#14158)
* many bugfixes for js fixes #12672, fixes #14153, closes #14123, closes #11331, fixes #11783, fixes #13966, fixes #14087, fixes #14117, closes #12256. mostly fixes the fact that it was allowed to assign to newly created temp variables. additionally attempts to get rid of null initialized seqs/strings (though they might pop up here and there); this simplifies a lot of things and makes code size smaller. even if null seqs/strings pop up here and there it's still better than all those bugs existing. * formatting fixes * CI fixes * more CI fixes
Diffstat (limited to 'tests/js')
-rw-r--r-- | tests/js/t12672.nim | 12 | ||||
-rw-r--r-- | tests/js/t14153.nim | 22 | ||||
-rw-r--r-- | tests/js/tjshello.nim | 2 | ||||
-rw-r--r-- | tests/js/tjshello_stacktrace.nim | 9 | ||||
-rw-r--r-- | tests/js/tmangle.nim | 4 | ||||
-rw-r--r-- | tests/js/trepr.nim | 18 | ||||
-rw-r--r-- | tests/js/ttempgen.nim | 79 |
7 files changed, 134 insertions, 12 deletions
diff --git a/tests/js/t12672.nim b/tests/js/t12672.nim new file mode 100644 index 000000000..a658fbcbe --- /dev/null +++ b/tests/js/t12672.nim @@ -0,0 +1,12 @@ +discard """ + output: "" +""" + +proc foo = + var x: seq[seq[int]] + for row in x.mitems: + let i = 1 + echo row + inc row[i-1] + +foo() diff --git a/tests/js/t14153.nim b/tests/js/t14153.nim new file mode 100644 index 000000000..350bbd83b --- /dev/null +++ b/tests/js/t14153.nim @@ -0,0 +1,22 @@ +discard """ + output: ''' +index 5 not in 0 .. 2 +index 5 not in 0 .. 2 +''' +""" + +var x = @[1, 2, 3] + +try: + echo x[5] +except IndexError: + echo getCurrentExceptionMsg() +except: + doAssert false + +try: + x[5] = 8 +except IndexError: + echo getCurrentExceptionMsg() +except: + doAssert false diff --git a/tests/js/tjshello.nim b/tests/js/tjshello.nim index 19e0b90ae..8e090b3d2 100644 --- a/tests/js/tjshello.nim +++ b/tests/js/tjshello.nim @@ -1,4 +1,5 @@ discard """ + cmd: "nim $target $options --stackTrace:off --lineTrace:off $file" output: "Hello World" maxcodesize: 1000 ccodecheck: "!@'function'" @@ -7,4 +8,3 @@ discard """ import jsconsole console.log "Hello World" - diff --git a/tests/js/tjshello_stacktrace.nim b/tests/js/tjshello_stacktrace.nim new file mode 100644 index 000000000..d5e1c36eb --- /dev/null +++ b/tests/js/tjshello_stacktrace.nim @@ -0,0 +1,9 @@ +discard """ + output: "Hello World" + maxcodesize: 4500 + ccodecheck: "!@'function'" +""" + +import jsconsole + +console.log "Hello World" diff --git a/tests/js/tmangle.nim b/tests/js/tmangle.nim index c97bf7029..393043722 100644 --- a/tests/js/tmangle.nim +++ b/tests/js/tmangle.nim @@ -62,8 +62,8 @@ block: result = result and obj1.`&&`.addr[] == "bar".cstring result = result and obj2.`if` == 0 result = result and obj2.`for` == 0 - result = result and obj2.`==`.isNil() - result = result and obj2.`&&`.isNil() + result = result and obj2.`==`.len == 0 + result = result and obj2.`&&`.len == 0 echo test() # Test codegen for fields with uppercase letters: diff --git a/tests/js/trepr.nim b/tests/js/trepr.nim index 366d247c5..ffa9d4de0 100644 --- a/tests/js/trepr.nim +++ b/tests/js/trepr.nim @@ -308,21 +308,21 @@ b = 0, c = 0.0, d = '\0', e = eA, -f = nil, +f = "", g = {}, h = {}, -i = [nil, nil, nil], -j = nil, +i = ["", "", ""], +j = @[], k = 0, -l = [a = nil, -b = nil], +l = [a = "", +b = @[]], m = nil, n = nil, -o = [Field0 = [a = nil, -b = nil], -Field1 = nil], +o = [Field0 = [a = "", +b = @[]], +Field1 = ""], p = nil, -q = nil] +q = ""] """) doAssert(repr(cc) == """ [a = 12, diff --git a/tests/js/ttempgen.nim b/tests/js/ttempgen.nim new file mode 100644 index 000000000..badc66c1b --- /dev/null +++ b/tests/js/ttempgen.nim @@ -0,0 +1,79 @@ +discard """ + output: ''' +foo +''' +""" + +block: # #12672 + var a = @[1] + let i = 1 + inc a[i-1] + + var b: seq[int] + doAssertRaises(IndexDefect): inc b[0] + doAssertRaises(IndexDefect): inc b[i-1] + + var x: seq[seq[int]] + doAssertRaises(IndexDefect): # not TypeError + inc x[0][i-1] + +block: # #14087 + type Obj = object + str: string + + var s = @[Obj(str: "abc"), Obj(str: "def")] + s[1].str.add("ghi") + s[s.len - 1].str.add("jkl") + s[^1].str.add("mno") + s[s.high].str.add("pqr") + + let slen = s.len + s[slen - 1].str.add("stu") + + let shigh = s.high + s[shigh].str.add("vwx") + + proc foo(): int = + echo "foo" + shigh + s[foo()].str.add("yz") + doAssert s[1].str == "defghijklmnopqrstuvwxyz" + +block: # #14117 + type + A = object + case kind: bool + of true: + sons: seq[int] + else: discard + + var a = A(kind: true) + doAssert a.sons.len == 0 + a.sons.add(1) + doAssert a.sons.len == 1 + +import tables + +block: # #13966 + var t: Table[int8, array[int8, seq[tuple[]]]] + + t[0] = default(array[int8, seq[tuple[]]]) + t[0][0].add () + +block: # #11783 + proc fun(): string = + discard + + var ret: string + ret.add fun() + doAssert ret == "" + +block: # #12256 + var x: bool + + doAssert x == false + + reset x + + doAssert x == false + doAssert x != true |