1
0
forked from Mirror/wren

Split and replace in wren.

This commit is contained in:
Andew Jones
2017-03-07 21:12:03 -05:00
parent 4fe3ad3f8b
commit 32aa43d1df
10 changed files with 158 additions and 0 deletions

View 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

View File

@ -0,0 +1 @@
"foo".replace("", "f") // expect runtime error: From must be a non-empty string.

View File

@ -0,0 +1 @@
"foo".replace("o", 1) // expect runtime error: To must be a string.

View File

@ -0,0 +1 @@
"foo".replace(1, "o") // expect runtime error: From must be a non-empty string.

View 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]

View File

@ -0,0 +1 @@
"foo".split(1) // expect runtime error: Argument must be a non-empty string.

View File

@ -0,0 +1 @@
"foo".split("") // expect runtime error: Argument must be a non-empty string.