Add String.count to count the number of instances of a string.

This commit is contained in:
Christoffer Lerno
2025-05-02 21:48:04 +02:00
parent a411f20762
commit d313afa487
3 changed files with 49 additions and 0 deletions

View File

@@ -14,6 +14,22 @@ fn void test_starts_with()
assert(!s.starts_with("o"));
}
fn void test_count()
{
String s = "aaabcabd";
assert(s.count("a") == 4);
assert(s.count("aa") == 1);
assert(s.count("ab") == 2);
assert(s.count("") == 0);
assert(s.count("e") == 0);
String s2 = "abbccc";
assert(s2.count("a") == 1);
assert(s2.count("b") == 2);
assert(s2.count("c") == 3);
assert(s2.count("ab") == 1);
assert(s2.count(" ") == 0);
}
fn void quick_zstr()
{
String str = "1234";