tstdlib_issues.nim 1.9 KB

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