Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / github.com / sergi / go-diff@v1.1.0 / diffmatchpatch / stringutil_test.go
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.
4 //
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/
8
9 package diffmatchpatch
10
11 import (
12         "fmt"
13         "testing"
14
15         "github.com/stretchr/testify/assert"
16 )
17
18 func TestRunesIndexOf(t *testing.T) {
19         type TestCase struct {
20                 Pattern string
21                 Start   int
22
23                 Expected int
24         }
25
26         for i, tc := range []TestCase{
27                 {"abc", 0, 0},
28                 {"cde", 0, 2},
29                 {"e", 0, 4},
30                 {"cdef", 0, -1},
31                 {"abcdef", 0, -1},
32                 {"abc", 2, -1},
33                 {"cde", 2, 2},
34                 {"e", 2, 4},
35                 {"cdef", 2, -1},
36                 {"abcdef", 2, -1},
37                 {"e", 6, -1},
38         } {
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))
41         }
42 }
43
44 func 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
79 func 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 }