builtin: rewrite string.split_nth and fix some bugs (#7189)

This commit is contained in:
Andréas Livet 2020-12-08 09:51:47 +01:00 committed by GitHub
parent 8931d3d39c
commit a2ec52b8c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 25 deletions

View file

@ -138,8 +138,8 @@ fn test_split_nth() {
assert (d.split_nth(',', -1).len == 2)
assert (d.split_nth(',', 3).len == 2)
e := ",,,0,,,,,a,,b,"
// assert (e.split(',,').len == 5)
// assert (e.split_nth(',,', 3).len == 2)
assert (e.split(',,').len == 5)
assert (e.split_nth(',,', 3).len == 3)
assert (e.split_nth(',', -1).len == 12)
assert (e.split_nth(',', 3).len == 3)
}
@ -213,6 +213,12 @@ fn test_split() {
assert a[4] == 'o'
assert a[5] == 'm'
assert a[6] == 'e'
// /////////
s = 'wavy turquoise bags'
vals = s.split(' bags')
assert vals.len == 2
assert vals[0] == 'wavy turquoise'
assert vals[1] == ''
}
fn test_trim_space() {