(t *testing.T)
| 17 | } |
| 18 | |
| 19 | func TestAddOperation(t *testing.T) { |
| 20 | testCases := map[string]*operationTestCase{ |
| 21 | "adding an element to an object": { |
| 22 | input: "foo: bar", |
| 23 | operation: &Operation{ |
| 24 | Op: opAdd, |
| 25 | Path: ".baz", |
| 26 | Value: loadYamlFromString(`qux`), |
| 27 | }, |
| 28 | expected: ` |
| 29 | foo: bar |
| 30 | baz: qux |
| 31 | `, |
| 32 | }, |
| 33 | "adding an element to an array": { |
| 34 | input: "foo: [bar,baz]", |
| 35 | operation: &Operation{ |
| 36 | Op: opAdd, |
| 37 | Path: ".foo[1]", |
| 38 | Value: loadYamlFromString(`qux`), |
| 39 | }, |
| 40 | expected: "foo: [bar,qux,baz]", |
| 41 | }, |
| 42 | "adding an object to an object": { |
| 43 | input: ` |
| 44 | foo: bar |
| 45 | `, |
| 46 | operation: &Operation{ |
| 47 | Op: opAdd, |
| 48 | Path: ".child", |
| 49 | Value: loadYamlFromString(` |
| 50 | grandchild: {} |
| 51 | `), |
| 52 | }, |
| 53 | expected: ` |
| 54 | foo: bar |
| 55 | child: |
| 56 | grandchild: {} |
| 57 | `, |
| 58 | }, |
| 59 | "appending an element to an array": { |
| 60 | input: `foo: [bar]`, |
| 61 | operation: &Operation{ |
| 62 | Op: opAdd, |
| 63 | Path: ".foo", |
| 64 | Value: loadYamlFromString(`[abc,def]`), |
| 65 | }, |
| 66 | expected: `foo: [bar, [abc, def]]`, |
| 67 | }, |
| 68 | "adding a nil element to an object": { |
| 69 | input: ` |
| 70 | foo: bar |
| 71 | `, |
| 72 | operation: &Operation{ |
| 73 | Op: opAdd, |
| 74 | Path: ".baz", |
| 75 | Value: loadYamlFromString(`~`), |
| 76 | }, |
nothing calls this directly
no test coverage detected