Skip to content

Commit a81f28a

Browse files
committed
gen: simplify search
1 parent dc7c302 commit a81f28a

File tree

2 files changed

+11
-53
lines changed

2 files changed

+11
-53
lines changed

test/gen/env.go

+8-34
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
package main
22

33
var Env = map[string]any{
4-
"ok": true,
5-
"i": 1,
6-
"str": "str",
7-
"f64": .5,
8-
"f32": float32(.5),
9-
"i64": int64(1),
10-
"i32": int32(2),
11-
"u64": uint64(4),
12-
"u32": uint32(5),
13-
"u16": uint16(6),
14-
"u8": uint8(7),
15-
"array": []int{1, 2, 3, 4, 5},
16-
"foo": Foo{"foo"},
17-
"bar": Bar{42, "bar"},
18-
"listOfFoo": []Foo{{"bar"}, {"baz"}},
19-
"add": func(a, b int) int { return a + b },
20-
"div": func(a, b int) int { return a / b },
21-
"half": func(a float64) float64 { return a / 2 },
22-
"sumUp": func(a int, x ...int) int {
23-
s := a
24-
for _, n := range x {
25-
s += n
26-
}
27-
return s
28-
},
4+
"ok": true,
5+
"i": 1,
6+
"str": "str",
7+
"f64": .5,
8+
"array": []int{1, 2, 3, 4, 5},
9+
"foo": Foo{"foo"},
10+
"list": []Foo{{"bar"}, {"baz"}},
11+
"add": func(a, b int) int { return a + b },
2912
"greet": func(name string) string { return "Hello, " + name },
3013
}
3114

@@ -36,12 +19,3 @@ type Foo struct {
3619
func (f Foo) String() string {
3720
return "foo"
3821
}
39-
40-
func (f Foo) Qux(s string) string {
41-
return f.Bar + s
42-
}
43-
44-
type Bar struct {
45-
I int `expr:"i"`
46-
Str string `expr:"str"`
47-
}

test/gen/gen.go

+3-19
Original file line numberDiff line numberDiff line change
@@ -170,38 +170,22 @@ func nilNode(_ int) string {
170170
}
171171

172172
func floatNode(_ int) string {
173-
return oneOf(list[string]{
174-
{"1.0", 1},
175-
{".5", 1},
176-
{"0.0", 1},
177-
{"-1.0", 1},
178-
{"1e+10", 1},
179-
{"1e-10", 1},
180-
})
173+
return "1.0"
181174
}
182175

183176
func integerNode(_ int) string {
184177
return oneOf(list[string]{
185178
{"1", 1},
186-
{"2", 1},
187-
{"-1", 1},
188179
{"0", 1},
189180
})
190181
}
191182

192183
func stringNode(_ int) string {
193-
return oneOf(list[string]{
194-
{"foo", 1},
195-
{"bar", 1},
196-
{"str", 1},
197-
})
184+
return "foo"
198185
}
199186

200187
func booleanNode(_ int) string {
201-
if maybe() {
202-
return "true"
203-
}
204-
return "false"
188+
return random([]string{"true", "false"})
205189
}
206190

207191
func identifierNode(_ int) string {

0 commit comments

Comments
 (0)