| 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 TestUnary(t *testing.T) { |
| 11 | t.Run("not", func(t *testing.T) { |
| 12 | t.Run("literals", func(t *testing.T) { |
| 13 | t.Run("not true", testCase{ |
| 14 | s: `!true`, |
| 15 | out: model.NewBoolValue(false), |
| 16 | }.run) |
| 17 | t.Run("not not true", testCase{ |
| 18 | s: `!!true`, |
| 19 | out: model.NewBoolValue(true), |
| 20 | }.run) |
| 21 | t.Run("not not not true", testCase{ |
| 22 | s: `!!!true`, |
| 23 | out: model.NewBoolValue(false), |
| 24 | }.run) |
| 25 | t.Run("not false", testCase{ |
| 26 | s: `!false`, |
| 27 | out: model.NewBoolValue(true), |
| 28 | }.run) |
| 29 | t.Run("not not false", testCase{ |
| 30 | s: `!!false`, |
| 31 | out: model.NewBoolValue(false), |
| 32 | }.run) |
| 33 | t.Run("not not not false", testCase{ |
| 34 | s: `!!!false`, |
| 35 | out: model.NewBoolValue(true), |
| 36 | }.run) |
| 37 | }) |
| 38 | t.Run("variables", func(t *testing.T) { |
| 39 | in := func() *model.Value { |
| 40 | return model.NewValue(orderedmap.NewMap(). |
| 41 | Set("t", true). |
| 42 | Set("f", false)) |
| 43 | } |
| 44 | t.Run("not true", testCase{ |
| 45 | s: `!t`, |
| 46 | inFn: in, |
| 47 | out: model.NewBoolValue(false), |
| 48 | }.run) |
| 49 | t.Run("not not true", testCase{ |
| 50 | s: `!!t`, |
| 51 | inFn: in, |
| 52 | out: model.NewBoolValue(true), |
| 53 | }.run) |
| 54 | t.Run("not not not true", testCase{ |
| 55 | s: `!!!t`, |
| 56 | inFn: in, |
| 57 | out: model.NewBoolValue(false), |
| 58 | }.run) |
| 59 | t.Run("not false", testCase{ |
| 60 | s: `!f`, |
| 61 | inFn: in, |
| 62 | out: model.NewBoolValue(true), |
| 63 | }.run) |
| 64 | t.Run("not not false", testCase{ |
| 65 | s: `!!f`, |
| 66 | inFn: in, |
| 67 | out: model.NewBoolValue(false), |
| 68 | }.run) |
| 69 | t.Run("not not not false", testCase{ |
| 70 | s: `!!!f`, |
| 71 | inFn: in, |
| 72 | out: model.NewBoolValue(true), |
| 73 | }.run) |
| 74 | }) |
| 75 | }) |
| 76 | } |