mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
fdf30b1ac8
Created an IndexValueStore class which can store any object and return an integer index to its hash map. Linear data is now stored in ve.dm.LinearData instances. Two subclasses for element and meta data contain methods specific to those data types (ElementLinearData and MetaLinearData). The static methods in ve.dm.Document that inspected data at a given offset are now instance methods of ve.dm.ElementLinearData. AnnotationSets (which are no longer OrderedHashSets) have been moved to /dm and also have to be instantiated with a pointer the store. Bug: 46320 Change-Id: I249a5d48726093d1cb3e36351893f4bff85f52e2
63 lines
2.3 KiB
JavaScript
63 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor IndexValueStore tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.dm.IndexValueStore' );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'index(es)/indexOfHash', 11, function ( assert ) {
|
|
var index, indexes,
|
|
object1 = { 'a': 1, 'b': 2 },
|
|
object2 = { 'c': 3, 'd': 4 },
|
|
store = new ve.dm.IndexValueStore();
|
|
|
|
index = store.index( object1 );
|
|
assert.equal( index, 0, 'First object stores in 0' );
|
|
index = store.index( object1 );
|
|
assert.equal( index, 0, 'First object re-stores in 0' );
|
|
index = store.index( object2 );
|
|
assert.equal( index, 1, 'Second object stores in 1' );
|
|
assert.deepEqual( store.value( 0 ), object1, '0th item is first object' );
|
|
|
|
index = store.index( object2, 'custom hash string' );
|
|
assert.equal( index, 2, 'Second object with custom hash stores in 2' );
|
|
index = store.index( object1, 'custom hash string' );
|
|
assert.equal( index, 2, 'Using the same custom hash stores in 2 again' );
|
|
assert.deepEqual( store.value( 0 ), object1, '2nd item is second object' );
|
|
|
|
assert.equal( store.indexOfHash( 'custom hash string' ), 2, 'Index of custom hash is 2' );
|
|
assert.equal( store.indexOfHash( 'unused hash string' ), null, 'Index of unused hash is null' );
|
|
|
|
store = new ve.dm.IndexValueStore();
|
|
|
|
indexes = store.indexes( [ object1, object2 ] );
|
|
assert.deepEqual( indexes, [ 0, 1 ], 'Store two objects in 0,1' );
|
|
|
|
store = new ve.dm.IndexValueStore();
|
|
|
|
index = store.index( 'String to store' );
|
|
assert.equal( store.value( 0 ), 'String to store', 'Strings are stored as strings, not objects' );
|
|
|
|
} );
|
|
|
|
QUnit.test( 'value(s)', 5, function ( assert ) {
|
|
var object1 = { 'a': 1, 'b': 2 },
|
|
object2 = { 'c': 3, 'd': 4 },
|
|
store = new ve.dm.IndexValueStore();
|
|
|
|
store.index( object1 );
|
|
store.index( object2 );
|
|
assert.deepEqual( store.value( 0 ), object1, 'Value 0 is first stored object' );
|
|
assert.deepEqual( store.value( 1 ), object2, 'Value 1 is second stored object' );
|
|
assert.equal( store.value( 2 ), undefined, 'Value 2 is undefined' );
|
|
assert.deepEqual( store.values( [1, 0] ), [ object2, object1 ], 'Values [1, 0] are second and first object' );
|
|
object1.a = 3;
|
|
assert.deepEqual( store.value( 0 ), { 'a': 1, 'b': 2 }, 'Value 0 is still first stored object after original has been modified' );
|
|
} );
|
|
|
|
|