@@ -2,23 +2,24 @@ package expr_test
22
33import (
44 "regexp"
5- "strings"
65 "testing"
76
87 "github.com/antonmedv/expr"
98)
109
1110func FuzzExpr (f * testing.F ) {
1211 env := map [string ]interface {}{
13- "i" : 1 ,
14- "j" : 2 ,
15- "a" : []int {1 , 2 , 3 },
16- "m" : map [string ]interface {}{"a" : 1 , "b" : 2 , "m" : map [string ]int {"a" : 1 }},
17- "s" : "abc" ,
12+ "i" : 1 ,
13+ "j" : 2 ,
14+ "b" : true ,
15+ "a" : []int {1 , 2 , 3 },
16+ "m" : map [string ]interface {}{"a" : 1 , "b" : 2 , "m" : map [string ]int {"a" : 1 }},
17+ "s" : "abc" ,
18+ "add" : func (a , b int ) int { return a + b },
1819 }
1920
20- fn := expr .Function (
21- "fn " ,
21+ head := expr .Function (
22+ "head " ,
2223 func (params ... interface {}) (interface {}, error ) {
2324 return params [0 ], nil
2425 },
@@ -85,9 +86,17 @@ func FuzzExpr(f *testing.F) {
8586 `s matches "a"` ,
8687 `s matches "a+"` ,
8788 `true ? 1 : 2` ,
88- `fn(1)` ,
89+ `false ? 1 : 2` ,
90+ `b ?? true` ,
91+ `head(1)` ,
8992 `{a: 1, b: 2}` ,
9093 `[1, 2, 3]` ,
94+ `type(1)` ,
95+ `type("a")` ,
96+ `type([1, 2, 3])` ,
97+ `type({a: 1, b: 2})` ,
98+ `type(head)` ,
99+ `keys(m)` ,
91100 }
92101
93102 for _ , s := range corpus {
@@ -122,19 +131,8 @@ func FuzzExpr(f *testing.F) {
122131 regexp .MustCompile (`operator "in" not defined on int` ),
123132 }
124133
125- skipCode := []string {
126- `??` ,
127- }
128-
129134 f .Fuzz (func (t * testing.T , code string ) {
130- for _ , skipCase := range skipCode {
131- if strings .Contains (code , skipCase ) {
132- t .Skipf ("skip code: %s" , skipCase )
133- return
134- }
135- }
136-
137- program , err := expr .Compile (code , expr .Env (env ), fn , expr .ExperimentalPipes ())
135+ program , err := expr .Compile (code , expr .Env (env ), head , expr .ExperimentalPipes ())
138136 if err != nil {
139137 t .Skipf ("compile error: %s" , err )
140138 }
0 commit comments