| 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 TestFuncGet(t *testing.T) { |
| 11 | t.Run("returns array element", testCase{ |
| 12 | s: `[1,2,3,4,5].get(3)`, |
| 13 | out: model.NewIntValue(4), |
| 14 | }.run) |
| 15 | t.Run("returns map key", testCase{ |
| 16 | s: `{"a": 3, "b": 4, "c": 5}.get("b")`, |
| 17 | out: model.NewIntValue(4), |
| 18 | }.run) |
| 19 | t.Run("coalesce with invalid map accessor", testCase{ |
| 20 | s: `{}.get("a") ?? "missing"`, |
| 21 | out: model.NewStringValue("missing"), |
| 22 | }.run) |
| 23 | t.Run("returns null when string accessor used on slice", testCase{ |
| 24 | s: `[].get(0) ?? "missing"`, |
| 25 | out: model.NewStringValue("missing"), |
| 26 | }.run) |
| 27 | } |