| | 1 | | #pragma rtGlobals=3 |
| | 2 | | #pragma TextEncoding="UTF-8" |
| | 3 | | #pragma rtFunctionErrors=1 |
| | 4 | | #pragma version=1.10 |
| | 5 | | #pragma ModuleName=TEST_Utils_Strings |
| | 6 | |
|
| 1 | 7 | | static Function Test_IsPrefix() |
| 1 | 8 | | INFO("Expect \"%s\" is prefix of \"%s\"", s2 = "abcde", s1 = "abcde") |
| 1 | 9 | | CHECK(IUTF_Utils_Strings#IsPrefix("abcde", "abcde")) |
| 1 | 10 | | INFO("Expect \"%s\" is prefix of \"%s\"", s2 = "abcde", s1 = "abc") |
| 1 | 11 | | CHECK(IUTF_Utils_Strings#IsPrefix("abcde", "abc")) |
| 1 | 12 | | INFO("Expect \"%s\" is no prefix of \"%s\"", s2 = "abcde", s1 = "cde") |
| 1 | 13 | | CHECK(!IUTF_Utils_Strings#IsPrefix("abcde", "cde")) |
| 1 | 14 | | End |
| | 15 | |
|
| 1 | 16 | | static Function Test_ReplaceAllRegex() |
| 1 | 17 | | // empty text |
| 1 | 18 | | CHECK_EQUAL_STR("", IUTF_Utils_Strings#ReplaceAllRegex("", "", "")) |
| 1 | 19 | | CHECK_EQUAL_STR("", IUTF_Utils_Strings#ReplaceAllRegex(".*", "", "abc")) |
| | 20 | |
|
| 1 | 21 | | // replaces simple patterns |
| 1 | 22 | | CHECK_EQUAL_STR("b", IUTF_Utils_Strings#ReplaceAllRegex("a", "a", "b")) |
| 1 | 23 | | CHECK_EQUAL_STR("b b", IUTF_Utils_Strings#ReplaceAllRegex("a", "a a", "b")) |
| 1 | 24 | | CHECK_EQUAL_STR("b b ", IUTF_Utils_Strings#ReplaceAllRegex("a", "a a ", "b")) |
| | 25 | |
|
| 1 | 26 | | // replaces more complex patterns |
| 1 | 27 | | CHECK_EQUAL_STR("cbacba", IUTF_Utils_Strings#ReplaceAllRegex("(?<!b)a", "abaaba", "c")) |
| 1 | 28 | | End |
| | 29 | |
|
| 1 | 30 | | static Function Test_CountRegex() |
| 1 | 31 | | // empty text |
| 1 | 32 | | CHECK_EQUAL_VAR(0, IUTF_Utils_Strings#CountRegex("", "")) |
| 1 | 33 | | CHECK_EQUAL_VAR(0, IUTF_Utils_Strings#CountRegex(".*", "")) |
| | 34 | |
|
| 1 | 35 | | // replaces simple patterns |
| 1 | 36 | | CHECK_EQUAL_VAR(1, IUTF_Utils_Strings#CountRegex("a", "a")) |
| 1 | 37 | | CHECK_EQUAL_VAR(2, IUTF_Utils_Strings#CountRegex("a", "a a")) |
| 1 | 38 | | CHECK_EQUAL_VAR(2, IUTF_Utils_Strings#CountRegex("a", "a a ")) |
| | 39 | |
|
| 1 | 40 | | // replaces more complex patterns |
| 1 | 41 | | CHECK_EQUAL_VAR(2, IUTF_Utils_Strings#CountRegex("(?<!b)a", "abaaba")) |
| 1 | 42 | | End |