From d73b19967dd087608f2dce779ffdaa7f242ebb18 Mon Sep 17 00:00:00 2001 From: Marco Lizza Date: Wed, 4 Feb 2015 13:58:16 +0100 Subject: [PATCH] Adding 8-bit strings test cases. --- test/string/concatenation.wren | 3 +++ test/string/contains.wren | 6 ++++++ test/string/count.wren | 6 ++++++ test/string/ends_with.wren | 6 ++++++ test/string/equality.wren | 5 +++++ test/string/index_of.wren | 7 +++++++ test/string/iterate.wren | 8 ++++++++ test/string/iterator_value.wren | 8 ++++++++ test/string/join.wren | 5 +++++ test/string/starts_with.wren | 5 +++++ test/string/subscript.wren | 7 +++++++ test/string/to_string.wren | 5 +++++ 12 files changed, 71 insertions(+) diff --git a/test/string/concatenation.wren b/test/string/concatenation.wren index a3417b46..60df5588 100644 --- a/test/string/concatenation.wren +++ b/test/string/concatenation.wren @@ -1 +1,4 @@ IO.print("a" + "b") // expect: ab + +// 8-bit clean +IO.print(("a\0b" + "\0c") == "a\0b\0c") // expect: true diff --git a/test/string/contains.wren b/test/string/contains.wren index f86bcf58..301aedd1 100644 --- a/test/string/contains.wren +++ b/test/string/contains.wren @@ -8,3 +8,9 @@ IO.print("something".contains("math")) // expect: false // Non-ASCII. IO.print("søméthîng".contains("méth")) // expect: true IO.print("søméthîng".contains("meth")) // expect: false + +// 8-bit clean +IO.print("a\0b\0c".contains("\0")) // expect: true +IO.print("a\0b\0c".contains("b")) // expect: true +IO.print("a\0b\0c".contains("b\0c")) // expect: true +IO.print("a\0b\0c".contains("bc")) // expect: false diff --git a/test/string/count.wren b/test/string/count.wren index d7af9f3b..686f9b08 100644 --- a/test/string/count.wren +++ b/test/string/count.wren @@ -1,2 +1,8 @@ IO.print("".count) // expect: 0 IO.print("a string".count) // expect: 8 + +// 8-bit clean +IO.print("\0".count) // expect: 1 +IO.print("a\0b".count) // expect: 3 +IO.print("\0c".count) // expect: 2 +IO.print(("a\0b" + "\0c").count) // expect: 5 diff --git a/test/string/ends_with.wren b/test/string/ends_with.wren index a55e6350..9859adce 100644 --- a/test/string/ends_with.wren +++ b/test/string/ends_with.wren @@ -7,3 +7,9 @@ IO.print("abcd".endsWith("")) // expect: true // Non-ASCII. IO.print("søméthîng".endsWith("thîng")) // expect: true IO.print("søméthîng".endsWith("thing")) // expect: false + +// 8-bit clean +IO.print("a\0b\0c".endsWith("\0")) // expect: false +IO.print("a\0b\0c".endsWith("c")) // expect: true +IO.print("a\0b\0c".endsWith("\0c")) // expect: true +IO.print("a\0b\0c".endsWith("\0b")) // expect: false diff --git a/test/string/equality.wren b/test/string/equality.wren index 92a3aef7..91977516 100644 --- a/test/string/equality.wren +++ b/test/string/equality.wren @@ -21,3 +21,8 @@ IO.print("true" != true) // expect: true // Non-ASCII. IO.print("vålue" == "value") // expect: false IO.print("vålue" == "vålue") // expect: true + +// 8-bit clean +IO.print("a\0b\0c" == "a") // expect: false +IO.print("a\0b\0c" == "abc") // expect: false +IO.print("a\0b\0c" == "a\0b\0c") // expect: true diff --git a/test/string/index_of.wren b/test/string/index_of.wren index 8ee67978..b72c9a6a 100644 --- a/test/string/index_of.wren +++ b/test/string/index_of.wren @@ -7,3 +7,10 @@ IO.print("abab".indexOf("ab")) // expect: 0 IO.print("søméஃthîng".indexOf("e")) // expect: -1 IO.print("søméஃthîng".indexOf("m")) // expect: 3 IO.print("søméஃthîng".indexOf("thî")) // expect: 9 + +// 8-bit clean +IO.print("a\0b\0c".indexOf("\0")) // expect: 1 +IO.print("a\0b\0c".indexOf("a")) // expect: 0 +IO.print("a\0b\0c".indexOf("b\0c")) // expect: 2 +IO.print("a\0b\0c".indexOf("a\0b\0c\0d")) // expect: -1 +IO.print("a\0b\0a\0b".indexOf("a\0b")) // expect: 0 diff --git a/test/string/iterate.wren b/test/string/iterate.wren index e79861b6..9a32d570 100644 --- a/test/string/iterate.wren +++ b/test/string/iterate.wren @@ -14,3 +14,11 @@ IO.print(s.iterate(-1)) // expect: false // Nothing to iterate in an empty string. IO.print("".iterate(null)) // expect: false + +// 8-bit clean +IO.print("a\0b\0c".iterate(null)) // expect: 0 +IO.print("a\0b\0c".iterate(0)) // expect: 1 +IO.print("a\0b\0c".iterate(1)) // expect: 2 +IO.print("a\0b\0c".iterate(2)) // expect: 3 +IO.print("a\0b\0c".iterate(3)) // expect: 4 +IO.print("a\0b\0c".iterate(4)) // expect: false diff --git a/test/string/iterator_value.wren b/test/string/iterator_value.wren index 343cee4d..5bc74405 100644 --- a/test/string/iterator_value.wren +++ b/test/string/iterator_value.wren @@ -5,3 +5,11 @@ IO.print(s.iteratorValue(2)) // expect: ç // Iterator value in middle of UTF sequence is an empty string. IO.print(s.iteratorValue(3) == "") // expect: true IO.print(s.iteratorValue(4)) // expect: d + +// 8-bit clean +var t = "a\0b\0c" +IO.print(t.iteratorValue(0) == "a") // expect: true +IO.print(t.iteratorValue(1) == "\0") // expect: true +IO.print(t.iteratorValue(2) == "b") // expect: true +IO.print(t.iteratorValue(3) == "\0") // expect: true +IO.print(t.iteratorValue(4) == "c") // expect: true diff --git a/test/string/join.wren b/test/string/join.wren index 6c1183c1..df71a543 100644 --- a/test/string/join.wren +++ b/test/string/join.wren @@ -3,3 +3,8 @@ var str = "string" IO.print(str.join("") == str) // expect: true IO.print(str.join(", ")) // expect: s, t, r, i, n, g + +// 8-bit clean +var ing = "a\0b\0c" +IO.print(ing.join("") == ing) // expect: true +IO.print(ing.join(", ") == "a, \0, b, \0, c") // expect: true diff --git a/test/string/starts_with.wren b/test/string/starts_with.wren index 856307e5..e537e6ae 100644 --- a/test/string/starts_with.wren +++ b/test/string/starts_with.wren @@ -7,3 +7,8 @@ IO.print("abcd".startsWith("")) // expect: true // Non-ASCII. IO.print("søméthîng".startsWith("sømé")) // expect: true IO.print("søméthîng".startsWith("some")) // expect: false + +// 8-bit clean +IO.print("a\0b\0c".startsWith("a")) // expect: true +IO.print("a\0b\0c".startsWith("a\0")) // expect: true +IO.print("a\0b\0c".startsWith("b\0")) // expect: false diff --git a/test/string/subscript.wren b/test/string/subscript.wren index 8212e32b..4556fcc6 100644 --- a/test/string/subscript.wren +++ b/test/string/subscript.wren @@ -33,3 +33,10 @@ IO.print("søméஃthîng"[7] == "") // expect: true IO.print("søméஃthîng"[8] == "") // expect: true IO.print("søméஃ"[-1] == "") // expect: true IO.print("søméஃ"[-2] == "") // expect: true + +// 8-bit clean +IO.print("a\0b\0c"[0] == "a") // expect: true +IO.print("a\0b\0c"[1] == "\0") // expect: true +IO.print("a\0b\0c"[2] == "b") // expect: true +IO.print("a\0b\0c"[3] == "\0") // expect: true +IO.print("a\0b\0c"[4] == "c") // expect: true diff --git a/test/string/to_string.wren b/test/string/to_string.wren index c7f11fd0..8a583864 100644 --- a/test/string/to_string.wren +++ b/test/string/to_string.wren @@ -1,2 +1,7 @@ IO.print("".toString == "") // expect: true IO.print("blah".toString == "blah") // expect: true + +// 8-bit clean +IO.print("a\0b\0c".toString == "a\0b\0c") // expect: true +IO.print("a\0b\0c".toString == "a") // expect: false +IO.print("a\0b\0c".toString) // expect: a