Debian Codegraph @

execution/execute_all_test.go

raw symbols SCIP
1 package execution_test
2
3 import (
4 "testing"
5
6 "github.com/tomwright/dasel/v3/model"
7 "github.com/tomwright/dasel/v3/model/orderedmap"
8 )
9
10 func TestAllExpr(t *testing.T) {
11 t.Run("all match", testCase{
12 s: `[1, 2, 3].all($this > 0)`,
13 out: model.NewBoolValue(true),
14 }.run)
15 t.Run("some match", testCase{
16 s: `[1, 2, 3].all($this > 1)`,
17 out: model.NewBoolValue(false),
18 }.run)
19 t.Run("none match", testCase{
20 s: `[1, 2, 3].all($this > 5)`,
21 out: model.NewBoolValue(false),
22 }.run)
23 t.Run("with equality", testCase{
24 s: `["a", "a", "a"].all($this == "a")`,
25 out: model.NewBoolValue(true),
26 }.run)
27 t.Run("empty array", testCase{
28 s: `[].all($this > 0)`,
29 out: model.NewBoolValue(true),
30 }.run)
31 t.Run("boolean literal true", testCase{
32 s: `[1, 2, 3].all(true)`,
33 out: model.NewBoolValue(true),
34 }.run)
35 t.Run("boolean literal false", testCase{
36 s: `[1, 2, 3].all(false)`,
37 out: model.NewBoolValue(false),
38 }.run)
39 t.Run("with negation", testCase{
40 s: `[1, 2, 3].all(!($this > 5))`,
41 out: model.NewBoolValue(true),
42 }.run)
43 t.Run("with nested property", testCase{
44 inFn: func() *model.Value {
45 s := model.NewSliceValue()
46 _ = s.Append(model.NewValue(orderedmap.NewMap().Set("active", true)))
47 _ = s.Append(model.NewValue(orderedmap.NewMap().Set("active", true)))
48 return s
49 },
50 s: `all(active == true)`,
51 out: model.NewBoolValue(true),
52 }.run)
53 t.Run("chained after filter", testCase{
54 s: `[1, 2, 3, 4, 5].filter($this > 2).all($this > 2)`,
55 out: model.NewBoolValue(true),
56 }.run)
57 t.Run("all with $key true", testCase{
58 s: `[10, 20, 30].all($key < 3)`,
59 out: model.NewBoolValue(true),
60 }.run)
61 t.Run("all with $key false", testCase{
62 s: `[10, 20, 30].all($key < 2)`,
63 out: model.NewBoolValue(false),
64 }.run)
65 }