mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
* followup #17001: improve coverage for tests/openarray/topenarray.nim
(cherry picked from commit 21e60b9a97)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user