diff options
| author | Adam Zadrożny <zadroznyadam@protonmail.com> | 2024-12-04 14:29:49 +0100 |
|---|---|---|
| committer | Adam Zadrożny <zadroznyadam@protonmail.com> | 2024-12-04 14:29:49 +0100 |
| commit | 5dfc24882fb9ed40c79e60963dbfdbccd3c82450 (patch) | |
| tree | 55f5a9607a1e3b2939d470d3879cb82198932cc2 /tests/core/strings | |
| parent | c79466ab3cdc95d436752d37370336423c749211 (diff) | |
improve `strings.index_multi`
There's no point searching for substrings after lowest_index,
so let's not.
This significantly improves performance on long strings.
Diffstat (limited to 'tests/core/strings')
| -rw-r--r-- | tests/core/strings/test_core_strings.odin | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/core/strings/test_core_strings.odin b/tests/core/strings/test_core_strings.odin index 0d94b9c62..0304ec226 100644 --- a/tests/core/strings/test_core_strings.odin +++ b/tests/core/strings/test_core_strings.odin @@ -40,6 +40,25 @@ test_last_index_any_small_string_not_found :: proc(t: ^testing.T) { testing.expect(t, index == -1, "last_index_any should be -1") } +@test +test_index_multi_overlapping_substrs :: proc(t: ^testing.T) { + index, width := strings.index_multi("some example text", {"ample", "exam"}) + testing.expect_value(t, index, 5) + testing.expect_value(t, width, 4) +} + +@test +test_index_multi_not_found :: proc(t: ^testing.T) { + index, width := strings.index_multi("some example text", {"ey", "tey"}) + testing.expect_value(t, index, -1) +} + +@test +test_index_multi_with_empty_string :: proc(t: ^testing.T) { + index, width := strings.index_multi("some example text", {"ex", ""}) + testing.expect_value(t, index, -1) +} + Cut_Test :: struct { input: string, offset: int, |