@@ -133,6 +133,14 @@ var parseTests = []parseTest{
133133 "len(foo)" ,
134134 builtinNode {"len" , []Node {nameNode {"foo" }}},
135135 },
136+ {
137+ `foo matches "foo"` ,
138+ matchesNode {left : nameNode {"foo" }, right : textNode {"foo" }},
139+ },
140+ {
141+ `foo matches regex` ,
142+ matchesNode {left : nameNode {"foo" }, right : nameNode {"regex" }},
143+ },
136144}
137145
138146type parseErrorTest struct {
@@ -178,6 +186,10 @@ func TestParse(t *testing.T) {
178186 t .Errorf ("%s:\n %v" , test .input , err )
179187 continue
180188 }
189+ if m , ok := actual .(matchesNode ); ok {
190+ m .r = nil
191+ actual = m
192+ }
181193 if ! reflect .DeepEqual (actual , test .expected ) {
182194 t .Errorf ("%s:\n got\n \t %#v\n expected\n \t %#v" , test .input , actual , test .expected )
183195 }
@@ -195,43 +207,3 @@ func TestParse_error(t *testing.T) {
195207 }
196208 }
197209}
198-
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 )
232- }
233-
234- if m .r != nil {
235- t .Fatal ("regexp should not be compiled" )
236- }
237- }
0 commit comments