| 1 | package execution_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/tomwright/dasel/v3/model" |
| 7 | ) |
| 8 | |
| 9 | func TestFuncReplace(t *testing.T) { |
| 10 | t.Run("input arg", testCase{ |
| 11 | s: `replace("hello world", "world", "there")`, |
| 12 | out: model.NewStringValue("hello there"), |
| 13 | }.run) |
| 14 | |
| 15 | t.Run("multiple data arg", testCase{ |
| 16 | s: `replace("hello world", "o", "0", "l", "1")`, |
| 17 | out: model.NewStringValue("he110 w0r1d"), |
| 18 | }.run) |
| 19 | |
| 20 | t.Run("data arg", testCase{ |
| 21 | s: `"hello world".replace("o", "0")`, |
| 22 | out: model.NewStringValue("hell0 w0rld"), |
| 23 | }.run) |
| 24 | |
| 25 | t.Run("multiple data arg", testCase{ |
| 26 | s: `"hello world".replace("o", "0", "h", "H")`, |
| 27 | out: model.NewStringValue("Hell0 w0rld"), |
| 28 | }.run) |
| 29 | |
| 30 | t.Run("data arg with input arg ignores data arg", testCase{ |
| 31 | s: `"bob".replace("hello world", "o", "0", "world", "there")`, |
| 32 | out: model.NewStringValue("hell0 there"), |
| 33 | }.run) |
| 34 | } |