tstdlib_issues.nim 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. discard """
  2. output: '''
  3. 02
  4. 1
  5. 2
  6. 3
  7. 4
  8. 5
  9. 9
  10. b = true
  11. 123456789
  12. Second readLine raised an exception
  13. 123456789
  14. 1
  15. 2aaaaaaaa
  16. 3bbbbbbb
  17. '''
  18. """
  19. import terminal, colors, re, encodings, strutils, os
  20. block t9394:
  21. let codeFg = ansiForegroundColorCode(colAliceBlue)
  22. let codeBg = ansiBackgroundColorCode(colAliceBlue)
  23. doAssert codeFg == "\27[38;2;240;248;255m"
  24. doAssert codeBg == "\27[48;2;240;248;255m"
  25. block t5382:
  26. let regexp = re"^\/([0-9]{2})\.html$"
  27. var matches: array[1, string]
  28. discard "/02.html".find(regexp, matches)
  29. echo matches[0]
  30. block tcount:
  31. # bug #1845, #2224
  32. var arr = [3,2,1,5,4]
  33. # bubble sort
  34. for i in low(arr)..high(arr):
  35. for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeDefect]
  36. if arr[i] > arr[j]:
  37. let tmp = arr[i]
  38. arr[i] = arr[j]
  39. arr[j] = tmp
  40. for i in low(arr)..high(arr):
  41. echo arr[i]
  42. # check this terminates:
  43. for x in countdown('\255', '\0'):
  44. discard
  45. block t8468:
  46. when defined(windows):
  47. var utf16to8 = open(destEncoding = "utf-16", srcEncoding = "utf-8")
  48. var s = "some string"
  49. var c = utf16to8.convert(s)
  50. var z = newStringOfCap(s.len * 2)
  51. for x in s:
  52. z.add x
  53. z.add chr(0)
  54. doAssert z == c
  55. block t5349:
  56. const fn = "file9char.txt"
  57. writeFile(fn, "123456789")
  58. var f = system.open(fn)
  59. echo getFileSize(f)
  60. var line = newString(10)
  61. try:
  62. let b = readLine(f, line)
  63. echo "b = ", b
  64. except:
  65. echo "First readLine raised an exception"
  66. echo line
  67. try:
  68. line = readLine(f)
  69. let b = readLine(f, line)
  70. echo "b = ", b
  71. except:
  72. echo "Second readLine raised an exception"
  73. echo line
  74. f.close()
  75. removeFile(fn)
  76. # bug #8961
  77. writeFile("test.txt", "1\C\L2aaaaaaaa\C\L3bbbbbbb")
  78. for line in lines("test.txt"):
  79. echo line
  80. block t9456:
  81. var f: File
  82. f.close()