| 1 | package execution_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/tomwright/dasel/v3/model" |
| 7 | _ "github.com/tomwright/dasel/v3/parsing/json" |
| 8 | ) |
| 9 | |
| 10 | func TestFuncKeys(t *testing.T) { |
| 11 | t.Run("returns slice indices", testCase{ |
| 12 | s: `[1,2,3,4,5].keys()`, |
| 13 | outFn: func() *model.Value { |
| 14 | r := model.NewSliceValue() |
| 15 | for i := 0; i < 5; i++ { |
| 16 | if err := r.Append(model.NewIntValue(int64(i))); err != nil { |
| 17 | panic(err) |
| 18 | } |
| 19 | } |
| 20 | return r |
| 21 | }, |
| 22 | }.run) |
| 23 | t.Run("returns map keys", testCase{ |
| 24 | s: `{"a": 3, "b": 4, "c": 5}.keys()`, |
| 25 | outFn: func() *model.Value { |
| 26 | r := model.NewSliceValue() |
| 27 | for _, key := range []string{"a", "b", "c"} { |
| 28 | if err := r.Append(model.NewStringValue(key)); err != nil { |
| 29 | panic(err) |
| 30 | } |
| 31 | } |
| 32 | return r |
| 33 | }, |
| 34 | }.run) |
| 35 | } |