44 "errors"
55 "fmt"
66 "go/token"
7+ "regexp"
78 "strings"
89 "testing"
910)
@@ -189,57 +190,57 @@ func TestParseRuleError(t *testing.T) {
189190 }{
190191 {
191192 `m.Match("$x").Where(m["x"].Object.Is("abc")).Report("")` ,
192- `abc is not a valid go/types object name` ,
193+ `\Qabc is not a valid go/types object name` ,
193194 },
194195
195196 {
196197 `m.Match("$x").MatchComment("").Report("")` ,
197- `Match () and MatchComment() can't be combined` ,
198+ `\QMatch () and MatchComment() can't be combined` ,
198199 },
199200
200201 {
201202 `m.MatchComment("").Match("$x").Report("")` ,
202- `Match () and MatchComment() can't be combined` ,
203+ `\QMatch () and MatchComment() can't be combined` ,
203204 },
204205
205206 {
206207 `m.Where(m.File().Imports("strings")).Report("no match call")` ,
207- `missing Match() or MatchComment() call` ,
208+ `\Qmissing Match() or MatchComment() call` ,
208209 },
209210
210211 {
211212 `m.Match("$x").Where(m["x"].Pure)` ,
212- `missing Report() or Suggest() call` ,
213+ `\Qmissing Report() or Suggest() call` ,
213214 },
214215
215216 {
216217 `m.Match("$x").Match("$x")` ,
217- `Match () can't be repeated` ,
218+ `\QMatch () can't be repeated` ,
218219 },
219220
220221 {
221222 `m.MatchComment("").MatchComment("")` ,
222- `MatchComment () can't be repeated` ,
223+ `\QMatchComment () can't be repeated` ,
223224 },
224225
225226 {
226227 `m.Match().Report("$$")` ,
227- `too few arguments in call to m.Match` ,
228+ `(?: too few|not enough) arguments in call to m\ .Match` ,
228229 },
229230
230231 {
231232 `m.MatchComment().Report("$$")` ,
232- `too few arguments in call to m.MatchComment` ,
233+ `(?: too few|not enough) arguments in call to m\ .MatchComment` ,
233234 },
234235
235236 {
236237 `m.MatchComment("(").Report("")` ,
237- `error parsing regexp: missing closing )` ,
238+ `\Qerror parsing regexp: missing closing )` ,
238239 },
239240
240241 {
241242 `m.Match("func[]").Report("$$")` ,
242- `parse match pattern: cannot parse expr: 1:5: expected '(', found '['` ,
243+ `\Qparse match pattern: cannot parse expr: 1:5: expected '(', found '['` ,
243244 },
244245 }
245246
@@ -261,9 +262,9 @@ func TestParseRuleError(t *testing.T) {
261262 continue
262263 }
263264 have := err .Error ()
264- want := test .err
265- if ! strings . Contains (have , want ) {
266- t .Errorf ("parse %s: errors mismatch:\n have: %s\n want: %s" , test .expr , have , want )
265+ wantRE := regexp . MustCompile ( test .err )
266+ if ! wantRE . MatchString (have ) {
267+ t .Errorf ("parse %s: errors mismatch:\n have: %s\n want: %s" , test .expr , have , test . err )
267268 continue
268269 }
269270 }
0 commit comments