Skip to content

Commit

Permalink
tests: implement unicode tests for other string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
liz3 committed Oct 29, 2024
1 parent e8a3d35 commit 742c89f
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/strings/collapseSpaces.du
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class TestStringCollapseSpaces < UnitTest {
this.assertEquals(res, expected);
this.assertNotEquals(testString, expected);
}

testStringCollapseSpacesUnicode() {
const x = "😀🌍🐦aä";
const testString = "This is 🌍 a huge string🐦 🐦 of a lot of spaces.";
const expected = "This is 🌍 a huge string🐦 🐦 of a lot of spaces.";
const res = testString.collapseSpaces();
this.assertEquals(res, expected);
this.assertNotEquals(testString, expected);
}

}

TestStringCollapseSpaces().run();
10 changes: 10 additions & 0 deletions tests/strings/concat.du
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class TestStringConcat < UnitTest {

this.assertEquals(x, "Dictu is great!");
}
testStringConcatUnicode() {
this.assertEquals("😅" + " 😅 " + "😅", "😅 😅 😅");

const x = "Dictu" +
" 😊 " +
"great❗";

this.assertEquals(x, "Dictu 😊 great❗");
}

}

TestStringConcat().run();
6 changes: 6 additions & 0 deletions tests/strings/contains.du
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class TestStringContains < UnitTest {
this.assertTruthy("1Dictu is great!1".contains("1"));
this.assertTruthy(("1Dictu " + "is great!").contains("1"));
}
testStringContainsUnicode() {
this.assertTruthy(("❗Dictu " + "is great!").contains("❗"));
this.assertFalsey("Dictu is great!".contains("❗"));
this.assertTruthy("Dictu is ♨️ right?️".contains("♨️")); // ♨️ is two characters!

}
}

TestStringContains().run();
6 changes: 6 additions & 0 deletions tests/strings/count.du
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class TestStringCount < UnitTest {
this.assertEquals("Dictu is great! Dictu is great!".count("1234"), 0);
this.assertEquals("Dictu is great! Dictu is great!".count("!"), 2);
}
testStringCountUnicode() {
this.assertEquals("Dictu is 😎! Dictu is 😎!".count("Dictu is 😎!"), 2);
this.assertEquals("Dictu is great❗".count("❗"), 1);
this.assertEquals("Dictu is great❕ Dictu is great❕".count("❗"), 0);

}
}

TestStringCount().run();
7 changes: 7 additions & 0 deletions tests/strings/endsWith.du
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class TestStringEndsWith < UnitTest {
this.assertFalsey("test".endsWith("!@£$%"));
this.assertFalsey("test".endsWith("123456789"));
}
testStringEndsWithUnicode() {
this.assertTruthy("🌐😁⚓🌍".endsWith("🌍"));
this.assertTruthy("🌐😁⚓🌍".endsWith("⚓🌍"));
this.assertTruthy("🌐😁⚓🌍".endsWith("🌐😁⚓🌍"));
this.assertFalsey("🌐😁⚓🌍".endsWith("😅"));
this.assertFalsey("🌐😁⚓🌍".endsWith("🌐😁⚓🌍😅"));
}
}

TestStringEndsWith().run();
5 changes: 5 additions & 0 deletions tests/strings/findLast.du
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class TestStringLastIndexOf < UnitTest {
this.assertEquals("woolly woolly mammoth".findLast("woolly"), 7);
this.assertEquals("mammoth".findLast("woolly"), -1);
}
testStringLowerUnicode() {
this.assertEquals("🌐😁⚓🌍 🌐😁⚓🌍 mammoth".findLast("🌐😁⚓🌍"), 5);
this.assertEquals("🌐😁⚓🌍".findLast("😅😅"), -1);

}
}

TestStringLastIndexOf().run();
4 changes: 4 additions & 0 deletions tests/strings/format.du
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class TestStringFormat < UnitTest {
this.assertEquals("{}".format({"test": 10, "aaa": 10}), '{"aaa": 10, "test": 10}');
this.assertEquals("{} {} {}".format(test, Test, Trait), '<fn test> <Cls Test> <Trait Trait>');
}
testStringFormatUnicode() {
this.assertEquals("World: {} is {}".format("🌍", "😎"), "World: 🌍 is 😎");
this.assertEquals("hello {}".format(["🌐😁⚓🌍"]), "hello [\"🌐😁⚓🌍\"]");
}
}

TestStringFormat().run();
4 changes: 4 additions & 0 deletions tests/strings/lower.du
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class TestStringLower < UnitTest {
this.assertEquals("12Dictu45".lower(), "12dictu45");
this.assertEquals("!@£$%^&*".lower(), "!@£$%^&*");
}
testStringLowerUnicode() {
this.assertEquals("ÄÜÖ".lower(), "äüö");
this.assertEquals("DICTU🌍".lower(), "dictu🌍");
}
}

TestStringLower().run();
5 changes: 5 additions & 0 deletions tests/strings/repeat.du
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class TestStringRepeat < UnitTest {
this.assertEquals("ba" + "na".repeat(2), "banana");
this.assertEquals("ha".repeat(6), "hahahahahaha");
}
testStringRepeatUnicode() {
this.assertEquals("⌛" + "⏳".repeat(2), "⌛⏳⏳");
this.assertEquals("📃".repeat(5), "📃📃📃📃📃");
}

}

TestStringRepeat().run();
5 changes: 5 additions & 0 deletions tests/strings/replace.du
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class TestStringReplace < UnitTest {
this.assertEquals("test".replace("t", "123456789123456789123456789123456789"),
"123456789123456789123456789123456789es123456789123456789123456789123456789");
}
testStringReplaceUnicode() {
this.assertEquals("😀".replace("😀", "😅"), "😅");
this.assertEquals("😀😀".replace("😀", "😀😀"), "😀😀😀😀");
this.assertEquals("❕string❗".replace("❗", "❕❕"), "❕string❕❕");
}
}

TestStringReplace().run();
1 change: 1 addition & 0 deletions tests/strings/startsWith.du
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestStringStartsWith < UnitTest {
}
testStringStartsWithUnicode() {
this.assertTruthy("💻test".startsWith("💻t"));
this.assertTruthy("💻test".startsWith("💻test"));
this.assertFalsey("💻test".startsWith("💻te💻"));
}
}
Expand Down
13 changes: 12 additions & 1 deletion tests/strings/strip.du
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestStringStrip < UnitTest {
this.assertEquals(" Dictu is great!".rightStrip().len(), 17);
this.assertEquals(" Dictu is great! ".rightStrip().len(), 17);
}

testStringStrip() {
this.assertEquals("Dictu is great! ".strip(), "Dictu is great!");
this.assertEquals(" Dictu is great!".strip(), "Dictu is great!");
Expand All @@ -36,6 +36,17 @@ class TestStringStrip < UnitTest {
this.assertEquals(" Dictu is great!".strip().len(), 15);
this.assertEquals(" Dictu is great! ".strip().len(), 15);
}

testStringStripUnicode() {
this.assertEquals("🐦Dictu is great🐦 ".strip(), "🐦Dictu is great🐦");
this.assertEquals(" 🐦Dictu is great!🐦".strip(), "🐦Dictu is great!🐦");
this.assertEquals(" 🐦Dictu is great!🐦 ".strip(), "🐦Dictu is great!🐦");
this.assertEquals("Dictu is great🐦 ".strip().len(), 15);
this.assertEquals(" Dictu is great🐦".strip().len(), 15);
this.assertEquals(" 🐦Dictu is great🐦 ".strip().len(), 16);
}


}

TestStringStrip().run();
7 changes: 7 additions & 0 deletions tests/strings/title.du
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class TestStringTitle < UnitTest {
this.assertEquals("!@£$%^&*".title(), "!@£$%^&*");
this.assertEquals("once upon a time".title(), "Once Upon A Time");
}
testStringTitleUnicode() {
this.assertEquals("über".title(), "Über");
this.assertEquals("üBer".title(), "Über");
this.assertEquals("👻👻".title(), "👻👻");
this.assertEquals("👻👻 test".title(), "👻👻 Test");
this.assertEquals("👻👻 test üBer".title(), "👻👻 Test Über");
}
}

TestStringTitle().run();
3 changes: 3 additions & 0 deletions tests/strings/toBool.du
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class TestStringToBool < UnitTest {
this.assertTruthy("10".toBool());
this.assertFalsey("".toBool());
}
testStringToBoolUnicode() {
this.assertTruthy("💬".toBool());
}
}

TestStringToBool().run();
4 changes: 4 additions & 0 deletions tests/strings/upper.du
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class TestStringUpper < UnitTest {
this.assertEquals("12Dictu45".upper(), "12DICTU45");
this.assertEquals("!@£$%^&*".upper(), "!@£$%^&*");
}
testStringUpperUnicode() {
this.assertEquals("üäö".upper(), "ÜÄÖ");
this.assertEquals("ü🌐test".upper(), "Ü🌐TEST");
}
}

TestStringUpper().run();
4 changes: 4 additions & 0 deletions tests/strings/wordCount.du
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class TestStringWordCount < UnitTest {
this.assertEquals("This is a sentence".wordCount(), 4);
this.assertEquals("This is an even longer sentence".wordCount(), 6);
}
testStringWordCountUnicode() {
this.assertEquals("Dictu is cool😎".wordCount(), 3);
this.assertEquals("WOrld🌐 üäö".wordCount(), 2);
}
}

TestStringWordCount().run();
5 changes: 5 additions & 0 deletions tests/strings/wrap.du
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class TestStringWrap < UnitTest {
const idx = res.find("\n");
this.assertTruthy(res.find("\n") <= this.maxLen);
}
testStringWrapUnicode() {
const _len = 5;
const wrapped = "🌐test 🐦🐦🐦 test344🐦".wrap(_len);
this.assertEquals(wrapped, "🌐test\n🐦🐦🐦\ntest344🐦");
}
}

TestStringWrap().run();

0 comments on commit 742c89f

Please sign in to comment.