Skip to content

Commit 437bc8e

Browse files
committed
Refactor random code get
1 parent e135bda commit 437bc8e

File tree

4 files changed

+195
-190
lines changed

4 files changed

+195
-190
lines changed

test/gen/env.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
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+
},
29+
"greet": func(name string) string { return "Hello, " + name },
30+
}
31+
32+
type Foo struct {
33+
Bar string
34+
}
35+
36+
func (f Foo) String() string {
37+
return "foo"
38+
}
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+
}

0 commit comments

Comments
 (0)