]> Sergey Matveev's repositories - path-extractor.git/blob - pe_test.go
2deeae75e91b5c61daf315ccba39ec9106ee0ba6
[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", MatchOptions{})
7         if output[0] != "alt/generateStore.php" {
8                 t.Errorf("Doesnt match files", output)
9         }
10
11         output = GetAllMatches("I have a cat.", MatchOptions{})
12         if len(output) != 0 {
13                 t.Errorf("Matches sentence", output)
14         }
15
16         output = GetAllMatches("'/usr/bin", MatchOptions{})
17         if output[0] != "/usr/bin" {
18                 t.Errorf("Doesn't match statement correctly", output)
19         }
20
21         output = GetAllMatches("/usr_b/bin", MatchOptions{})
22         if output[0] != "/usr_b/bin" {
23                 t.Errorf("Doesn't match statement correctly", output)
24         }
25
26         output = GetAllMatches("\"/usr/bin", MatchOptions{})
27         if output[0] != "/usr/bin" {
28                 t.Errorf("Doesn't match statement correctly", output)
29         }
30
31         output = GetAllMatches("`/usr/bin", MatchOptions{})
32         if output[0] != "/usr/bin" {
33                 t.Errorf("Doesn't match statement correctly", output)
34         }
35
36         output = GetAllMatches("€/usr/bin", MatchOptions{})
37         if output[0] != "/usr/bin" {
38                 t.Errorf("Doesn't match statement correctly", output)
39         }
40
41         output = GetAllMatches("prefix=/usr/bin", MatchOptions{})
42         if len(output) != 1 {
43                 t.Errorf("Should match =/usr/bin", output)
44         }
45         if output[0] != "/usr/bin" {
46                 t.Errorf("Doesn't match statement correctly", output)
47         }
48
49         output = GetAllMatches("/var//log", MatchOptions{})
50         if len(output) != 0 {
51                 t.Errorf("Matches double //", output)
52         }
53
54         output = GetAllMatches("s/+//", MatchOptions{})
55         if len(output) != 0 {
56                 t.Errorf("Doesn't match substitute", output)
57         }
58
59         output = GetAllMatches("s/^//", MatchOptions{})
60         if len(output) != 0 {
61                 t.Errorf("Doesn't match substitute", output)
62         }
63
64         output = GetAllMatches("/usr/bin/env\\", MatchOptions{})
65         if len(output) != 1 {
66                 t.Errorf("Doesn't match escaped", output)
67         }
68         if output[0] != "/usr/bin/env" {
69                 t.Errorf("Doesn't match escaped exactly", output)
70         }
71
72         output = GetAllMatches("!#/usr/bin/env", MatchOptions{})
73         if len(output) != 1 {
74                 t.Errorf("Doesn't match shebang", output)
75         }
76         if output[0] != "/usr/bin/env" {
77                 t.Errorf("Doesn't match shebang exactly", output)
78         }
79
80         output = GetAllMatches("hello .gitignore", MatchOptions{})
81         if output[0] != ".gitignore" {
82                 t.Errorf("Doesnt match hidden files", output)
83         }
84
85         output = GetAllMatches(" this.user ", MatchOptions{})
86         if len(output) != 0 {
87                 t.Errorf("Matches this.user", output)
88         }
89
90         output = GetAllMatches("To https://test@test.org/88/ls.git", MatchOptions{})
91         if len(output) != 0 {
92                 t.Errorf("Matches email adresses", output)
93         }
94
95         output = GetAllMatches(" mail@mail.com ", MatchOptions{})
96         if len(output) != 0 {
97                 t.Errorf("Matches email adresses", output)
98         }
99
100         output = GetAllMatches(" logo@2x.png ", MatchOptions{})
101         if len(output) == 0 {
102                 t.Errorf("Doesn't match retina asset", output)
103         }
104
105         output = GetAllMatches("and/or", MatchOptions{})
106         if len(output) != 0 {
107                 t.Errorf("Matches and/or adresses", output)
108         }
109
110         output = GetAllMatches("v1.2", MatchOptions{})
111         if len(output) != 0 {
112                 t.Errorf("Matches version number", output)
113         }
114
115         output = GetAllMatches("obj.slice()", MatchOptions{})
116         if len(output) != 0 {
117                 t.Errorf("Matches function call", output)
118         }
119
120         output = GetAllMatches("fs.read(arg)", MatchOptions{})
121         if len(output) != 0 {
122                 t.Errorf("Matches function call", output)
123         }
124
125         output = GetAllMatches("~/www", MatchOptions{})
126         if len(output) == 0 || output[0] != "~/www" {
127                 t.Errorf("Doesnt match home", output)
128         }
129
130         output = GetAllMatches("origin/master", MatchOptions{})
131         if len(output) != 0 {
132                 t.Errorf("Matches remote name", output)
133         }
134
135         output = GetAllMatches("john doe (dead on 28/04/2014)", MatchOptions{})
136         if len(output) != 0 {
137                 t.Errorf("Matches date", output)
138         }
139
140         output = GetAllMatches("john doe ,dead on 28/04/2014", MatchOptions{})
141         if len(output) != 0 {
142                 t.Errorf("Matches date", output)
143         }
144
145         output = GetAllMatches(".gitignore , ~/www", MatchOptions{})
146         if len(output) != 2 {
147                 t.Errorf("Doesnt match multi", output)
148         }
149
150         output = GetAllMatches("user.test.js", MatchOptions{})
151         if len(output) != 1 {
152                 t.Errorf("Doesnt match multiple extensions", output)
153         }
154
155         output = GetAllMatches("(user.js)", MatchOptions{})
156         if len(output) != 1 {
157                 t.Errorf("Doesnt match surrounded by parens", output)
158         }
159         if output[0] != "user.js" {
160                 t.Errorf("matches surrounded by parens badly", output)
161         }
162
163         output = GetAllMatches("var/", MatchOptions{})
164         if len(output) != 1 {
165                 t.Errorf("Doesnt match dir", output)
166         }
167
168         output = GetAllMatches("//", MatchOptions{})
169         if len(output) != 0 {
170                 t.Errorf("Comment matches", output)
171         }
172
173         output = GetAllMatches("test.js:45", MatchOptions{format: "ackmate"})
174         if len(output) != 1 {
175                 t.Errorf("Ackmate doesnt match", output)
176         }
177         if output[0] == "test.js" {
178                 t.Errorf("Ackmate should not forget number", output)
179         }
180         if output[0] != "test.js:45" {
181                 t.Errorf("Ackmate should output right line number", output)
182         }
183 }