@@ -2,23 +2,24 @@ package expr_test
2
2
3
3
import (
4
4
"regexp"
5
- "strings"
6
5
"testing"
7
6
8
7
"github.com/antonmedv/expr"
9
8
)
10
9
11
10
func FuzzExpr (f * testing.F ) {
12
11
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 },
18
19
}
19
20
20
- fn := expr .Function (
21
- "fn " ,
21
+ head := expr .Function (
22
+ "head " ,
22
23
func (params ... interface {}) (interface {}, error ) {
23
24
return params [0 ], nil
24
25
},
@@ -85,9 +86,17 @@ func FuzzExpr(f *testing.F) {
85
86
`s matches "a"` ,
86
87
`s matches "a+"` ,
87
88
`true ? 1 : 2` ,
88
- `fn(1)` ,
89
+ `false ? 1 : 2` ,
90
+ `b ?? true` ,
91
+ `head(1)` ,
89
92
`{a: 1, b: 2}` ,
90
93
`[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)` ,
91
100
}
92
101
93
102
for _ , s := range corpus {
@@ -122,19 +131,8 @@ func FuzzExpr(f *testing.F) {
122
131
regexp .MustCompile (`operator "in" not defined on int` ),
123
132
}
124
133
125
- skipCode := []string {
126
- `??` ,
127
- }
128
-
129
134
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 ())
138
136
if err != nil {
139
137
t .Skipf ("compile error: %s" , err )
140
138
}
0 commit comments