MCPcopy Create free account
hub / github.com/sergi/go-diff / TestIndexOf

Function TestIndexOf

diffmatchpatch/stringutil_test.go:44–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func TestIndexOf(t *testing.T) {
45 type TestCase struct {
46 String string
47 Pattern string
48 Position int
49
50 Expected int
51 }
52
53 for i, tc := range []TestCase{
54 {"hi world", "world", -1, 3},
55 {"hi world", "world", 0, 3},
56 {"hi world", "world", 1, 3},
57 {"hi world", "world", 2, 3},
58 {"hi world", "world", 3, 3},
59 {"hi world", "world", 4, -1},
60 {"abbc", "b", -1, 1},
61 {"abbc", "b", 0, 1},
62 {"abbc", "b", 1, 1},
63 {"abbc", "b", 2, 2},
64 {"abbc", "b", 3, -1},
65 {"abbc", "b", 4, -1},
66 // The greek letter beta is the two-byte sequence of "\u03b2".
67 {"a\u03b2\u03b2c", "\u03b2", -1, 1},
68 {"a\u03b2\u03b2c", "\u03b2", 0, 1},
69 {"a\u03b2\u03b2c", "\u03b2", 1, 1},
70 {"a\u03b2\u03b2c", "\u03b2", 3, 3},
71 {"a\u03b2\u03b2c", "\u03b2", 5, -1},
72 {"a\u03b2\u03b2c", "\u03b2", 6, -1},
73 } {
74 actual := indexOf(tc.String, tc.Pattern, tc.Position)
75 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
76 }
77}
78
79func TestLastIndexOf(t *testing.T) {
80 type TestCase struct {

Callers

nothing calls this directly

Calls 1

indexOfFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…