File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ func (v *visitor) visit(node ast.Node) reflect.Type {
7171 t = v .BoolNode (n )
7272 case * ast.StringNode :
7373 t = v .StringNode (n )
74+ case * ast.ConstantNode :
75+ t = v .ConstantNode (n )
7476 case * ast.UnaryNode :
7577 t = v .UnaryNode (n )
7678 case * ast.BinaryNode :
@@ -160,6 +162,10 @@ func (v *visitor) StringNode(*ast.StringNode) reflect.Type {
160162 return stringType
161163}
162164
165+ func (v * visitor ) ConstantNode (node * ast.ConstantNode ) reflect.Type {
166+ return reflect .TypeOf (node .Value )
167+ }
168+
163169func (v * visitor ) UnaryNode (node * ast.UnaryNode ) reflect.Type {
164170 t := v .visit (node .Node )
165171
Original file line number Diff line number Diff line change @@ -2,11 +2,14 @@ package checker_test
22
33import (
44 "fmt"
5+ "reflect"
6+ "regexp"
57 "strings"
68 "testing"
79 "time"
810
911 "github.com/antonmedv/expr"
12+ "github.com/antonmedv/expr/ast"
1013 "github.com/antonmedv/expr/checker"
1114 "github.com/antonmedv/expr/conf"
1215 "github.com/antonmedv/expr/parser"
@@ -85,6 +88,19 @@ func TestVisitor_BuiltinNode(t *testing.T) {
8588 }
8689}
8790
91+ func TestVisitor_ConstantNode (t * testing.T ) {
92+ tree , err := parser .Parse (`re("[a-z]")` )
93+
94+ regexValue := regexp .MustCompile ("[a-z]" )
95+ constNode := & ast.ConstantNode {Value : regexValue }
96+ ast .Patch (& tree .Node , constNode )
97+
98+ _ , err = checker .Check (tree , conf .New (& mockEnv {}))
99+ assert .NoError (t , err )
100+
101+ assert .Equal (t , reflect .TypeOf (regexValue ), tree .Node .Type ())
102+ }
103+
88104func TestCheck (t * testing.T ) {
89105 var typeTests = []string {
90106 "!Bool" ,
You can’t perform that action at this time.
0 commit comments