Add some more tests for newFromInsertion

Change-Id: I3c403928a8176d8685e48a63759fefec4657ca96
This commit is contained in:
Catrope 2012-06-04 06:41:32 -07:00
parent 109624e8b3
commit e67b2fd793

View file

@ -36,19 +36,7 @@ ve.dm.Transaction.runConstructorTests = function( constructor, cases ) {
test( 'newFromInsertion', function() { test( 'newFromInsertion', function() {
var doc = new ve.dm.Document( ve.dm.example.data ), var doc = new ve.dm.Document( ve.dm.example.data ),
cases = { cases = {
'content in first element': { 'paragraph before first element': {
'args': [doc, 1, ['1', '2', '3']],
'ops': [
{ 'type': 'retain', 'length': 1 },
{
'type': 'replace',
'remove': [],
'insert': ['1', '2', '3']
},
{ 'type': 'retain', 'length': 58 }
]
},
'before first element': {
'args': [doc, 0, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]], 'args': [doc, 0, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]],
'ops': [ 'ops': [
{ {
@ -59,7 +47,7 @@ test( 'newFromInsertion', function() {
{ 'type': 'retain', 'length': 59 } { 'type': 'retain', 'length': 59 }
] ]
}, },
'after last element': { 'paragraph after last element': {
'args': [doc, 59, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]], 'args': [doc, 59, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]],
'ops': [ 'ops': [
{ 'type': 'retain', 'length': 59 }, { 'type': 'retain', 'length': 59 },
@ -81,7 +69,106 @@ test( 'newFromInsertion', function() {
}, },
{ 'type': 'retain', 'length': 50 } { 'type': 'retain', 'length': 50 }
] ]
},
'paragraph inside a heading closes and reopens heading': {
'args': [doc, 2, [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]],
'ops': [
{ 'type': 'retain', 'length': 2 },
{
'type': 'replace',
'remove': [],
// FIXME should retain attributes in heading opening
'insert': [{'type': '/heading' }, { 'type': 'paragraph' } , 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'heading' }]
},
{ 'type': 'retain', 'length': 57 }
]
},
'paragraph inside a list closes and reopens list': {
'args': [doc, 12, [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]],
'ops': [
{ 'type': 'retain', 'length': 12 },
{
'type': 'replace',
'remove': [],
'insert': [{'type': '/list' }, { 'type': 'paragraph' } , 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'list' }]
},
{ 'type': 'retain', 'length': 47 }
]
},
'tableCell inside the document is wrapped in a table and a tableRow': {
'args': [doc, 41, [{ 'type': 'tableCell' }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }]],
'ops': [
{ 'type': 'retain', 'length': 41 },
{
'type': 'replace',
'remove': [],
'insert': [{ 'type': 'table' }, { 'type': 'tableRow' }, { 'type': 'tableCell' }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }, { 'type': '/tableRow' }, { 'type': '/table' }]
},
{ 'type': 'retain', 'length': 18 }
]
},
'tableCell inside a paragraph is wrapped in a table and a tableRow and closes and reopens the paragraph': {
'args': [doc, 50, [{ 'type': 'tableCell' }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }]],
'ops': [
{ 'type': 'retain', 'length': 50 },
{
'type': 'replace',
'remove': [],
'insert': [{ 'type': '/paragraph' }, { 'type': 'table' }, { 'type': 'tableRow' }, { 'type': 'tableCell' }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }, { 'type': '/tableRow' }, { 'type': '/table' }, { 'type': 'paragraph' }]
},
{ 'type': 'retain', 'length': 9 }
]
},
'text at a structural location in the document is wrapped in a paragraph': {
'args': [doc, 0, ['F', 'O', 'O']],
'ops': [
{
'type': 'replace',
'remove': [],
'insert': [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]
},
{ 'type': 'retain', 'length': 59 }
]
},
'text inside a paragraph is not wrapped in a paragraph': {
'args': [doc, 15, ['F', 'O', 'O']],
'ops': [
{ 'type': 'retain', 'length': 15 },
{
'type': 'replace',
'remove': [],
'insert': ['F', 'O', 'O']
},
{ 'type': 'retain', 'length': 44 }
]
},
'text inside a heading is not wrapped in a paragraph': {
'args': [doc, 2, ['F', 'O', 'O']],
'ops': [
{ 'type': 'retain', 'length': 2 },
{
'type': 'replace',
'remove': [],
'insert': ['F', 'O', 'O']
},
{ 'type': 'retain', 'length': 57 }
]
},
'text inside a tableRow is wrapped in a paragraph and closes and reopens the tableRow and the table': {
'args': [doc, 33, ['F', 'O', 'O']],
'ops': [
{ 'type': 'retain', 'length': 33 },
{
'type': 'replace',
'remove': [],
'insert': [{ 'type': '/tableRow' }, { 'type': '/table' }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'table' }, { 'type': 'tableRow' }]
},
{ 'type': 'retain', 'length': 26 }
]
} }
// TODO test cases for unclosed openings
// TODO test cases for (currently failing) unopened closings use case
// TODO analyze other possible cases (substrings of linmod data)
}; };
ve.dm.Transaction.runConstructorTests( ve.dm.Transaction.newFromInsertion, cases ); ve.dm.Transaction.runConstructorTests( ve.dm.Transaction.newFromInsertion, cases );
} ); } );