2013-07-03 01:30:10 +00:00
|
|
|
/*!
|
2014-09-18 23:56:11 +00:00
|
|
|
* VisualEditor DataModel Document tests.
|
2013-07-03 01:30:10 +00:00
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2013-07-03 01:30:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2015-02-13 19:46:28 +00:00
|
|
|
QUnit.module( 've.dm.Document (MW)' );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
|
|
|
// FIXME runner copypasted from core, use data provider
|
|
|
|
QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert ) {
|
2014-09-18 23:56:11 +00:00
|
|
|
var documentModel, i, j,
|
|
|
|
expectCount = 0,
|
2013-10-15 16:50:01 +00:00
|
|
|
store = new ve.dm.IndexValueStore(),
|
2013-10-15 12:18:11 +00:00
|
|
|
storeItems = [
|
|
|
|
ve.dm.mwExample.MWBlockImage.storeItems,
|
|
|
|
ve.dm.mwExample.MWInlineImage.storeItems
|
|
|
|
],
|
2013-07-03 01:30:10 +00:00
|
|
|
tests = [
|
2013-10-15 16:50:01 +00:00
|
|
|
{
|
|
|
|
data: [
|
2015-03-07 04:43:53 +00:00
|
|
|
// 0
|
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
|
|
|
// 1
|
|
|
|
{ type: '/mwBlockImage' }
|
2013-10-15 16:50:01 +00:00
|
|
|
],
|
|
|
|
cases: [
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0 ),
|
|
|
|
expected: new ve.Range( 0, 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0 ),
|
|
|
|
expected: new ve.Range( 0, 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 0, 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 2 ),
|
|
|
|
expected: new ve.Range( 2, 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 2, 0 ),
|
|
|
|
expected: new ve.Range( 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 2 ),
|
|
|
|
expected: new ve.Range( 2, 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 2, 0 ),
|
|
|
|
expected: new ve.Range( 2, 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 0 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: [
|
2015-03-07 04:43:53 +00:00
|
|
|
// 0
|
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
|
|
|
// 1
|
|
|
|
{ type: '/mwBlockImage' },
|
|
|
|
// 2
|
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
|
|
|
// 3
|
|
|
|
{ type: '/mwBlockImage' }
|
2013-10-15 16:50:01 +00:00
|
|
|
],
|
|
|
|
cases: [
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 2, 4 ),
|
|
|
|
expected: new ve.Range( 4 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 0, 4 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 4, 2 ),
|
|
|
|
expected: new ve.Range( 4, 0 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: -1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 2, 4 ),
|
|
|
|
expected: new ve.Range( 2 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: [
|
2015-03-07 04:43:53 +00:00
|
|
|
// 0
|
|
|
|
{ type: 'alienBlock' },
|
|
|
|
// 1
|
|
|
|
{ type: '/alienBlock' },
|
|
|
|
// 2
|
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
|
|
|
// 3
|
|
|
|
{ type: '/mwBlockImage' },
|
|
|
|
// 4
|
|
|
|
{ type: 'alienBlock' },
|
|
|
|
// 5
|
|
|
|
{ type: '/alienBlock' }
|
2013-10-15 16:50:01 +00:00
|
|
|
],
|
|
|
|
cases: [
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0 ),
|
2014-06-10 23:19:50 +00:00
|
|
|
expected: new ve.Range( 0, 2 )
|
2013-10-15 16:50:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 2 ),
|
|
|
|
expected: new ve.Range( 2, 4 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 2, 4 ),
|
|
|
|
expected: new ve.Range( 4 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 4 ),
|
2014-06-10 23:19:50 +00:00
|
|
|
expected: new ve.Range( 4, 6 )
|
2013-10-15 16:50:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0 ),
|
|
|
|
expected: new ve.Range( 0, 2 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
|
|
|
expected: new ve.Range( 0, 4 )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: true,
|
|
|
|
given: new ve.Range( 0, 4 ),
|
|
|
|
expected: new ve.Range( 0, 6 )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: [
|
2015-03-07 04:43:53 +00:00
|
|
|
// 0
|
|
|
|
{ type: 'paragraph' },
|
|
|
|
// 1
|
|
|
|
{ type: 'alienInline' },
|
|
|
|
// 2
|
|
|
|
{ type: '/alienInline' },
|
|
|
|
// 3
|
|
|
|
ve.copy( ve.dm.mwExample.MWInlineImage.data ),
|
|
|
|
// 4
|
|
|
|
{ type: '/mwInlineImage' },
|
|
|
|
// 5
|
|
|
|
{ type: 'alienInline' },
|
|
|
|
// 6
|
|
|
|
{ type: '/alienInline' },
|
|
|
|
// 7
|
|
|
|
{ type: '/paragraph' }
|
2013-10-15 16:50:01 +00:00
|
|
|
],
|
|
|
|
cases: [
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 1 ),
|
2014-06-10 23:19:50 +00:00
|
|
|
expected: new ve.Range( 1, 3 )
|
2013-10-15 16:50:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 5 ),
|
2014-06-10 23:19:50 +00:00
|
|
|
expected: new ve.Range( 5, 7 )
|
2013-10-15 16:50:01 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2013-10-15 12:18:11 +00:00
|
|
|
for ( i = 0; i < storeItems.length; i++ ) {
|
|
|
|
for ( j = 0; j < storeItems[i].length; j++ ) {
|
|
|
|
store.index( storeItems[i][j].value, storeItems[i][j].hash );
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 01:30:10 +00:00
|
|
|
for ( i = 0; i < tests.length; i++ ) {
|
2013-10-15 16:50:01 +00:00
|
|
|
documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[i].data ) );
|
2013-07-03 01:30:10 +00:00
|
|
|
for ( j = 0; j < tests[i].cases.length; j++ ) {
|
|
|
|
expectCount++;
|
|
|
|
assert.equalRange(
|
2014-09-18 23:56:11 +00:00
|
|
|
documentModel.getRelativeRange(
|
2013-07-03 01:30:10 +00:00
|
|
|
tests[i].cases[j].given,
|
|
|
|
tests[i].cases[j].direction,
|
|
|
|
'character',
|
|
|
|
tests[i].cases[j].expand
|
|
|
|
),
|
|
|
|
tests[i].cases[j].expected,
|
2014-07-05 20:56:21 +00:00
|
|
|
'Test document ' + i +
|
|
|
|
', range ' + tests[i].cases[j].given.toJSON() +
|
|
|
|
', direction ' + tests[i].cases[j].direction
|
2013-07-03 01:30:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QUnit.expect( expectCount );
|
|
|
|
} );
|