From 0bd10c82eb9dd0d762ca63dcecf193c342fd775f Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Thu, 6 Sep 2018 10:35:17 +0200 Subject: [PATCH] Other: Added logging for new operations. --- src/dev-utils/enableenginedebug.js | 32 ++++++-- tests/dev-utils/enableenginedebug.js | 111 ++++++++++++++++++++++++--- 2 files changed, 128 insertions(+), 15 deletions(-) diff --git a/src/dev-utils/enableenginedebug.js b/src/dev-utils/enableenginedebug.js index 7aa1282b4..c8a1fa0f3 100644 --- a/src/dev-utils/enableenginedebug.js +++ b/src/dev-utils/enableenginedebug.js @@ -25,6 +25,10 @@ import MoveOperation from '../model/operation/moveoperation'; import NoOperation from '../model/operation/nooperation'; import RenameOperation from '../model/operation/renameoperation'; import RootAttributeOperation from '../model/operation/rootattributeoperation'; +import WrapOperation from '../model/operation/wrapoperation'; +import UnwrapOperation from '../model/operation/unwrapoperation'; +import SplitOperation from '../model/operation/splitoperation'; +import MergeOperation from '../model/operation/mergeoperation'; import Model from '../model/model'; import ModelDocument from '../model/document'; import ModelDocumentFragment from '../model/documentfragment'; @@ -330,8 +334,7 @@ function enableLoggingTools() { sandbox.mock( MoveOperation.prototype, 'toString', function() { const range = ModelRange.createFromPositionAndShift( this.sourcePosition, this.howMany ); - return getClassName( this ) + `( ${ this.baseVersion } ): ` + - `${ range } -> ${ this.targetPosition }${ this.isSticky ? ' (sticky)' : '' }`; + return getClassName( this ) + `( ${ this.baseVersion } ): ${ range } -> ${ this.targetPosition }`; } ); sandbox.mock( NoOperation.prototype, 'toString', function() { @@ -348,6 +351,27 @@ function enableLoggingTools() { `"${ this.key }": ${ JSON.stringify( this.oldValue ) } -> ${ JSON.stringify( this.newValue ) }, ${ this.root.rootName }`; } ); + sandbox.mock( MergeOperation.prototype, 'toString', function() { + return getClassName( this ) + `( ${ this.baseVersion } ): ` + + `${ this.sourcePosition } -> ${ this.targetPosition } ( ${ this.howMany } ), ${ this.graveyardPosition }`; + } ); + + sandbox.mock( SplitOperation.prototype, 'toString', function() { + return getClassName( this ) + `( ${ this.baseVersion } ): ` + + `${ this.position } ( ${ this.howMany } )${ this.graveyardPosition ? ', ' + this.graveyardPosition : '' }`; + } ); + + sandbox.mock( WrapOperation.prototype, 'toString', function() { + const range = ModelRange.createFromPositionAndShift( this.position, this.howMany ); + + return getClassName( this ) + `( ${ this.baseVersion } ): ` + + `${ range } with ${ this.element ? this.element : this.graveyardPosition }`; + } ); + + sandbox.mock( UnwrapOperation.prototype, 'toString', function() { + return getClassName( this ) + `( ${ this.baseVersion } ): ${ this.position } ( ${ this.howMany } ), ${ this.graveyardPosition }`; + } ); + sandbox.mock( ViewText.prototype, 'toString', function() { return `#${ this.data }`; } ); @@ -547,9 +571,7 @@ function dumpTrees( document, version ) { // @param {module:engine/model/operation/operation~Operation} // @returns {String} Class name. function getClassName( obj ) { - const path = obj.constructor.className.split( '.' ); - - return path[ path.length - 1 ]; + return obj.constructor.className; } // Helper function, converts a map to the {"key1":"value1","key2":"value2"} format. diff --git a/tests/dev-utils/enableenginedebug.js b/tests/dev-utils/enableenginedebug.js index 3051fcb2b..8c20cd8e3 100644 --- a/tests/dev-utils/enableenginedebug.js +++ b/tests/dev-utils/enableenginedebug.js @@ -21,6 +21,10 @@ import MoveOperation from '../../src/model/operation/moveoperation'; import NoOperation from '../../src/model/operation/nooperation'; import RenameOperation from '../../src/model/operation/renameoperation'; import RootAttributeOperation from '../../src/model/operation/rootattributeoperation'; +import MergeOperation from '../../src/model/operation/mergeoperation'; +import SplitOperation from '../../src/model/operation/splitoperation'; +import WrapOperation from '../../src/model/operation/wrapoperation'; +import UnwrapOperation from '../../src/model/operation/unwrapoperation'; import Model from '../../src/model/model'; import ModelDocumentFragment from '../../src/model/documentfragment'; @@ -311,16 +315,6 @@ describe( 'debug tools', () => { expect( log.calledWithExactly( op.toString() ) ).to.be.true; } ); - it( 'MoveOperation sticky', () => { - const op = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( modelRoot, 6 ), 0 ); - op.isSticky = true; - - expect( op.toString() ).to.equal( 'MoveOperation( 0 ): main [ 1 ] - [ 3 ] -> main [ 6 ] (sticky)' ); - - op.log(); - expect( log.calledWithExactly( op.toString() ) ).to.be.true; - } ); - it( 'NoOperation', () => { const op = new NoOperation( 0 ); @@ -347,6 +341,103 @@ describe( 'debug tools', () => { op.log(); expect( log.calledWithExactly( op.toString() ) ).to.be.true; } ); + + it( 'MergeOperation', () => { + const op = new MergeOperation( + new ModelPosition( modelRoot, [ 1, 0 ] ), + 2, + new ModelPosition( modelRoot, [ 0, 2 ] ), + new ModelPosition( modelDoc.graveyard, [ 0 ] ), + 0 + ); + + expect( op.toString() ).to.equal( + 'MergeOperation( 0 ): main [ 1, 0 ] -> main [ 0, 2 ] ( 2 ), $graveyard [ 0 ]' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); + + it( 'SplitOperation without graveyard position', () => { + const op = new SplitOperation( + new ModelPosition( modelRoot, [ 1, 4 ] ), + 6, + null, + 0 + ); + + expect( op.toString() ).to.equal( + 'SplitOperation( 0 ): main [ 1, 4 ] ( 6 )' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); + + it( 'SplitOperation with graveyard position', () => { + const op = new SplitOperation( + new ModelPosition( modelRoot, [ 1, 4 ] ), + 6, + new ModelPosition( modelDoc.graveyard, [ 0 ] ), + 0 + ); + + expect( op.toString() ).to.equal( + 'SplitOperation( 0 ): main [ 1, 4 ] ( 6 ), $graveyard [ 0 ]' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); + + it( 'WrapOperation with element', () => { + const op = new WrapOperation( + new ModelPosition( modelRoot, [ 3 ] ), + 2, + new ModelElement( 'blockQuote' ), + 0 + ); + + expect( op.toString() ).to.equal( + 'WrapOperation( 0 ): main [ 3 ] - [ 5 ] with
' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); + + it( 'WrapOperation with graveyard position', () => { + const op = new WrapOperation( + new ModelPosition( modelRoot, [ 3 ] ), + 2, + new ModelPosition( modelDoc.graveyard, [ 0 ] ), + 0 + ); + + expect( op.toString() ).to.equal( + 'WrapOperation( 0 ): main [ 3 ] - [ 5 ] with $graveyard [ 0 ]' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); + + it( 'UnwrapOperation', () => { + const op = new UnwrapOperation( + new ModelPosition( modelRoot, [ 1, 0 ] ), + 2, + new ModelPosition( modelDoc.graveyard, [ 0 ] ), + 0 + ); + + expect( op.toString() ).to.equal( + 'UnwrapOperation( 0 ): main [ 1, 0 ] ( 2 ), $graveyard [ 0 ]' + ); + + op.log(); + expect( log.calledWithExactly( op.toString() ) ).to.be.true; + } ); } ); it( 'for applied operations', () => {