Merge "Added tests and fixed inconsistencies for empty text node handling"

This commit is contained in:
jenkins-bot 2013-01-29 23:16:30 +00:00 committed by Gerrit Code Review
commit 602d01e461
5 changed files with 16 additions and 28 deletions

View file

@ -122,15 +122,6 @@ ve.dm.Document = function VeDmDocument( data, parentDocument ) {
// This can only happen if we got unbalanced data
throw new Error( 'Unbalanced input passed to document' );
}
if ( children.length === 0 &&
ve.dm.nodeFactory.canNodeContainContent(
currentNode.getType()
)
) {
// Content nodes cannot be childless, add a zero-length text node
children.push( new ve.dm.TextNode( 0 ) );
}
// Attach the children to the node
ve.batchSplice( currentNode, 0, 0, children );
}

View file

@ -51,11 +51,6 @@ QUnit.test( 'getAnnotatedHtml', function ( assert ) {
['c', [ { 'type': 'textStyle/italic' } ]]
]
},
{
// [ ]
'data': [{ 'type': 'paragraph' },{ 'type': '/paragraph' }],
'html': []
},
{
// [ ]
'data': [{ 'type': 'paragraph' },' ',{ 'type': '/paragraph' }],

View file

@ -34,10 +34,8 @@ QUnit.test( 'constructor', 7, function ( assert ) {
doc = new ve.dm.Document( [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ] );
assert.equalNodeTree(
doc.getDocumentNode(),
new ve.dm.DocumentNode( [ new ve.dm.ParagraphNode(
[ new ve.dm.TextNode( 0 ) ], { 'type': 'paragraph' }
) ] ),
'empty paragraph gets a zero-length text node'
new ve.dm.DocumentNode( [ new ve.dm.ParagraphNode( [], { 'type': 'paragraph' } ) ] ),
'empty paragraph no longer has a text node'
);
doc = new ve.dm.Document( ve.copyArray( ve.dm.example.withMeta ) );

View file

@ -40,7 +40,7 @@ QUnit.test( 'protection against double application', 3, function ( assert ) {
);
} );
QUnit.test( 'commit/rollback', 62, function ( assert ) {
QUnit.test( 'commit/rollback', 66, function ( assert ) {
var i, key, originalData, originalDoc, msg, testDocument, tx,
expectedData, expectedDocument,
bold = ve.dm.example.createAnnotation( ve.dm.example.bold ),
@ -191,6 +191,16 @@ QUnit.test( 'commit/rollback', 62, function ( assert ) {
ve.setProp( data[0], 'internal', 'changed', 'content', 1 );
}
},
'emptying text': {
'calls': [
['pushRetain', 10],
['pushReplace', ['d'], []]
],
'expected': function ( data ) {
data.splice( 10, 1 );
ve.setProp( data[9], 'internal', 'changed', 'content', 1 );
}
},
'inserting mixed content': {
'calls': [
['pushRetain', 1],

View file

@ -32,17 +32,11 @@ function getNodeTreeSummary( node, shallow ) {
numChildren;
if ( node.children !== undefined ) {
// Count children manually to exclude zero-length text nodes
numChildren = 0;
numChildren = node.children.length;
if ( !shallow ) {
summary.children = [];
}
for ( i = 0; i < node.children.length; i++ ) {
if ( node.children[i].getType() !== 'text' || node.children[i].getLength() > 0 ) {
numChildren++;
if ( !shallow ) {
summary.children.push( getNodeTreeSummary( node.children[i] ) );
}
for ( i = 0; i < numChildren; i++ ) {
summary.children.push( getNodeTreeSummary( node.children[i] ) );
}
}
}