t_helpers_test.go: enhanced tests for the helpers module
This commit is contained in:
+43
-39
@@ -5,51 +5,55 @@
|
|||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO The new function param model does not allow this kind of test
|
func subtract(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
// ------------------------------------------------------------------
|
if len(args) != 2 {
|
||||||
// func subtract(ctx ExprContext, name string, args map[string]any) (result any, err error) {
|
err = fmt.Errorf("%s(): requires exactly two arguments", name)
|
||||||
// if len(args) != 2 {
|
return
|
||||||
// err = fmt.Errorf("%s(): requires exactly two arguments", name)
|
}
|
||||||
// return
|
x, xok := args["a"].(int64)
|
||||||
// }
|
y, yok := args["b"].(int64)
|
||||||
// x, xok := args[0].(int64)
|
if xok && yok {
|
||||||
// y, yok := args[1].(int64)
|
result = x - y
|
||||||
// if xok && yok {
|
} else {
|
||||||
// result = x - y
|
err = fmt.Errorf("expected integer (int64) arguments, got %T and %T values", x, y)
|
||||||
// } else {
|
}
|
||||||
// err = fmt.Errorf("expected integer (int64) arguments, got %T and %T values", x, y)
|
return
|
||||||
// }
|
}
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestEvalStringA(t *testing.T) {
|
func TestEvalStringA(t *testing.T) {
|
||||||
|
|
||||||
// source := `a + b * subtract(4,2)`
|
source := `a + b * subtract(4,2)`
|
||||||
// args := []Arg{
|
args := []Arg{
|
||||||
// {"a", uint8(1)},
|
{"a", uint8(1)},
|
||||||
// {"b", int8(2)},
|
{"b", int8(2)},
|
||||||
// {"subtract", FuncTemplate2(subtract)},
|
{"subtract", kern.FuncTemplate(subtract)},
|
||||||
// // force coverage
|
// force coverage
|
||||||
// {"a16", uint16(1)},
|
{"a16", uint16(1)},
|
||||||
// {"b16", int16(2)},
|
{"b16", int16(2)},
|
||||||
// {"a32", uint32(1)},
|
{"a32", uint32(1)},
|
||||||
// {"b32", int32(2)},
|
{"b32", int32(2)},
|
||||||
// {"a64", uint64(1)},
|
{"a64", uint64(1)},
|
||||||
// {"b64", int64(2)},
|
{"b64", int64(2)},
|
||||||
// {"f32", float32(1.0)},
|
{"f32", float32(1.0)},
|
||||||
// {"f64", float64(1.0)},
|
{"f64", float64(1.0)},
|
||||||
// }
|
{"string", "text"},
|
||||||
|
{"bool", true},
|
||||||
|
}
|
||||||
|
|
||||||
// wantResult := int64(5)
|
wantResult := int64(5)
|
||||||
// gotResult, gotErr := EvalStringA(source, args...)
|
gotResult, gotErr := EvalStringA(source, args...)
|
||||||
// if value, ok := gotResult.(int64); ok && value != wantResult {
|
if value, ok := gotResult.(int64); ok && value != wantResult {
|
||||||
// t.Errorf("Source %q got %v, want %v", source, gotResult, wantResult)
|
t.Errorf("Source %q got %v, want %v", source, gotResult, wantResult)
|
||||||
// t.Errorf("Error: %v", gotErr)
|
t.Errorf("Error: %v", gotErr)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
func TestEvalString(t *testing.T) {
|
func TestEvalString(t *testing.T) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user