Skip to content

Commit 6a984f4

Browse files
committed
Add helpers tests
1 parent 4c7e9b9 commit 6a984f4

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

checker/checker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ func Check(tree *parser.Tree, config *conf.Config) (t reflect.Type, err error) {
3030
}
3131

3232
t = v.visit(tree.Node)
33-
patchOperators(tree, config)
33+
34+
// TODO: Move patch into visitor.
35+
if v.operators != nil {
36+
patchOperators(tree, config)
37+
}
3438

3539
if v.expect != reflect.Invalid {
3640
switch v.expect {

vm/vm_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,60 @@ func TestRun(t *testing.T) {
308308
}
309309
}
310310

311+
func TestRun_helpers(t *testing.T) {
312+
values := []interface{}{
313+
uint(1),
314+
uint8(1),
315+
uint16(1),
316+
uint32(1),
317+
uint64(1),
318+
int(1),
319+
int8(1),
320+
int16(1),
321+
int32(1),
322+
int64(1),
323+
float32(1),
324+
float64(1),
325+
}
326+
ops := []string{"+", "-", "*", "/", "%", "==", ">=", "<=", "<", ">"}
327+
328+
for _, a := range values {
329+
for _, b := range values {
330+
for _, op := range ops {
331+
332+
if op == "%" {
333+
switch a.(type) {
334+
case float32, float64:
335+
continue
336+
}
337+
switch b.(type) {
338+
case float32, float64:
339+
continue
340+
}
341+
}
342+
343+
input := fmt.Sprintf("a %v b", op)
344+
env := map[string]interface{}{
345+
"a": a,
346+
"b": b,
347+
}
348+
349+
tree, err := parser.Parse(input)
350+
require.NoError(t, err)
351+
352+
_, err = checker.Check(tree, nil)
353+
require.NoError(t, err)
354+
355+
program, err := compiler.Compile(tree, nil)
356+
require.NoError(t, err)
357+
358+
_, err = vm.Run(program, env)
359+
require.NoError(t, err)
360+
}
361+
}
362+
}
363+
}
364+
311365
type mockEnv struct {
312366
Any interface{}
313367
Int int

0 commit comments

Comments
 (0)