|
@@ -263,6 +263,120 @@ static void testAsHashMapKey() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void testStartsWith() {
|
|
|
+ String s;
|
|
|
+ CORE_TEST_FALSE(s.append("0123456789"));
|
|
|
+
|
|
|
+ String s2;
|
|
|
+ CORE_TEST_FALSE(s2.append("123"));
|
|
|
+ String s3;
|
|
|
+ CORE_TEST_FALSE(s3.append("234"));
|
|
|
+ String s4;
|
|
|
+ CORE_TEST_FALSE(s4.append("789"));
|
|
|
+ String s5;
|
|
|
+ CORE_TEST_FALSE(s5.append("124"));
|
|
|
+ String s6;
|
|
|
+ String s7;
|
|
|
+ CORE_TEST_FALSE(s7.append("7891"));
|
|
|
+
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s2));
|
|
|
+ CORE_TEST_TRUE(s.startsWidth(s2, 1));
|
|
|
+
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s3));
|
|
|
+ CORE_TEST_TRUE(s.startsWidth(s3, 2));
|
|
|
+
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s4));
|
|
|
+ CORE_TEST_TRUE(s.startsWidth(s4, 7));
|
|
|
+
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s5));
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s5, 3));
|
|
|
+
|
|
|
+ CORE_TEST_TRUE(s.startsWidth(s6));
|
|
|
+ CORE_TEST_TRUE(s.startsWidth(s6, 3));
|
|
|
+
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s7));
|
|
|
+ CORE_TEST_FALSE(s.startsWidth(s7, 7));
|
|
|
+}
|
|
|
+
|
|
|
+static void testSearch() {
|
|
|
+ String s;
|
|
|
+ CORE_TEST_FALSE(s.append("0123456789"));
|
|
|
+
|
|
|
+ String s2;
|
|
|
+ CORE_TEST_FALSE(s2.append("123"));
|
|
|
+ String s3;
|
|
|
+ CORE_TEST_FALSE(s3.append("234"));
|
|
|
+ String s4;
|
|
|
+ CORE_TEST_FALSE(s4.append("789"));
|
|
|
+ String s5;
|
|
|
+ CORE_TEST_FALSE(s5.append("124"));
|
|
|
+ String s6;
|
|
|
+ String s7;
|
|
|
+ CORE_TEST_FALSE(s7.append("7891"));
|
|
|
+
|
|
|
+ CORE_TEST_EQUAL(1, s.search(s2));
|
|
|
+ CORE_TEST_EQUAL(2, s.search(s3));
|
|
|
+ CORE_TEST_EQUAL(7, s.search(s4));
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s5));
|
|
|
+ CORE_TEST_EQUAL(0, s.search(s6));
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s7));
|
|
|
+
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s2, 3));
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s3, 3));
|
|
|
+ CORE_TEST_EQUAL(7, s.search(s4, 3));
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s5, 3));
|
|
|
+ CORE_TEST_EQUAL(3, s.search(s6, 3));
|
|
|
+ CORE_TEST_EQUAL(-1, s.search(s7, 3));
|
|
|
+}
|
|
|
+
|
|
|
+static void testContains() {
|
|
|
+ String s;
|
|
|
+ CORE_TEST_FALSE(s.append("0123456789"));
|
|
|
+
|
|
|
+ String s2;
|
|
|
+ CORE_TEST_FALSE(s2.append("123"));
|
|
|
+ String s3;
|
|
|
+ CORE_TEST_FALSE(s3.append("234"));
|
|
|
+ String s4;
|
|
|
+ CORE_TEST_FALSE(s4.append("789"));
|
|
|
+ String s5;
|
|
|
+ CORE_TEST_FALSE(s5.append("124"));
|
|
|
+ String s6;
|
|
|
+ String s7;
|
|
|
+ CORE_TEST_FALSE(s7.append("7891"));
|
|
|
+
|
|
|
+ CORE_TEST_TRUE(s.contains(s2));
|
|
|
+ CORE_TEST_TRUE(s.contains(s3));
|
|
|
+ CORE_TEST_TRUE(s.contains(s4));
|
|
|
+ CORE_TEST_FALSE(s.contains(s5));
|
|
|
+ CORE_TEST_TRUE(s.contains(s6));
|
|
|
+ CORE_TEST_FALSE(s.contains(s7));
|
|
|
+}
|
|
|
+
|
|
|
+static void testSearchChar() {
|
|
|
+ String s;
|
|
|
+ CORE_TEST_FALSE(s.append("01üää3ä"));
|
|
|
+
|
|
|
+ CORE_TEST_EQUAL(0, s.search(U'0'));
|
|
|
+ CORE_TEST_EQUAL(1, s.search(U'1'));
|
|
|
+ CORE_TEST_EQUAL(2, s.search(U'ü'));
|
|
|
+ CORE_TEST_EQUAL(3, s.search(U'ä'));
|
|
|
+ CORE_TEST_EQUAL(4, s.search(U'ä', 4));
|
|
|
+ CORE_TEST_EQUAL(5, s.search(U'3'));
|
|
|
+ CORE_TEST_EQUAL(6, s.search(U'ä', 5));
|
|
|
+}
|
|
|
+
|
|
|
+static void testContainsChar() {
|
|
|
+ String s;
|
|
|
+ CORE_TEST_FALSE(s.append("01üää3ä"));
|
|
|
+
|
|
|
+ CORE_TEST_TRUE(s.contains(U'0'));
|
|
|
+ CORE_TEST_TRUE(s.contains(U'1'));
|
|
|
+ CORE_TEST_TRUE(s.contains(U'ü'));
|
|
|
+ CORE_TEST_TRUE(s.contains(U'ä'));
|
|
|
+ CORE_TEST_FALSE(s.contains(U'ö'));
|
|
|
+}
|
|
|
+
|
|
|
void Core::ArrayStringTests::test() {
|
|
|
testEquality();
|
|
|
testUnicodeEquality();
|
|
@@ -292,4 +406,9 @@ void Core::ArrayStringTests::test() {
|
|
|
testHashCode();
|
|
|
testAddSelf();
|
|
|
testAsHashMapKey();
|
|
|
+ testStartsWith();
|
|
|
+ testSearch();
|
|
|
+ testContains();
|
|
|
+ testSearchChar();
|
|
|
+ testContainsChar();
|
|
|
}
|