Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 2x 2x | import type {TestCase} from './types'; const testCases: TestCase[] = [ { comment: 'Can copy value to key of the same object', doc: {foo: 'bar'}, patch: [{op: 'copy', path: '/fooo', from: '/foo'}], expected: {foo: 'bar', fooo: 'bar'}, }, { comment: 'Can overwrite object key of the same object', doc: {foo: 'bar', a: 123}, patch: [{op: 'copy', path: '/foo', from: '/a'}], expected: {foo: 123, a: 123}, }, { comment: 'Can copy value from parent object to child array', doc: {foo: 'bar', arr: [1]}, patch: [{op: 'copy', path: '/arr/1', from: '/foo'}], expected: {foo: 'bar', arr: [1, 'bar']}, }, { comment: 'Can copy value from child object to adjacent child array', doc: {foo: {a: null}, arr: [1]}, patch: [{op: 'copy', path: '/arr/-', from: '/foo/a'}], expected: {foo: {a: null}, arr: [1, null]}, }, { comment: 'Can copy value from deep object to adjacent child array', doc: {foo: {a: {b: {c: {d: 123.4}}}}, arr: [1]}, patch: [{op: 'copy', path: '/arr/0', from: '/foo/a/b/c/d'}], expected: {foo: {a: {b: {c: {d: 123.4}}}}, arr: [123.4, 1]}, }, { comment: 'Can copy value from array into object', doc: { arr: [3, 2, 1], obj: {}, }, patch: [ {op: 'copy', path: '/obj/1', from: '/arr/2'}, {op: 'copy', path: '/test', from: '/arr/0'}, ], expected: { arr: [3, 2, 1], obj: { '1': 1, }, test: 3, }, }, { comment: 'Can copy values between two arrays', doc: { a: [3, 2, 1], b: ['c', 'a', 'b'], }, patch: [ {op: 'copy', path: '/a/-', from: '/b/1'}, {op: 'copy', path: '/a/-', from: '/b/0'}, {op: 'copy', path: '/a/4', from: '/b/2'}, ], expected: { a: [3, 2, 1, 'a', 'b', 'c'], b: ['c', 'a', 'b'], }, skipInJsonOt: true, }, { comment: 'Can copy value and return it back', doc: { a: {foo: 'bar'}, }, patch: [ {op: 'copy', path: '/b', from: '/a'}, {op: 'copy', path: '/a', from: '/b'}, ], expected: { a: {foo: 'bar'}, b: {foo: 'bar'}, }, }, ]; export default testCases; |