]> Sergey Matveev's repositories - path-extractor.git/blob - pe_test.go
bc07d279b695c12fb8f8c33e1cd2cc7f6efde3be
[path-extractor.git] / pe_test.go
1 package pathextractor
2
3 import "testing"
4
5 func TestEverything(t *testing.T) {
6         output := GetAllMatches("?? alt/generateStore.php", "")
7         if output[0] != "alt/generateStore.php" {
8                 t.Errorf("Doesnt match files", output)
9         }
10
11         output = GetAllMatches("2.0G", "")
12         if len(output) != 0 {
13                 t.Errorf("File size matches", output)
14         }
15
16         output = GetAllMatches("4.0K", "")
17         if len(output) != 0 {
18                 t.Errorf("File size matches", output)
19         }
20
21         output = GetAllMatches("72K", "")
22         if len(output) != 0 {
23                 t.Errorf("File size matches", output)
24         }
25
26         output = GetAllMatches("remotes/origin/master", "")
27         if len(output) != 0 {
28                 t.Errorf("Git branch matches", output)
29         }
30
31         output = GetAllMatches("I have a cat.", "")
32         if len(output) != 0 {
33                 t.Errorf("Matches sentence", output)
34         }
35
36         output = GetAllMatches("'/usr/bin", "")
37         if output[0] != "/usr/bin" {
38                 t.Errorf("Doesn't match statement correctly", output)
39         }
40
41         output = GetAllMatches("/usr_b/bin", "")
42         if output[0] != "/usr_b/bin" {
43                 t.Errorf("Doesn't match statement correctly", output)
44         }
45
46         output = GetAllMatches("\"/usr/bin", "")
47         if output[0] != "/usr/bin" {
48                 t.Errorf("Doesn't match statement correctly", output)
49         }
50
51         output = GetAllMatches("`/usr/bin", "")
52         if output[0] != "/usr/bin" {
53                 t.Errorf("Doesn't match statement correctly", output)
54         }
55
56         output = GetAllMatches("€/usr/bin", "")
57         if output[0] != "/usr/bin" {
58                 t.Errorf("Doesn't match statement correctly", output)
59         }
60
61         output = GetAllMatches("prefix=/usr/bin", "")
62         if len(output) != 1 {
63                 t.Errorf("Should match =/usr/bin", output)
64         }
65         if output[0] != "/usr/bin" {
66                 t.Errorf("Doesn't match statement correctly", output)
67         }
68
69         output = GetAllMatches("/var//log", "")
70         if len(output) != 0 {
71                 t.Errorf("Matches double //", output)
72         }
73
74         output = GetAllMatches("s/+//", "")
75         if len(output) != 0 {
76                 t.Errorf("Doesn't match substitute", output)
77         }
78
79         output = GetAllMatches("s/^//", "")
80         if len(output) != 0 {
81                 t.Errorf("Doesn't match substitute", output)
82         }
83
84         output = GetAllMatches("/usr/bin/env\\", "")
85         if len(output) != 1 {
86                 t.Errorf("Doesn't match escaped", output)
87         }
88         if output[0] != "/usr/bin/env" {
89                 t.Errorf("Doesn't match escaped exactly", output)
90         }
91
92         output = GetAllMatches("!#/usr/bin/env", "")
93         if len(output) != 1 {
94                 t.Errorf("Doesn't match shebang", output)
95         }
96         if output[0] != "/usr/bin/env" {
97                 t.Errorf("Doesn't match shebang exactly", output)
98         }
99
100         output = GetAllMatches("hello .gitignore", "")
101         if output[0] != ".gitignore" {
102                 t.Errorf("Doesnt match hidden files", output)
103         }
104
105         output = GetAllMatches(" this.user ", "")
106         if len(output) != 0 {
107                 t.Errorf("Matches this.user", output)
108         }
109
110         output = GetAllMatches("To https://test@test.org/88/ls.git", "")
111         if len(output) != 0 {
112                 t.Errorf("Matches email adresses", output)
113         }
114
115         output = GetAllMatches(" mail@mail.com ", "")
116         if len(output) != 0 {
117                 t.Errorf("Matches email adresses", output)
118         }
119
120         output = GetAllMatches(" logo@2x.png ", "")
121         if len(output) == 0 {
122                 t.Errorf("Doesn't match retina asset", output)
123         }
124
125         output = GetAllMatches("and/or", "")
126         if len(output) != 0 {
127                 t.Errorf("Matches and/or adresses", output)
128         }
129
130         output = GetAllMatches("v1.2", "")
131         if len(output) != 0 {
132                 t.Errorf("Matches version number", output)
133         }
134
135         output = GetAllMatches("14.22.2", "")
136         if len(output) != 0 {
137                 t.Errorf("Matches version number", output)
138         }
139
140         output = GetAllMatches("~/v1.2/js", "")
141         if len(output) != 1 {
142                 t.Errorf("Should match path with version inside", output)
143         }
144
145         output = GetAllMatches("obj.slice()", "")
146         if len(output) != 0 {
147                 t.Errorf("Matches function call", output)
148         }
149
150         output = GetAllMatches("fs.read(arg)", "")
151         if len(output) != 0 {
152                 t.Errorf("Matches function call", output)
153         }
154
155         output = GetAllMatches("~/www", "")
156         if len(output) == 0 || output[0] != "~/www" {
157                 t.Errorf("Doesnt match home", output)
158         }
159
160         output = GetAllMatches("origin/master", "")
161         if len(output) != 0 {
162                 t.Errorf("Matches remote name", output)
163         }
164
165         output = GetAllMatches("john doe (dead on 28/04/2014)", "")
166         if len(output) != 0 {
167                 t.Errorf("Matches date", output)
168         }
169
170         output = GetAllMatches("john doe ,dead on 28/04/2014", "")
171         if len(output) != 0 {
172                 t.Errorf("Matches date", output)
173         }
174
175         output = GetAllMatches(".gitignore , ~/www", "")
176         if len(output) != 2 {
177                 t.Errorf("Doesnt match multi", output)
178         }
179
180         output = GetAllMatches("user.test.js", "")
181         if len(output) != 1 {
182                 t.Errorf("Doesnt match multiple extensions", output)
183         }
184
185         output = GetAllMatches("[Error/foobar]", "")
186         if len(output) == 1 {
187                 t.Errorf("Matches error", output)
188         }
189
190         output = GetAllMatches("[Object.foo]", "")
191         if len(output) == 1 {
192                 t.Errorf("Matches Object.foo", output)
193         }
194
195         output = GetAllMatches("(user.js)", "")
196         if len(output) != 1 {
197                 t.Errorf("Doesnt match surrounded by parens", output)
198         }
199         if output[0] != "user.js" {
200                 t.Errorf("matches surrounded by parens badly", output)
201         }
202
203         output = GetAllMatches("var/", "")
204         if len(output) != 1 {
205                 t.Errorf("Doesnt match dir", output)
206         }
207
208         output = GetAllMatches("//", "")
209         if len(output) != 0 {
210                 t.Errorf("Comment matches", output)
211         }
212
213         output = GetAllMatches("test.js:45", "ackmate")
214         if len(output) != 1 {
215                 t.Errorf("Ackmate doesnt match", output)
216         }
217
218         if output[0] == "test.js" {
219                 t.Errorf("Ackmate should not forget number", output)
220         }
221         if output[0] != "test.js:45" {
222                 t.Errorf("Ackmate should output right line number", output)
223         }
224
225         output = GetAllMatches("test.js:45:12", "ackmate")
226         if len(output) != 1 {
227                 t.Errorf("Ackmate doesnt match", output)
228         }
229
230         if output[0] == "test.js" {
231                 t.Errorf("Ackmate should not forget number", output)
232         }
233         if output[0] != "test.js:45:12" {
234                 t.Errorf("Ackmate should output right line number", output)
235         }
236
237         output = GetAllMatches("test.js:45:12 foo bar", "ackmate")
238         if len(output) != 1 {
239                 t.Errorf("Ackmate doesnt match", output)
240         }
241
242         if output[0] == "test.js" {
243                 t.Errorf("Ackmate should not forget number", output)
244         }
245         if output[0] != "test.js:45:12" {
246                 t.Errorf("Ackmate should output right line number", output)
247         }
248 }