1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/strings/builder_test.v
2019-11-11 08:24:28 +03:00

41 lines
687 B
V

import strings
fn test_sb() {
mut sb := strings.Builder{}
sb.write('hi')
sb.write('!')
sb.write('hello')
assert sb.str() == 'hi!hello'
assert sb.len == 8
sb = strings.new_builder(10)
sb.write('a')
sb.write('b')
println(sb.str())
assert sb.str() == 'ab'
assert sb.len == 2
}
const (
n = 100000
)
fn test_big_sb() {
mut sb := strings.new_builder(100)
mut sb2 := strings.new_builder(10000)
for i in 0..n {
sb.writeln(i.str())
sb2.write('+')
}
s := sb.str()
lines := s.split_into_lines()
assert lines.len == n
assert lines[0] == '0'
assert lines[1] == '1'
assert lines[777] == '777'
assert lines[98765] == '98765'
println(sb2.len)
assert sb2.len == n
}