/*! * VisualEditor DataModel TreeModifier tests. * * @copyright See AUTHORS.txt */ ve.dm.TreeModifier.prototype.dump = function () { const lines = [], del = this.deletions, ins = this.insertions; function nodeTag( idx, node ) { return ( idx === undefined ? '' : idx + ' ' ) + ( del.includes( node ) ? 'DEL ' : ins.includes( node ) ? 'INS ' : '' ); } function appendNodeLines( indent, node, idx ) { const sp = '-\t'.repeat( indent ); if ( node.type === 'text' ) { lines.push( sp + nodeTag( idx, node ) + 'VeDmTextNode(' + node.getOuterLength() + ')' ); return; } lines.push( sp + nodeTag( idx, node ) + node.constructor.name + '(' + node.getOuterLength() + ')' ); if ( node.hasChildren() ) { node.children.forEach( ( child, i ) => { appendNodeLines( indent + 1, child, i ); } ); } } appendNodeLines( 0, this.document.documentNode ); lines.push( 'inserter: { path: [ ' + this.inserter.path.join( ', ' ) + ' ], offset: ' + this.inserter.offset + ' }, ' + 'linear ' + this.inserter.linearOffset + ', insertions: ' + JSON.stringify( this.insertedPositions ) ); lines.push( 'remover: { path: [ ' + this.remover.path.join( ', ' ) + ' ], offset: ' + this.remover.offset + ' }, ' + 'linear ' + this.remover.linearOffset ); lines.push( 'insertedPositions: ' + JSON.stringify( this.insertedPositions ) ); lines.push( 'insertedNodes: ' + JSON.stringify( this.insertedNodes ) ); lines.push( 'adjustments: ' + JSON.stringify( this.adjustmentTree ) ); lines.push( 'adjusted inserter: ' + JSON.stringify( this.adjustInserterPosition( this.getRawInserterPosition() ) ) ); lines.push( 'adjusted remover: ' + JSON.stringify( this.adjustRemoverPosition( this.getRawRemoverPosition( { path: this.remover.path, offset: this.remover.offset, node: this.remover.node } ) ) ) ); ve.batchSplice( lines, lines.length, 0, this.data.data.map( ( item, i ) => i + ':' + JSON.stringify( item ) + ',' ) ); return lines.join( '\n' ); }; ve.test.utils.nodesByTypeSummary = function ( doc ) { const nodesByType = ve.copy( doc.nodesByType ); for ( const type in nodesByType ) { nodesByType[ type ] = nodesByType[ type ].length; } return nodesByType; }; QUnit.module( 've.dm.TreeModifier' ); QUnit.test( 'treeDiff', ( assert ) => { // old:
foobarbaz
qux
quux
// new:foo
barBAZ
qux
qUUx
foo{+
+}bar{-baz-|+BAZ+}
qux
{-q{-uu-|+UU+}x
{++} [ { type: 'insertNode', isContent: false, at: [ 0, 0, 1 ], element: { type: 'paragraph' } } ], // Retain 3 [ { type: 'moveText', isContent: true, from: [ 1, 0, 0 ], length: 3, to: [ 0, 0, 1, 0 ] } // { 0: { diff: 1 }, 1: { 0: { 0: { diff: -6 } } } } ], // {-baz-|+BAZ+} [ { type: 'removeText', isContent: true, at: [ 1, 0, 0 ], data: [ ...'baz' ] }, // { 0: { diff: 1 }, 1: { 0: { 0: { diff: -9 } } } } { type: 'insertText', isContent: true, at: [ 0, 0, 1, 3 ], data: [ ...'baz' ] } ], // Retain 6 [ { type: 'removeNode', isContent: false, at: [ 1, 0 ], element: { type: 'paragraph' } }, // { 0: { diff: 1 }, 1: { 0: { diff: -1 } } } { type: 'moveNode', isContent: false, from: [ 1, 0 ], to: [ 0, 0, 2 ] } // { 0: { diff: 1 }, 1: { 0: { diff: -2 } } } ], // {-