aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/bytes_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2019-09-24 22:22:02 +0700
committerShulhan <m.shulhan@gmail.com>2019-09-24 22:38:39 +0700
commit7eacd3ade3ecc83ee59ca8ce14cb60c2082096a3 (patch)
tree431c01263c1b70a5205d7952d2da0e6ea1b45a37 /lib/bytes/bytes_test.go
parent7474d7ac41d49af9e15a5c21de99a3eaea5f68b4 (diff)
downloadpakakeh.go-7eacd3ade3ecc83ee59ca8ce14cb60c2082096a3.tar.xz
bytes: add function get all indexes of token in string
Diffstat (limited to 'lib/bytes/bytes_test.go')
-rw-r--r--lib/bytes/bytes_test.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/bytes/bytes_test.go b/lib/bytes/bytes_test.go
index 938f4ca1..66b04e6a 100644
--- a/lib/bytes/bytes_test.go
+++ b/lib/bytes/bytes_test.go
@@ -171,7 +171,7 @@ func TestIsTokenAt(t *testing.T) {
p int
exp bool
}{{
- // empty
+ // empty
}, {
token: []byte("world"),
p: -1,
@@ -332,3 +332,31 @@ func TestInReplace(t *testing.T) {
test.Assert(t, "InReplace", c.exp, string(got), true)
}
}
+
+func TestIndexes(t *testing.T) {
+ cases := []struct {
+ desc string
+ s []byte
+ token []byte
+ exp []int
+ }{{
+ desc: "With empty string",
+ token: []byte("moo"),
+ }, {
+ desc: "With empty token",
+ s: []byte("moo moo"),
+ }, {
+ desc: "With non empty string and token",
+ s: []byte("moo moomoo"),
+ token: []byte("moo"),
+ exp: []int{0, 4, 7},
+ }}
+
+ for _, c := range cases {
+ t.Log(c.desc)
+
+ got := Indexes(c.s, c.token)
+
+ test.Assert(t, "Indexes", c.exp, got, true)
+ }
+}