Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/54640


Change subject: Create basic tests for AnnotationSet.
......................................................................

Create basic tests for AnnotationSet.

Also covers methods inherited from OrderedHashSet.

Bug: 46320
Change-Id: I632e4cf1b87312179a9ce52df0d590ff42f56325
---
M VisualEditor.hooks.php
M modules/ve/test/index.php
A modules/ve/test/ve.AnnotationSet.test.js
3 files changed, 66 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/40/54640/1

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 5b5a3d8..b5042e8 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -78,6 +78,7 @@
                                've.example.js',
                                've.Document.test.js',
                                've.Node.test.js',
+                               've.AnnotationSet.test.js',
                                've.BranchNode.test.js',
                                've.LeafNode.test.js',
                                've.Factory.test.js',
diff --git a/modules/ve/test/index.php b/modules/ve/test/index.php
index bb1c1f0..37c99f6 100644
--- a/modules/ve/test/index.php
+++ b/modules/ve/test/index.php
@@ -195,6 +195,7 @@
                <script src="ve.Trigger.test.js"></script>
                <script src="ve.Document.test.js"></script>
                <script src="ve.Node.test.js"></script>
+               <script src="ve.AnnotationSet.test.js"></script>
                <script src="ve.BranchNode.test.js"></script>
                <script src="ve.LeafNode.test.js"></script>
                <script src="ve.Factory.test.js"></script>
diff --git a/modules/ve/test/ve.AnnotationSet.test.js 
b/modules/ve/test/ve.AnnotationSet.test.js
new file mode 100644
index 0000000..bdf45c1
--- /dev/null
+++ b/modules/ve/test/ve.AnnotationSet.test.js
@@ -0,0 +1,64 @@
+/*!
+ * VisualEditor AnnotationSet tests.
+ *
+ * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+QUnit.module( 've.AnnotationSet' );
+
+/* Tests */
+
+QUnit.test( 'Basic usage', 26, function ( assert ) {
+       var annotationSet3,
+               bold = new ve.dm.TextStyleBoldAnnotation(),
+               italic = new ve.dm.TextStyleItalicAnnotation(),
+               underline = new ve.dm.TextStyleUnderlineAnnotation(),
+               annotationSet = new ve.AnnotationSet( [ bold, italic ] ),
+               annotationSet2 = new ve.AnnotationSet( [ italic, underline ] ),
+               emptySet = new ve.AnnotationSet();
+
+       assert.equal( annotationSet.getLength(), 2, 'getLength is 2' );
+       assert.equal( annotationSet.isEmpty(), false, 'isEmpty is false' );
+       assert.equal( annotationSet.get( 0 ), bold, 'get(0) is bold' );
+       assert.equal( annotationSet.contains( italic ), true, 'contains italic' 
);
+       assert.equal( annotationSet.contains( underline ), false, 'doesn\'t 
contain underline' );
+       assert.equal( annotationSet.containsAnyOf( annotationSet2 ), true, 
'containsAnyOf set2 is true' );
+       assert.equal( annotationSet.containsAnyOf( emptySet ), false, 
'containsAnyOf empty set is false' );
+       assert.equal( annotationSet.containsAllOf( annotationSet2 ), false, 
'containsAllOf set2 set is false' );
+       assert.equal( annotationSet.containsAllOf( annotationSet ), true, 
'containsAllOf slef is true' );
+       assert.equal( annotationSet.indexOf( italic ), 1, 'indexOf italic is 1' 
);
+       assert.equal( annotationSet.hasAnnotationWithName( 'textStyle/bold' ), 
true, 'hasAnnotationWithName textStyle/bold is true' );
+       assert.equal( annotationSet.hasAnnotationWithName( 
'textStyle/underline' ), false, 'hasAnnotationWithName underline is false' );
+
+       annotationSet2.add( bold, 1 );
+       assert.equal( annotationSet2.indexOf( bold ), 1, 'set2 contains bold at 
1 after add at 1' );
+       annotationSet2.remove( bold );
+       assert.equal( annotationSet2.contains( bold ), false, 'set2 doesn\'t 
contain bold after remove' );
+       annotationSet2.add( bold, 0 );
+       assert.equal( annotationSet2.indexOf( bold ), 0, 'set2 contains bold at 
0 after add at 0' );
+       // set is now [ bold, italic, underline ]
+       annotationSet2.removeAt( 2 );
+       assert.equal( annotationSet2.contains( underline ), false, 'set2 
doesn\'t contain underline after removeAt 2' );
+       annotationSet2.removeAll();
+       assert.equal( annotationSet2.isEmpty(), true, 'set2 is empty after 
removeAll' );
+       annotationSet2.addSet( annotationSet );
+       assert.equal( annotationSet.getLength(), 2, 'set2 has length 2 after 
addSet' );
+       annotationSet2.removeSet( annotationSet );
+       assert.equal( annotationSet2.isEmpty(), true, 'set2 is empty after 
removeSet' );
+
+       annotationSet2 = new ve.AnnotationSet( [ italic, underline ] );
+       annotationSet2.removeNotInSet( annotationSet );
+       assert.equal( annotationSet.contains( italic ) && 
!annotationSet.contains( underline ), true, 'contains italic not underline 
after removeNotInSet' );
+       annotationSet2.add( underline, 1 );
+       annotationSet3 = annotationSet2.reversed();
+       assert.equal( annotationSet3.indexOf( underline ), 0, 'underline has 
indexOf 0 after reverse');
+       annotationSet3 = annotationSet.mergeWith( annotationSet2 );
+       assert.equal( annotationSet3.getLength(), 3, 'set merged with set2 has 
length 3');
+       annotationSet3 = annotationSet.diffWith( annotationSet2 );
+       assert.equal( annotationSet3.getLength(), 1, 'set diffed with set2 has 
length 1');
+       assert.equal( annotationSet3.contains( bold ), true, 'set diffed with 
set2 contains bold');
+       annotationSet3 = annotationSet.intersectWith( annotationSet2 );
+       assert.equal( annotationSet3.getLength(), 1, 'set intersected with set2 
has length 1');
+       assert.equal( annotationSet3.contains( italic ), true, 'set intersected 
with set2 contains italic');
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/54640
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I632e4cf1b87312179a9ce52df0d590ff42f56325
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to