@@ -101,10 +101,6 @@ var parseTests = []parseTest{
101
101
"a ?: b" ,
102
102
conditionalNode {nameNode {"a" }, nameNode {"a" }, nameNode {"b" }},
103
103
},
104
- {
105
- `"foo" matches "/foo/"` ,
106
- binaryNode {"matches" , textNode {"foo" }, textNode {"/foo/" }},
107
- },
108
104
{
109
105
"foo.bar().foo().baz[33]" ,
110
106
propertyNode {propertyNode {methodNode {methodNode {nameNode {"foo" }, identifierNode {"bar" }, []Node {}}, identifierNode {"foo" }, []Node {}}, identifierNode {"baz" }}, numberNode {33 }},
@@ -169,6 +165,10 @@ var parseErrorTests = []parseErrorTest{
169
165
"{-}" ,
170
166
"a map key must be a" ,
171
167
},
168
+ {
169
+ "a matches 'a)(b'" ,
170
+ "error parsing regexp: unexpected )" ,
171
+ },
172
172
}
173
173
174
174
func TestParse (t * testing.T ) {
@@ -196,14 +196,42 @@ func TestParseError(t *testing.T) {
196
196
}
197
197
}
198
198
199
- func TestParseErrorPosition (t * testing.T ) {
200
- _ , err := Parse ("foo() + bar(**)" )
201
- if err == nil {
202
- err = fmt .Errorf ("<nil>" )
199
+ func TestParse_matches (t * testing.T ) {
200
+ node , err := Parse (`foo matches "foo"` )
201
+ if err != nil {
202
+ t .Fatal (err )
203
+ }
204
+
205
+ m , ok := node .(matchesNode )
206
+ if ! ok {
207
+ t .Fatalf ("expected to me matchesNode, got %T" , node )
208
+ }
209
+
210
+ if ! reflect .DeepEqual (m .left , nameNode {"foo" }) || ! reflect .DeepEqual (m .right , textNode {"foo" }) {
211
+ t .Fatalf ("left or right side of matches operator invalid: %#v" , m )
212
+ }
213
+
214
+ if m .r == nil {
215
+ t .Fatal ("regexp should be compiled" )
216
+ }
217
+ }
218
+
219
+ func TestParse_matches_dynamic (t * testing.T ) {
220
+ node , err := Parse (`foo matches regex` )
221
+ if err != nil {
222
+ t .Fatal (err )
223
+ }
224
+
225
+ m , ok := node .(matchesNode )
226
+ if ! ok {
227
+ t .Fatalf ("expected to me matchesNode, got %T" , node )
228
+ }
229
+
230
+ if ! reflect .DeepEqual (m .left , nameNode {"foo" }) || ! reflect .DeepEqual (m .right , nameNode {"regex" }) {
231
+ t .Fatalf ("left or right side of matches operator invalid: %#v" , m )
203
232
}
204
233
205
- expected := "unexpected token operator(**)\n foo() + bar(**)\n ------------^"
206
- if err .Error () != expected {
207
- t .Errorf ("\n got\n \t %+v\n expected\n \t %v" , err .Error (), expected )
234
+ if m .r != nil {
235
+ t .Fatal ("regexp should not be compiled" )
208
236
}
209
237
}
0 commit comments