diff options
author | Parashurama <Rhagdamaziel@ymail.com> | 2017-09-15 13:35:57 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-09-15 13:35:57 +0200 |
commit | 88a5e9d88ccc0a48daa2710e88d2efb8a7ae6468 (patch) | |
tree | fc9a16fad9b80cf34257d286e90f003f22630ae9 /tests/vm | |
parent | 71b1377be918e10e9a279764747adbab73310688 (diff) | |
download | Nim-88a5e9d88ccc0a48daa2710e88d2efb8a7ae6468.tar.gz |
Fix operations on string as openarray in VM. (#6257)
* fix openarray.len for string as openArray in VM. * fix openarray[idx] for string as openArray in VM. * fix openarray[idx]=val for string as openArray in VM. * add tests for passing string as openArray in VM. * fix issue with NimNode.len NimNode.len was also returning len for string literals. also fix logic bug in if/elif chain.
Diffstat (limited to 'tests/vm')
-rw-r--r-- | tests/vm/tstring_openarray.nim | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/vm/tstring_openarray.nim b/tests/vm/tstring_openarray.nim new file mode 100644 index 000000000..1b8a1304c --- /dev/null +++ b/tests/vm/tstring_openarray.nim @@ -0,0 +1,34 @@ + +# tests various bug when passing string to openArray argument in VM. +# bug #6086 +proc map*[T, S](data: openArray[T], op: proc (x: T): S {.closure.}): + seq[S]{.inline.} = +# map inlined from sequtils + newSeq(result, data.len) + for i in 0..data.len-1: result[i] = op(data[i]) + + +proc set_all[T](s: var openArray[T]; val: T) = + for i in 0..<s.len: + s[i] = val + +proc test() = + var a0 = "hello_world" + var a1 = [1,2,3,4,5,6,7,8,9] + var a2 = @[1,2,3,4,5,6,7,8,9] + a0.set_all('i') + a1.set_all(4) + a2.set_all(4) + doAssert a0 == "iiiiiiiiiii" + doAssert a1 == [4,4,4,4,4,4,4,4,4] + doAssert a2 == @[4,4,4,4,4,4,4,4,4] + +const constval0 = "hello".map(proc(x: char): char = x) +const constval1 = [1,2,3,4].map(proc(x: int): int = x) + +doAssert("hello".map(proc(x: char): char = x) == constval0) +doAssert([1,2,3,4].map(proc(x: int): int = x) == constval1) + +test() +static: + test() |