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
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-07-03 01:30:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2021-08-25 08:31:34 +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
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const store = new ve.dm.HashValueStore(),
|
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
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[ 0 ] ),
|
2015-03-07 04:43:53 +00:00
|
|
|
// 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
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[ 0 ] ),
|
2015-03-07 04:43:53 +00:00
|
|
|
// 1
|
|
|
|
{ type: '/mwBlockImage' },
|
|
|
|
// 2
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[ 0 ] ),
|
2015-03-07 04:43:53 +00:00
|
|
|
// 3
|
|
|
|
{ type: '/mwBlockImage' }
|
2013-10-15 16:50:01 +00:00
|
|
|
],
|
|
|
|
cases: [
|
|
|
|
{
|
|
|
|
direction: 1,
|
|
|
|
expand: false,
|
|
|
|
given: new ve.Range( 0, 2 ),
|
2018-12-10 12:45:12 +00:00
|
|
|
expected: new ve.Range( 2, 4 )
|
2013-10-15 16:50:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.copy( ve.dm.mwExample.MWBlockImage.data[ 0 ] ),
|
2015-03-07 04:43:53 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
for ( let i = 0; i < storeItems.length; i++ ) {
|
|
|
|
for ( let j = 0; j < storeItems[ i ].length; j++ ) {
|
2018-03-06 12:44:37 +00:00
|
|
|
store.hash( storeItems[ i ][ j ].value, storeItems[ i ][ j ].hash );
|
2013-10-15 12:18:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-29 14:42:18 +00:00
|
|
|
for ( let i = 0; i < tests.length; i++ ) {
|
|
|
|
const documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[ i ].data ) );
|
|
|
|
for ( let j = 0; j < tests[ i ].cases.length; j++ ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
assert.equalRange(
|
2014-09-18 23:56:11 +00:00
|
|
|
documentModel.getRelativeRange(
|
2015-08-19 17:33:02 +00:00
|
|
|
tests[ i ].cases[ j ].given,
|
|
|
|
tests[ i ].cases[ j ].direction,
|
2013-07-03 01:30:10 +00:00
|
|
|
'character',
|
2015-08-19 17:33:02 +00:00
|
|
|
tests[ i ].cases[ j ].expand
|
2013-07-03 01:30:10 +00:00
|
|
|
),
|
2015-08-19 17:33:02 +00:00
|
|
|
tests[ i ].cases[ j ].expected,
|
2014-07-05 20:56:21 +00:00
|
|
|
'Test document ' + i +
|
2015-08-19 17:33:02 +00:00
|
|
|
', range ' + tests[ i ].cases[ j ].given.toJSON() +
|
|
|
|
', direction ' + tests[ i ].cases[ j ].direction
|
2013-07-03 01:30:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|