Skip to content

Commit 7fc83e1

Browse files
committed
tests: add a test for string's grow behaviour
1 parent 7529674 commit 7fc83e1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
discard """
2+
targets: c js vm
3+
knownIssue.js: "The new characters are not set to NUL"
4+
"""
5+
6+
var a: string
7+
a.setLen(3)
8+
doAssert a == "\0\0\0"
9+
10+
# start from a constant string
11+
var b = "abcdef"
12+
b.setLen(3)
13+
doAssert b == "abc"
14+
b.setLen(6) # grow to previous size
15+
doAssert b == "abc\0\0\0"
16+
17+
# start from a manually constructed string
18+
var c: string
19+
for _ in 0..<4:
20+
c.add 'c'
21+
c.setLen(2)
22+
doAssert c == "cc"
23+
c.setLen(4) # grow to previous size
24+
doAssert c == "cc\0\0"

0 commit comments

Comments
 (0)