Files
Nim/tests/exception/tindexerrorformatbounds.nim
Timothee Cour 942495611b revive #10228 (fix #9880) (#10610)
* Make index out of bounds more useful by including the 'bounds'.
* fixes #9880 index out of bounds (remaining cases); revives #10228
* change err msg to: `index 3 not in 0 .. 1`
2019-02-13 23:30:14 +01:00

32 lines
893 B
Nim

import os, osproc, strutils
const characters = "abcdefghijklmnopqrstuvwxyz"
var s: string
# # chcks.nim:23
# # test formatErrorIndexBound returns correct bounds
block:
s = characters
try:
discard s[0..999]
except IndexError:
let msg = getCurrentExceptionMsg()
let expected = "index $# not in 0 .. $#" % [$len(s), $(len(s)-1)]
doAssert msg.contains expected, $(msg, expected)
block:
try:
discard paramStr(999)
except IndexError:
let msg = getCurrentExceptionMsg()
let expected = "index 999 not in 0 .. 0"
doAssert msg.contains expected, $(msg, expected)
block:
const nim = getCurrentCompilerExe()
for i in 1..4:
let (outp, errC) = execCmdEx("$# e tests/exception/testindexerroroutput.nims test$#" % [nim, $i])
let expected = "index 3 not in 0 .. 2"
doAssert errC != 0
doAssert outp.contains expected, $(outp, errC, expected, i)