| 1 | package execution_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/tomwright/dasel/v3/model" |
| 7 | ) |
| 8 | |
| 9 | func TestFuncFirst(t *testing.T) { |
| 10 | t.Run("int array", testCase{ |
| 11 | s: `first([1, 2, 3])`, |
| 12 | out: model.NewIntValue(1), |
| 13 | }.run) |
| 14 | t.Run("string array", testCase{ |
| 15 | s: `first(["a", "b", "c"])`, |
| 16 | out: model.NewStringValue("a"), |
| 17 | }.run) |
| 18 | t.Run("single element", testCase{ |
| 19 | s: `first([42])`, |
| 20 | out: model.NewIntValue(42), |
| 21 | }.run) |
| 22 | t.Run("empty array", testCase{ |
| 23 | s: `first([])`, |
| 24 | out: model.NewNullValue(), |
| 25 | }.run) |
| 26 | t.Run("chained", testCase{ |
| 27 | s: `[1, 2, 3].first()`, |
| 28 | out: model.NewIntValue(1), |
| 29 | }.run) |
| 30 | } |