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

Function TestLastIndexOf

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

Source from the content-addressed store, hash-verified

77}
78
79func TestLastIndexOf(t *testing.T) {
80 type TestCase struct {
81 String string
82 Pattern string
83 Position int
84
85 Expected int
86 }
87
88 for i, tc := range []TestCase{
89 {"hi world", "world", -1, -1},
90 {"hi world", "world", 0, -1},
91 {"hi world", "world", 1, -1},
92 {"hi world", "world", 2, -1},
93 {"hi world", "world", 3, -1},
94 {"hi world", "world", 4, -1},
95 {"hi world", "world", 5, -1},
96 {"hi world", "world", 6, -1},
97 {"hi world", "world", 7, 3},
98 {"hi world", "world", 8, 3},
99 {"abbc", "b", -1, -1},
100 {"abbc", "b", 0, -1},
101 {"abbc", "b", 1, 1},
102 {"abbc", "b", 2, 2},
103 {"abbc", "b", 3, 2},
104 {"abbc", "b", 4, 2},
105 // The greek letter beta is the two-byte sequence of "\u03b2".
106 {"a\u03b2\u03b2c", "\u03b2", -1, -1},
107 {"a\u03b2\u03b2c", "\u03b2", 0, -1},
108 {"a\u03b2\u03b2c", "\u03b2", 1, 1},
109 {"a\u03b2\u03b2c", "\u03b2", 3, 3},
110 {"a\u03b2\u03b2c", "\u03b2", 5, 3},
111 {"a\u03b2\u03b2c", "\u03b2", 6, 3},
112 } {
113 actual := lastIndexOf(tc.String, tc.Pattern, tc.Position)
114 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
115 }
116}
117
118// Exhaustive check for all ints from 0 to 1112060 for correctness of implementation
119// of `intToRune() -> runeToInt()`.

Callers

nothing calls this directly

Calls 1

lastIndexOfFunction · 0.85

Tested by

no test coverage detected