forked from Mirror/wren
Split and replace in wren.
This commit is contained in:
17
test/core/string/replace.wren
Normal file
17
test/core/string/replace.wren
Normal file
@ -0,0 +1,17 @@
|
||||
System.print("something".replace("some", "no")) // expect: nothing
|
||||
System.print("something".replace("thing", "one")) // expect: someone
|
||||
System.print("something".replace("ometh", "umm")) // expect: summing
|
||||
System.print("something".replace("math", "ton")) // expect: something
|
||||
|
||||
// Multiple.
|
||||
System.print("somethingsomething".replace("some", "no")) // expect: nothingnothing
|
||||
System.print("abc abc abc".replace(" ", "")) // expect: abcabcabc
|
||||
System.print("abcabcabc".replace("abc", "")) // expect:
|
||||
|
||||
// Non-ASCII.
|
||||
System.print("søméthîng".replace("sømé", "nø")) // expect: nøthîng
|
||||
System.print("søméthîng".replace("meth", "ton")) // expect: søméthîng
|
||||
|
||||
// 8-bit clean.
|
||||
System.print("a\0b\0c".replace("\0", "")) // expect: abc
|
||||
System.print("a\0b\0c".replace("b", "") == "a\0\0c") // expect: true
|
||||
1
test/core/string/replace_empty_old.wren
Normal file
1
test/core/string/replace_empty_old.wren
Normal file
@ -0,0 +1 @@
|
||||
"foo".replace("", "f") // expect runtime error: From must be a non-empty string.
|
||||
1
test/core/string/replace_new_not_string.wren
Normal file
1
test/core/string/replace_new_not_string.wren
Normal file
@ -0,0 +1 @@
|
||||
"foo".replace("o", 1) // expect runtime error: To must be a string.
|
||||
1
test/core/string/replace_old_not_string.wren
Normal file
1
test/core/string/replace_old_not_string.wren
Normal file
@ -0,0 +1 @@
|
||||
"foo".replace(1, "o") // expect runtime error: From must be a non-empty string.
|
||||
16
test/core/string/split.wren
Normal file
16
test/core/string/split.wren
Normal file
@ -0,0 +1,16 @@
|
||||
System.print("something".split("meth")) // expect: [so, ing]
|
||||
System.print("something".split("some")) // expect: [, thing]
|
||||
System.print("something".split("ing")) // expect: [someth, ]
|
||||
System.print("something".split("math")) // expect: [something]
|
||||
|
||||
// Multiple.
|
||||
System.print("somethingsomething".split("meth")) // expect: [so, ingso, ing]
|
||||
System.print("abc abc abc".split(" ")) // expect: [abc, abc, abc]
|
||||
System.print("abcabcabc".split("abc")) // expect: [, , , ]
|
||||
|
||||
// Non-ASCII.
|
||||
System.print("søméthîng".split("méth")) // expect: [sø, îng]
|
||||
System.print("søméthîng".split("meth")) // expect: [søméthîng]
|
||||
|
||||
// 8-bit clean.
|
||||
System.print("a\0b\0c".split("\0")) // expect: [a, b, c]
|
||||
1
test/core/string/split_argument_not_string.wren
Normal file
1
test/core/string/split_argument_not_string.wren
Normal file
@ -0,0 +1 @@
|
||||
"foo".split(1) // expect runtime error: Argument must be a non-empty string.
|
||||
1
test/core/string/split_empty_seperator.wren
Normal file
1
test/core/string/split_empty_seperator.wren
Normal file
@ -0,0 +1 @@
|
||||
"foo".split("") // expect runtime error: Argument must be a non-empty string.
|
||||
Reference in New Issue
Block a user