tindexerrorformatbounds.nim 893 B

1234567891011121314151617181920212223242526272829303132
  1. import os, osproc, strutils
  2. const characters = "abcdefghijklmnopqrstuvwxyz"
  3. var s: string
  4. # # chcks.nim:23
  5. # # test formatErrorIndexBound returns correct bounds
  6. block:
  7. s = characters
  8. try:
  9. discard s[0..999]
  10. except IndexError:
  11. let msg = getCurrentExceptionMsg()
  12. let expected = "index $# not in 0 .. $#" % [$len(s), $(len(s)-1)]
  13. doAssert msg.contains expected, $(msg, expected)
  14. block:
  15. try:
  16. discard paramStr(999)
  17. except IndexError:
  18. let msg = getCurrentExceptionMsg()
  19. let expected = "index 999 not in 0 .. 0"
  20. doAssert msg.contains expected, $(msg, expected)
  21. block:
  22. const nim = getCurrentCompilerExe()
  23. for i in 1..4:
  24. let (outp, errC) = execCmdEx("$# e tests/exception/testindexerroroutput.nims test$#" % [nim, $i])
  25. let expected = "index 3 not in 0 .. 2"
  26. doAssert errC != 0
  27. doAssert outp.contains expected, $(outp, errC, expected, i)