Files
chaisql/internal/expr/functions/builtins_test.go
Jean Hadrien Chabran e556fc3048 Add functions packages support (#419)
* Add packaged functions support

* Add tests for math.floor func

* Export FunctionsTable

* Extract func stuff into its own package

* Rename stuff

* Fix tests

* Move doc package to cmd/genji

* Adjust naming, typos
2021-07-17 13:07:16 +02:00

55 lines
1.2 KiB
Go

package functions_test
import (
"testing"
"github.com/genjidb/genji/document"
"github.com/genjidb/genji/internal/environment"
"github.com/genjidb/genji/internal/testutil"
)
var doc document.Document = func() document.Document {
return document.NewFromJSON([]byte(`{
"a": 1,
"b": {"foo bar": [1, 2]},
"c": [1, {"foo": "bar"}, [1, 2]]
}`))
}()
var docWithKey document.Document = func() document.Document {
fb := document.NewFieldBuffer()
err := fb.Copy(doc)
if err != nil {
panic(err)
}
fb.DecodedKey = document.NewIntegerValue(1)
fb.EncodedKey, err = fb.DecodedKey.MarshalBinary()
if err != nil {
panic(err)
}
return fb
}()
var envWithDoc = environment.New(doc)
var envWithDocAndKey = environment.New(docWithKey)
func TestPk(t *testing.T) {
tests := []struct {
name string
env *environment.Environment
res document.Value
}{
{"empty env", &environment.Environment{}, document.NewNullValue()},
{"env with doc", envWithDoc, document.NewNullValue()},
{"env with doc and key", envWithDocAndKey, document.NewIntegerValue(1)},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
testutil.TestExpr(t, "pk()", test.env, test.res, false)
})
}
}