1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

strings: add Builder.write_rune/1 and Builder.write_runes/1 methods

This commit is contained in:
Delyan Angelov
2021-08-19 07:14:20 +03:00
parent 26b77515b9
commit fe08e1c504
3 changed files with 46 additions and 7 deletions

View File

@@ -2,6 +2,8 @@ import strings
type MyInt = int
const maxn = 100000
fn test_sb() {
mut sb := strings.new_builder(100)
sb.write_string('hi')
@@ -40,10 +42,6 @@ fn test_sb() {
//}
}
const (
maxn = 100000
)
fn test_big_sb() {
mut sb := strings.new_builder(100)
mut sb2 := strings.new_builder(10000)
@@ -94,3 +92,23 @@ fn test_cut_to() {
assert sb.cut_to(32) == ''
assert sb.len == 0
}
fn test_write_rune() {
mut sb := strings.new_builder(10)
sb.write_rune(`h`)
sb.write_rune(`e`)
sb.write_rune(`l`)
sb.write_rune(`l`)
sb.write_rune(`o`)
x := sb.str()
assert x == 'hello'
}
fn test_write_runes() {
mut sb := strings.new_builder(20)
sb.write_runes([`h`, `e`, `l`, `l`, `o`])
sb.write_rune(` `)
sb.write_runes([`w`, `o`, `r`, `l`, `d`])
x := sb.str()
assert x == 'hello world'
}