1 // Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
2 // https://github.com/sergi/go-diff
3 // See the included LICENSE file for license details.
5 // go-diff is a Go implementation of Google's Diff, Match, and Patch library
6 // Original library is Copyright (c) 2006 Google Inc.
7 // http://code.google.com/p/google-diff-match-patch/
15 "github.com/stretchr/testify/assert"
18 func TestRunesIndexOf(t *testing.T) {
19 type TestCase struct {
26 for i, tc := range []TestCase{
39 actual := runesIndexOf([]rune("abcde"), []rune(tc.Pattern), tc.Start)
40 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
44 func TestIndexOf(t *testing.T) {
45 type TestCase struct {
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},
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},
74 actual := indexOf(tc.String, tc.Pattern, tc.Position)
75 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
79 func TestLastIndexOf(t *testing.T) {
80 type TestCase struct {
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},
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},
113 actual := lastIndexOf(tc.String, tc.Pattern, tc.Position)
114 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))