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 {
71
71
t = v .BoolNode (n )
72
72
case * ast.StringNode :
73
73
t = v .StringNode (n )
74
+ case * ast.ConstantNode :
75
+ t = v .ConstantNode (n )
74
76
case * ast.UnaryNode :
75
77
t = v .UnaryNode (n )
76
78
case * ast.BinaryNode :
@@ -160,6 +162,10 @@ func (v *visitor) StringNode(*ast.StringNode) reflect.Type {
160
162
return stringType
161
163
}
162
164
165
+ func (v * visitor ) ConstantNode (node * ast.ConstantNode ) reflect.Type {
166
+ return reflect .TypeOf (node .Value )
167
+ }
168
+
163
169
func (v * visitor ) UnaryNode (node * ast.UnaryNode ) reflect.Type {
164
170
t := v .visit (node .Node )
165
171
Original file line number Diff line number Diff line change @@ -2,11 +2,14 @@ package checker_test
2
2
3
3
import (
4
4
"fmt"
5
+ "reflect"
6
+ "regexp"
5
7
"strings"
6
8
"testing"
7
9
"time"
8
10
9
11
"github.com/antonmedv/expr"
12
+ "github.com/antonmedv/expr/ast"
10
13
"github.com/antonmedv/expr/checker"
11
14
"github.com/antonmedv/expr/conf"
12
15
"github.com/antonmedv/expr/parser"
@@ -85,6 +88,19 @@ func TestVisitor_BuiltinNode(t *testing.T) {
85
88
}
86
89
}
87
90
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
+
88
104
func TestCheck (t * testing.T ) {
89
105
var typeTests = []string {
90
106
"!Bool" ,
You can’t perform that action at this time.
0 commit comments