| 1 | package execution_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/tomwright/dasel/v3/model" |
| 7 | ) |
| 8 | |
| 9 | func TestFuncRound(t *testing.T) { |
| 10 | t.Run("rounds up", testCase{ |
| 11 | s: `round(3.7)`, |
| 12 | out: model.NewIntValue(4), |
| 13 | }.run) |
| 14 | t.Run("rounds down", testCase{ |
| 15 | s: `round(3.2)`, |
| 16 | out: model.NewIntValue(3), |
| 17 | }.run) |
| 18 | t.Run("half rounds up", testCase{ |
| 19 | s: `round(3.5)`, |
| 20 | out: model.NewIntValue(4), |
| 21 | }.run) |
| 22 | t.Run("negative", testCase{ |
| 23 | s: `round(-3.7)`, |
| 24 | out: model.NewIntValue(-4), |
| 25 | }.run) |
| 26 | t.Run("int passthrough", testCase{ |
| 27 | s: `round(5)`, |
| 28 | out: model.NewIntValue(5), |
| 29 | }.run) |
| 30 | t.Run("chained", testCase{ |
| 31 | s: `(3.7).round()`, |
| 32 | out: model.NewIntValue(4), |
| 33 | }.run) |
| 34 | } |