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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
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 [RangeError]
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()
|