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

builtin: add string.replace_char and string.normalize_tabs (#15239)

This commit is contained in:
l-m
2022-07-28 05:04:39 +10:00
committed by GitHub
parent 60094d95e2
commit 10f3c9f127
2 changed files with 81 additions and 0 deletions

View File

@@ -380,6 +380,18 @@ fn test_replace_each() {
assert s2.replace_each(['hello_world', 'aaa', 'hello', 'bbb']) == 'aaa bbb'
}
fn test_replace_char() {
assert 'azert'.replace_char(`z`, `s`, 2) == 'assert'
assert '\rHello!\r'.replace_char(`\r`, `\n`, 1) == '\nHello!\n'
assert 'Hello!'.replace_char(`l`, `e`, 4) == 'Heeeeeeeeeo!'
assert '1141'.replace_char(`1`, `8`, 2) == '8888488'
}
fn test_normalize_tabs() {
assert '\t\tHello!'.normalize_tabs(4) == ' Hello!'
assert '\t\tHello!\t; greeting'.normalize_tabs(1) == ' Hello! ; greeting'
}
fn test_itoa() {
num := 777
assert num.str() == '777'