Merge pull request #7967 from nitely/empty_openarray_7904

support empty toOpenArray
This commit is contained in:
Andreas Rumpf 2018-06-06 11:06:57 +02:00 • committed by GitHub
commit 1593b9cac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 10 deletions

View file

@ -11,6 +11,10 @@ discard """
2
3
4
2
1
2
3
'''
"""
@ -47,3 +51,38 @@ foo(toOpenArray(arr, 8, 12))
var seqq = @[1, 2, 3, 4, 5]
foo(toOpenArray(seqq, 1, 3))
# empty openArray issue #7904
foo(toOpenArray(seqq, 0, -1))
foo(toOpenArray(seqq, 1, 0))
doAssertRaises(IndexError):
foo(toOpenArray(seqq, 0, -2))
foo(toOpenArray(arr, 9, 8))
foo(toOpenArray(arr, 0, -1))
foo(toOpenArray(arr, 1, 0))
doAssertRaises(IndexError):
foo(toOpenArray(arr, 10, 8))
# test openArray of openArray
proc oaEmpty(a: openArray[int]) =
foo(toOpenArray(a, 0, -1))
proc oaFirstElm(a: openArray[int]) =
foo(toOpenArray(a, 0, 0))
oaEmpty(toOpenArray(seqq, 0, -1))
oaEmpty(toOpenArray(seqq, 1, 0))
oaEmpty(toOpenArray(seqq, 1, 2))
oaFirstElm(toOpenArray(seqq, 1, seqq.len-1))
var arrNeg: array[-3 .. -1, int] = [1, 2, 3]
foo(toOpenArray(arrNeg, -3, -1))
foo(toOpenArray(arrNeg, 0, -1))
foo(toOpenArray(arrNeg, -3, -4))
doAssertRaises(IndexError):
foo(toOpenArray(arrNeg, -4, -1))
doAssertRaises(IndexError):
foo(toOpenArray(arrNeg, -1, 0))
doAssertRaises(IndexError):
foo(toOpenArray(arrNeg, -1, -3))