Skip to content

Commit

Permalink
followup #17001: improve coverage for tests/openarray/topenarray.nim (#…
Browse files Browse the repository at this point in the history
…17006)

* followup #17001: improve coverage for tests/openarray/topenarray.nim
  • Loading branch information
timotheecour authored Feb 13, 2021
1 parent 190fe36 commit 21e60b9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/openarray/topenarray.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ discard """
targets: "c cpp js"
"""

proc pro[T](a: var openArray[T]) = discard
proc fn1[T](a: openArray[T]): seq[T] =
for ai in a: result.add ai

proc fn2[T](a: var openArray[T]): seq[T] =
for ai in a: result.add ai

proc fn3[T](a: var openArray[T]) =
for i, ai in mpairs(a): ai = i * 10

proc main =
var a = [1,2,3,4,5]

pro(toOpenArray(a, 1, 3))
pro(a.toOpenArray(1,3))
doAssert fn1(a.toOpenArray(1,3)) == @[2,3,4]

doAssert fn2(toOpenArray(a, 1, 3)) == @[2,3,4]
doAssert fn2(a.toOpenArray(1,3)) == @[2,3,4]

fn3(a.toOpenArray(1,3))
when defined(js): discard # xxx bug #15952: `a` left unchanged
else: doAssert a == [1, 0, 10, 20, 5]

main()
# static: main() # xxx bug #15952: Error: cannot generate code for: mSlice

0 comments on commit 21e60b9

Please sign in to comment.