diff --git a/lambda_test.go b/lambda_test.go new file mode 100644 index 0000000..c1a4b20 --- /dev/null +++ b/lambda_test.go @@ -0,0 +1,43 @@ +package vfilter + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +type lambdaTest struct { + name, clause string + result Any + input Any +} + +var lambdaTestCases = []lambdaTest{ + { + name: "Simple Lambda", + clause: "x=>1+1", + input: 1, + result: 2, + }, + { + name: "Complex Lambda", + clause: "x=> 1 + 0x0aB", + input: 1, + result: 172, + }, +} + +func TestLambda(t *testing.T) { + scope := makeScope() + for _, test := range lambdaTestCases { + lambda, err := ParseLambda(test.clause) + assert.NoError(t, err) + + res := lambda.Reduce( + context.Background(), scope, []Any{test.input}) + if !scope.Eq(test.result, res) { + t.Fatalf("%v: %v != %v", test.name, test.result, res) + } + } +} diff --git a/vfilter.go b/vfilter.go index 1636f9f..29dbbdb 100644 --- a/vfilter.go +++ b/vfilter.go @@ -169,7 +169,7 @@ var ( {Name: "ORDERBY", Pattern: `(?i)\bORDER\s+BY\b`}, {Name: "BOOL", Pattern: `(?i)\bTRUE\b|\bFALSE\b`}, {Name: "LET", Pattern: `(?i)\bLET\b`}, - {Name: "Number", Pattern: `-?(0x[0-9a-f]+|\d*\.?\d+([eE][-+]?\d+)?)`}, + {Name: "Number", Pattern: `-?(0x[0-9a-fA-F]+|\d*\.?\d+([eE][-+]?\d+)?)`}, {Name: "Ident", Pattern: `[a-zA-Z_][a-zA-Z0-9_]*|` + "`[^`]+`"}, {Name: "SymbolIdent", Pattern: `-[a-zA-Z_][a-zA-Z0-9_]*|-` + "`[^`]+`"}, {Name: "Operators", Pattern: `<>|!=|<=|>=|=>|=~|[-]|[+]|[:*/%,.()=<>{}\[\]]`},