Debian Codegraph @

execution/func_has_test.go

raw symbols SCIP
1 package execution_test
2
3 import (
4 "testing"
5
6 "github.com/tomwright/dasel/v3/model"
7 )
8
9 func TestFuncHas(t *testing.T) {
10 t.Run("index in range", testCase{
11 s: `[1,2,3].has(0)`,
12 out: model.NewBoolValue(true),
13 }.run)
14 t.Run("negative index", testCase{
15 s: `[1,2,3].has(-1)`,
16 out: model.NewBoolValue(false),
17 }.run)
18 t.Run("index overflow", testCase{
19 s: `[1,2,3].has(3)`,
20 out: model.NewBoolValue(false),
21 }.run)
22 t.Run("index string", testCase{
23 s: `[1,2,3].has("foo")`,
24 out: model.NewBoolValue(false),
25 }.run)
26 t.Run("has map key", testCase{
27 s: `{"x":1}.has("x")`,
28 out: model.NewBoolValue(true),
29 }.run)
30 t.Run("does not have map key", testCase{
31 s: `{"x":1}.has("y")`,
32 out: model.NewBoolValue(false),
33 }.run)
34 t.Run("does not have map index", testCase{
35 s: `{"x":1}.has(1)`,
36 out: model.NewBoolValue(false),
37 }.run)
38 }