summary refs log tree commit diff stats
path: root/tests/stdlib/tstdlib_issues.nim
blob: 323bf09c6c1ffb7d74ebedfaeff2bd24d2718ef9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type *
discard """
output: '''
02
1
2
3
4
5
9
b = true
123456789
Second readLine raised an exception
123456789
1
2aaaaaaaa
3bbbbbbb
'''
"""

import terminal, colors, re, encodings, strutils, os


block t9394:
  let codeFg = ansiForegroundColorCode(colAliceBlue)
  let codeBg = ansiBackgroundColorCode(colAliceBlue)

  doAssert codeFg == "\27[38;2;240;248;255m"
  doAssert codeBg == "\27[48;2;240;248;255m"



block t5382:
  let regexp = re"^\/([0-9]{2})\.html$"
  var matches: array[1, string]
  discard "/02.html".find(regexp, matches)
  echo matches[0]



block tcount:
  # bug #1845, #2224
  var arr = [3,2,1,5,4]

  # bubble sort
  for i in low(arr)..high(arr):
    for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeDefect]
      if arr[i] > arr[j]:
        let tmp = arr[i]
        arr[i] = arr[j]
        arr[j] = tmp

  for i in low(arr)..high(arr):
    echo arr[i]

  # check this terminates:
  for x in countdown('\255', '\0'):
    discard



block t8468:
  when defined(windows):
    var utf16to8 = open(destEncoding = "utf-16", srcEncoding = "utf-8")
    var s = "some string"
    var c = utf16to8.convert(s)

    var z = newStringOfCap(s.len * 2)
    for x in s:
      z.add x
      z.add chr(0)

    doAssert z == c



block t5349:
  const fn = "file9char.txt"
  writeFile(fn, "123456789")

  var f = system.open(fn)
  echo getFileSize(f)

  var line = newString(10)
  try:
    let b = readLine(f, line)
    echo "b = ", b
  except:
    echo "First readLine raised an exception"
  echo line

  try:
    line = readLine(f)
    let b = readLine(f, line)
    echo "b = ", b
  except:
    echo "Second readLine raised an exception"
  echo line
  f.close()

  removeFile(fn)
  # bug #8961
  writeFile("test.txt", "1\C\L2aaaaaaaa\C\L3bbbbbbb")

  for line in lines("test.txt"):
    echo line

block t9456:
  var f: File
  f.close()