summary refs log tree commit diff stats
path: root/tests/exception/tindexerrorformatbounds.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/exception/tindexerrorformatbounds.nim')
-rw-r--r--tests/exception/tindexerrorformatbounds.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/exception/tindexerrorformatbounds.nim b/tests/exception/tindexerrorformatbounds.nim
new file mode 100644
index 000000000..7563c5ffa
--- /dev/null
+++ b/tests/exception/tindexerrorformatbounds.nim
@@ -0,0 +1,31 @@
+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)