Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Added logging for new operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Sep 6, 2018
1 parent b426902 commit 0bd10c8
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 15 deletions.
32 changes: 27 additions & 5 deletions src/dev-utils/enableenginedebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand All @@ -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 }`;
} );
Expand Down Expand Up @@ -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.
Expand Down
111 changes: 101 additions & 10 deletions tests/dev-utils/enableenginedebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 );

Expand All @@ -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 <blockQuote>'
);

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', () => {
Expand Down

0 comments on commit 0bd10c8

Please sign in to comment.