1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

feat: add FindAllOccurrences

This commit is contained in:
dudaodong
2025-01-10 14:03:45 +08:00
parent a0d97cf38e
commit 7653afa919
5 changed files with 119 additions and 7 deletions

View File

@@ -937,3 +937,32 @@ func TestExtractContent(t *testing.T) {
})
}
}
func TestFindAllOccurrences(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestFindAllOccurrences")
var empty []int
tests := []struct {
input string
substr string
expected []int
}{
{"", "", empty},
{"", "a", empty},
{"a", "", []int{0}},
{"a", "a", []int{0}},
{"aa", "a", []int{0, 1}},
{"ababab", "ab", []int{0, 2, 4}},
{"ababab", "ba", []int{1, 3}},
{"ababab", "c", empty},
{"ababab", "ababab", []int{0}},
{"ababab", "abababc", empty},
{"ababab", "abababa", empty},
}
for _, tt := range tests {
assert.Equal(tt.expected, FindAllOccurrences(tt.input, tt.substr))
}
}