Raise IndexDefect when deleting element at out of bounds index (#17821)

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Heiko Nickerl <mail@hnicke.de>
Co-authored-by: Heiko Nickerl <heiko.nickerl@flipapp.de>
This commit is contained in:
Heiko Nickerl 2021-06-20 17:56:33 +02:00 • committed by GitHub
commit 92cb765714
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 36 deletions

View file

@ -2,9 +2,10 @@ discard """
targets: "c cpp js"
"""
import stdtest/testutils
# TODO: in future work move existing `system` tests here, where they belong
import stdtest/testutils
template main =
block: # closure
@ -42,5 +43,34 @@ template main =
# doAssert rawEnv(inner3) != rawEnv(inner1) # because `a` vs `b` # this doesn't hold
outer()
block: # system.delete
block:
var s = @[1]
s.delete(0)
doAssert s == @[]
block:
var s = @["foo", "bar"]
s.delete(1)
doAssert s == @["foo"]
block:
var s: seq[string]
doAssertRaises(IndexDefect):
s.delete(0)
block:
doAssert not compiles(@["foo"].delete(-1))
block: # bug #6710
var s = @["foo"]
s.delete(0)
doAssert s == @[]
block: # bug #16544: deleting out of bounds index should raise
var s = @["foo"]
doAssertRaises(IndexDefect):
s.delete(1)
static: main()
main()