| 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 TestCoalesce(t *testing.T) { |
| 11 | t.Run("first non-null", testCase{ |
| 12 | inFn: func() *model.Value { |
| 13 | return model.NewValue(orderedmap.NewMap().Set("a", "hello")) |
| 14 | }, |
| 15 | s: `a ?? "default"`, |
| 16 | out: model.NewStringValue("hello"), |
| 17 | }.run) |
| 18 | |
| 19 | t.Run("fallback on missing", testCase{ |
| 20 | inFn: func() *model.Value { |
| 21 | return model.NewValue(orderedmap.NewMap().Set("a", "hello")) |
| 22 | }, |
| 23 | s: `b ?? "default"`, |
| 24 | out: model.NewStringValue("default"), |
| 25 | }.run) |
| 26 | |
| 27 | t.Run("chained coalesce", testCase{ |
| 28 | inFn: func() *model.Value { |
| 29 | return model.NewValue(orderedmap.NewMap().Set("c", "found")) |
| 30 | }, |
| 31 | s: `a ?? b ?? c ?? "none"`, |
| 32 | out: model.NewStringValue("found"), |
| 33 | }.run) |
| 34 | } |