Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / simple / testdata / src / trim / trim.go
1 package pkg
2
3 import (
4         "bytes"
5         "strings"
6 )
7
8 func foo(s string) int { return 0 }
9 func gen() string {
10         return ""
11 }
12
13 func fn() {
14         const s1 = "a string value"
15         var s2 = "a string value"
16         const n = 14
17
18         var id1 = "a string value"
19         var id2 string
20         if strings.HasPrefix(id1, s1) { // want `should replace.*with.*strings\.TrimPrefix`
21                 id1 = id1[len(s1):]
22         }
23
24         if strings.HasPrefix(id1, s1) { // want `should replace.*with.*strings\.TrimPrefix`
25                 id1 = strings.TrimPrefix(id1, s1)
26         }
27
28         if strings.HasPrefix(id1, s1) {
29                 id1 = strings.TrimPrefix(id1, s2)
30         }
31
32         if strings.Contains(id1, s1) { // want `should replace.*with.*strings\.Replace`
33                 id1 = strings.Replace(id1, s1, "something", 123)
34         }
35
36         if strings.HasSuffix(id1, s2) { // want `should replace.*with.*strings\.TrimSuffix`
37                 id1 = id1[:len(id1)-len(s2)]
38         }
39
40         var x, y []string
41         var i int
42         if strings.HasPrefix(x[i], s1) { // want `should replace.*with.*strings\.TrimPrefix`
43                 x[i] = x[i][len(s1):]
44         }
45
46         if strings.HasPrefix(x[i], y[i]) { // want `should replace.*with.*strings\.TrimPrefix`
47                 x[i] = x[i][len(y[i]):]
48         }
49
50         var t struct{ x string }
51         if strings.HasPrefix(t.x, s1) { // want `should replace.*with.*strings\.TrimPrefix`
52                 t.x = t.x[len(s1):]
53         }
54
55         if strings.HasPrefix(id1, "test") { // want `should replace.*with.*strings\.TrimPrefix`
56                 id1 = id1[len("test"):]
57         }
58
59         if strings.HasPrefix(id1, "test") { // want `should replace.*with.*strings\.TrimPrefix`
60                 id1 = id1[4:]
61         }
62
63         if strings.HasPrefix(id1, s1) { // want `should replace.*with.*strings\.TrimPrefix`
64                 id1 = id1[14:]
65         }
66
67         if strings.HasPrefix(id1, s1) { // want `should replace.*with.*strings\.TrimPrefix`
68                 id1 = id1[n:]
69         }
70
71         var b1, b2 []byte
72         if bytes.HasPrefix(b1, b2) { // want `should replace.*with.*bytes\.TrimPrefix`
73                 b1 = b1[len(b2):]
74         }
75
76         id3 := s2
77         if strings.HasPrefix(id1, id3) { // want `should replace.*with.*strings\.TrimPrefix`
78                 id1 = id1[len(id3):]
79         }
80
81         if strings.HasSuffix(id1, s2) {
82                 id1 = id1[:len(id1)+len(s2)] // wrong operator
83         }
84
85         if strings.HasSuffix(id1, s2) {
86                 id1 = id1[:len(s2)-len(id1)] // wrong math
87         }
88
89         if strings.HasSuffix(id1, s2) {
90                 id1 = id1[:len(id1)-len(id1)] // wrong string length
91         }
92
93         if strings.HasPrefix(id1, gen()) {
94                 id1 = id1[len(gen()):] // dynamic id3
95         }
96
97         if strings.HasPrefix(id1, s1) {
98                 id1 = id1[foo(s1):] // wrong function
99         }
100
101         if strings.HasPrefix(id1, s1) {
102                 id1 = id1[len(id1):] // len() on wrong value
103         }
104
105         if strings.HasPrefix(id1, "test") {
106                 id1 = id1[5:] // wrong length
107         }
108
109         if strings.HasPrefix(id1, s1) {
110                 id1 = id1[len(s1)+1:] // wrong length due to math
111         }
112
113         if strings.HasPrefix(id1, s1) {
114                 id2 = id1[len(s1):] // assigning to the wrong variable
115         }
116
117         if strings.HasPrefix(id1, s1) {
118                 id1 = id1[len(s1):15] // has a max
119         }
120
121         if strings.HasPrefix(id1, s1) {
122                 id1 = id2[len(s1):] // assigning the wrong value
123         }
124
125         if strings.HasPrefix(id1, s1) {
126                 id1 = id1[len(s1):]
127                 id1 += "" // doing more work in the if
128         }
129
130         if strings.HasPrefix(id1, s1) {
131                 id1 = id1[len(s1):]
132         } else {
133                 id1 = "game over" // else branch
134         }
135
136         if strings.HasPrefix(id1, s1) {
137                 // the conditional is guarding additional code
138                 id1 = id1[len(s1):]
139                 println(id1)
140         }
141 }