JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/*!
|
2013-01-15 23:38:49 +00:00
|
|
|
* VisualEditor DataModel Transaction tests.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
QUnit.module( 've.dm.Transaction' );
|
2012-04-20 01:11:08 +00:00
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
/* Helper methods */
|
2012-05-31 21:39:34 +00:00
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
function runBuilderTests( assert, cases ) {
|
|
|
|
var msg, tx, i;
|
|
|
|
for ( msg in cases ) {
|
|
|
|
tx = new ve.dm.Transaction();
|
|
|
|
for ( i = 0; i < cases[msg].calls.length; i++ ) {
|
2012-05-31 21:39:34 +00:00
|
|
|
tx[cases[msg].calls[i][0]].apply( tx, cases[msg].calls[i].slice( 1 ) );
|
|
|
|
}
|
2013-06-05 17:22:01 +00:00
|
|
|
assert.deepEqualWithDomElements( tx.getOperations(), cases[msg].ops, msg + ': operations match' );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.deepEqual( tx.getLengthDifference(), cases[msg].diff, msg + ': length differences match' );
|
2012-05-31 21:39:34 +00:00
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
}
|
2012-05-31 21:39:34 +00:00
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
function runConstructorTests( assert, constructor, cases ) {
|
|
|
|
var msg, tx;
|
|
|
|
for ( msg in cases ) {
|
2012-05-31 21:39:34 +00:00
|
|
|
if ( cases[msg].ops ) {
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
tx = constructor.apply(
|
2012-05-31 21:39:34 +00:00
|
|
|
ve.dm.Transaction, cases[msg].args
|
|
|
|
);
|
2013-06-05 17:22:01 +00:00
|
|
|
assert.deepEqualWithDomElements( tx.getOperations(), cases[msg].ops, msg + ': operations match' );
|
2012-05-31 21:39:34 +00:00
|
|
|
} else if ( cases[msg].exception ) {
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
/*jshint loopfunc:true */
|
|
|
|
assert.throws( function () {
|
Make use of new jshint options
* Restricting "camelcase":
No changes, we were passing all of these already
* Explicitly unrestricting "forin" and "plusplus"
These are off by default in node-jshint, but some distro of jshint
and editors that use their own wrapper around jshint instead of
node-jshint (Eclipse?) may have different defaults. Therefor
setting them to false explicitly. This also serves as a reminder
for the future so we'll always know we don't pass that, in case
we would want to change that.
* Fix order ("quotemark" before "regexp")
* Restricting "unused"
We're not passing all of this, which is why I've set it to false
for now. But I did put it in .jshintrc as placeholder.
I've fixed most of them, there's some left where there is no clean
solution.
* While at it fix a few issues:
- Unused variables ($target, $window)
- Bad practices (using jQuery context for find instead of creation)
- Redundant /*global */ comments
- Parameters that are not used and don't have documentation either
- Lines longer than 100 chars @ 4 spaces/tab
* Note:
- ve.ce.Surface.prototype.onChange takes two arguments but never
uses the former. And even the second one can be null/undefined.
Aside from that, the .change() function emits
another event for the transaction already. Looks like this
should be refactored a bit, two more separated events probably
or one that is actually used better.
- Also cleaned up a lot of comments, some of which were missing,
others were incorrect
- Reworked the contentChange event so we are no longer using the
word new as an object key; expanded a complex object into multiple
arguments being passed through the event to make it easier to work
with and document
Change-Id: I8490815a508c6c379d5f9a743bb4aefd14576aa6
2012-08-07 06:02:18 +00:00
|
|
|
constructor.apply(
|
2012-05-31 21:39:34 +00:00
|
|
|
ve.dm.Transaction, cases[msg].args
|
|
|
|
);
|
|
|
|
}, cases[msg].exception, msg + ': throw exception' );
|
|
|
|
}
|
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
}
|
2012-05-31 21:39:34 +00:00
|
|
|
|
2012-05-11 23:49:31 +00:00
|
|
|
/* Tests */
|
2012-05-07 18:45:31 +00:00
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'newFromInsertion', function ( assert ) {
|
2012-10-25 20:06:07 +00:00
|
|
|
var i, key,
|
2013-03-20 22:35:05 +00:00
|
|
|
doc = ve.dm.example.createExampleDocument(),
|
2013-04-26 18:41:27 +00:00
|
|
|
isolationDoc = ve.dm.example.createExampleDocument( 'isolationData' ),
|
|
|
|
complexTableDoc = ve.dm.example.createExampleDocument( 'complexTable' ),
|
2013-03-20 22:35:05 +00:00
|
|
|
doc2 = new ve.dm.Document(
|
|
|
|
ve.dm.example.preprocessAnnotations( [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ] )
|
|
|
|
),
|
2013-04-26 18:41:27 +00:00
|
|
|
doc3 = new ve.dm.Document(
|
|
|
|
ve.dm.example.preprocessAnnotations( [ { 'type': 'paragraph' }, 'F', 'o', 'o', { 'type': '/paragraph' } ] )
|
|
|
|
),
|
2012-05-31 21:39:34 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'paragraph before first element': {
|
|
|
|
'args': [doc, 0, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 63 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'paragraph after last element': {
|
2013-06-10 23:05:42 +00:00
|
|
|
'args': [doc, 63, [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]],
|
2013-04-06 16:45:26 +00:00
|
|
|
'ops': [
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 63 },
|
2013-04-06 16:45:26 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, '1', { 'type': '/paragraph' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'split paragraph': {
|
|
|
|
'args': [doc, 10, ['1', { 'type': '/paragraph' }, { 'type': 'paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 10 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': ['1', { 'type': '/paragraph' }, { 'type': 'paragraph' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 53 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'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': [],
|
|
|
|
'insert': [{'type': '/heading' }, { 'type': 'paragraph' } , 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'heading', 'attributes': { 'level': 1 } }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 61 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'paragraph inside a list moves in front of list': {
|
2013-04-06 16:45:26 +00:00
|
|
|
'args': [doc, 13, [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 12 },
|
2013-04-06 16:45:26 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [{ 'type': 'paragraph' } , 'F', 'O', 'O', { 'type': '/paragraph' }]
|
2013-04-06 16:45:26 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 51 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'tableCell inside the document is wrapped in a table, tableSection and tableRow': {
|
|
|
|
'args': [doc, 43, [{ 'type': 'tableCell', 'attributes': { 'style': 'data' } }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 43 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'table' }, { 'type': 'tableSection', 'attributes': { 'style': 'body' } }, { 'type': 'tableRow' }, { 'type': 'tableCell', 'attributes': { 'style': 'data' } }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }, { 'type': '/tableRow' }, { 'type': '/tableSection' }, { 'type': '/table' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 20 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'tableCell inside a paragraph is wrapped in a table, tableSection and tableRow and moves outside of paragraph': {
|
2013-04-06 16:45:26 +00:00
|
|
|
'args': [doc, 52, [{ 'type': 'tableCell', 'attributes': { 'style': 'data' } }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }]],
|
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 53 },
|
2013-04-06 16:45:26 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [{ 'type': 'table' }, { 'type': 'tableSection', 'attributes': { 'style': 'body' } }, { 'type': 'tableRow' }, { 'type': 'tableCell', 'attributes': { 'style': 'data' } }, { 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': '/tableCell' }, { 'type': '/tableRow' }, { 'type': '/tableSection' }, { 'type': '/table' }]
|
2013-04-06 16:45:26 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 10 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'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' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 63 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'text inside a paragraph is not wrapped in a paragraph': {
|
|
|
|
'args': [doc, 16, ['F', 'O', 'O']],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 16 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': ['F', 'O', 'O']
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 47 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'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']
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 61 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'text inside a tableSection moves all the way to the end of the table and is wrapped in a paragraph': {
|
2013-04-06 16:45:26 +00:00
|
|
|
'args': [doc, 34, ['F', 'O', 'O']],
|
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 37 },
|
2013-04-06 16:45:26 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]
|
2013-04-06 16:45:26 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 26 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert two complete paragraphs into start of paragraph moves insertion point left': {
|
2013-04-25 21:02:47 +00:00
|
|
|
'args': [doc, 10, [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 9 },
|
2013-04-25 21:02:47 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]
|
2013-04-25 21:02:47 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 54 }
|
2013-04-25 21:02:47 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert text, close paragraph and open heading into end of paragraph moves insertion point right': {
|
2013-04-25 21:02:47 +00:00
|
|
|
'args': [doc, 57, ['F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'heading', 'attributes': { 'level': 1 } }, 'B', 'A', 'R']],
|
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 58 },
|
2013-04-25 21:02:47 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'heading', 'attributes': { 'level': 1 } }, 'B', 'A', 'R', { 'type': '/heading' }]
|
2013-04-25 21:02:47 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 5 }
|
2013-04-25 21:02:47 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert heading and incomplete paragraph into heading': {
|
|
|
|
'args': [doc, 2, [{ 'type': 'heading', 'attributes': { 'level': 1 } }, 'F', 'O', 'O', { 'type': '/heading' }, { 'type': 'paragraph' }, 'B', 'A', 'R']],
|
2013-04-25 21:02:47 +00:00
|
|
|
'ops': [
|
2013-04-26 18:41:27 +00:00
|
|
|
{ 'type': 'retain', 'length': 2 },
|
2013-04-25 21:02:47 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
2013-04-26 18:41:27 +00:00
|
|
|
'insert': [
|
|
|
|
{ 'type': '/heading' }, { 'type': 'heading', 'attributes': { 'level': 1 } }, 'F', 'O', 'O', { 'type': '/heading' },
|
|
|
|
{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' },
|
|
|
|
{ 'type': 'heading', 'attributes': { 'level': 1 } }
|
|
|
|
]
|
2013-04-25 21:02:47 +00:00
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 61 }
|
2013-04-25 21:02:47 +00:00
|
|
|
]
|
|
|
|
},
|
2013-04-06 16:45:26 +00:00
|
|
|
'inserting two paragraphs into a document with just an empty paragraph': {
|
|
|
|
'args': [doc2, 1, ['F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R']],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': ['F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R']
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting three paragraphs into a document with just an empty paragraph': {
|
|
|
|
'args': [doc2, 1, ['F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'Z']],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': ['F', 'O', 'O', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'Z']
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 }
|
|
|
|
]
|
2013-04-26 18:41:27 +00:00
|
|
|
},
|
|
|
|
'inserting one paragraph into empty paragraph moves insertion before': {
|
|
|
|
'args': [doc2, 1, [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, 'F', 'O', 'O', { 'type': '/paragraph' }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 2 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting paragraph at end of paragraph moves insertion point forward': {
|
|
|
|
'args': [doc3, 4, [{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 5 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting paragraph into middle of paragraph splits paragraph': {
|
|
|
|
'args': [doc3, 2, [{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': '/paragraph' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }, { 'type': 'paragraph' }]
|
|
|
|
},
|
2013-06-05 10:47:47 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-04-26 18:41:27 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting paragraph into middle of list splits list': {
|
|
|
|
'args': [isolationDoc, 11, [{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 11 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': '/list' }, { 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }, { 'type': 'list', 'attributes': { 'style': 'bullet' } }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 235 }
|
2013-04-26 18:41:27 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting paragraph between table cells splits table, tableSection and tableRow': {
|
|
|
|
'args': [complexTableDoc, 40, [{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' }]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 40 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [
|
|
|
|
{ 'type': '/tableRow' }, { 'type': '/tableSection' }, { 'type': '/table' },
|
|
|
|
{ 'type': 'paragraph' }, 'B', 'A', 'R', { 'type': '/paragraph' },
|
2013-06-05 10:47:47 +00:00
|
|
|
{ 'type': 'table' }, { 'type': 'tableSection', 'attributes' : { 'style': 'body' } }, { 'type': 'tableRow' }
|
2013-04-26 18:41:27 +00:00
|
|
|
]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 13 }
|
2013-04-26 18:41:27 +00:00
|
|
|
]
|
2013-04-06 16:45:26 +00:00
|
|
|
}
|
|
|
|
// 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)
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2012-08-24 02:06:36 +00:00
|
|
|
for ( key in cases ) {
|
|
|
|
for ( i = 0; i < cases[key].ops.length; i++ ) {
|
|
|
|
if ( cases[key].ops[i].remove ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].remove, doc.getStore() );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
if ( cases[key].ops[i].insert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].insert, doc.getStore() );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromInsertion, cases );
|
2012-05-31 21:39:34 +00:00
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'newFromRemoval', function ( assert ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
var i, key, store,
|
|
|
|
doc = ve.dm.example.createExampleDocument( 'data' ),
|
|
|
|
alienDoc = ve.dm.example.createExampleDocument( 'alienData' ),
|
|
|
|
metaDoc = ve.dm.example.createExampleDocument( 'withMeta' ),
|
|
|
|
internalDoc = ve.dm.example.createExampleDocument( 'internalData' ),
|
2012-05-31 21:39:34 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'content in first element': {
|
|
|
|
'args': [doc, new ve.Range( 1, 3 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
'a',
|
|
|
|
['b', [ ve.dm.example.bold ]]
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 60 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'content in last element': {
|
|
|
|
'args': [doc, new ve.Range( 59, 60 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 59 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['m'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'first element': {
|
|
|
|
'args': [doc, new ve.Range( 0, 5 )],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
{ 'type': 'heading', 'attributes': { 'level': 1 } },
|
|
|
|
'a',
|
|
|
|
['b', [ ve.dm.example.bold ]],
|
|
|
|
['c', [ ve.dm.example.italic ]],
|
|
|
|
{ 'type': '/heading' }
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 58 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'middle element with image': {
|
|
|
|
'args': [doc, new ve.Range( 38, 42 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 38 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
'h',
|
2013-05-18 03:49:25 +00:00
|
|
|
{
|
|
|
|
'type': 'image',
|
|
|
|
'attributes': {
|
|
|
|
'src': ve.dm.example.imgSrc,
|
|
|
|
'width': null,
|
|
|
|
'height': null
|
|
|
|
},
|
2013-06-14 06:17:08 +00:00
|
|
|
'htmlAttributes': [ { 'values': { 'src': ve.dm.example.imgSrc } } ]
|
2013-05-18 03:49:25 +00:00
|
|
|
},
|
2013-04-06 16:45:26 +00:00
|
|
|
{ 'type': '/image' },
|
|
|
|
'i'
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 21 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'extra openings': {
|
|
|
|
'args': [doc, new ve.Range( 0, 7 )],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
{ 'type': 'heading', 'attributes': { 'level': 1 } },
|
|
|
|
'a',
|
|
|
|
['b', [ ve.dm.example.bold ]],
|
|
|
|
['c', [ ve.dm.example.italic ]],
|
|
|
|
{ 'type': '/heading' }
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 58 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'last element': {
|
|
|
|
'args': [doc, new ve.Range( 58, 61 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 58 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }, 'm', { 'type': '/paragraph' }],
|
|
|
|
'insert': []
|
2013-06-10 23:05:42 +00:00
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 2 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'extra closings': {
|
|
|
|
'args': [doc, new ve.Range( 31, 39 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 38 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['h'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 24 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'merge last two elements': {
|
|
|
|
'args': [doc, new ve.Range( 57, 59 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 57 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }, { 'type': 'paragraph' }],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 4 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'strip out of paragraph in tableCell and paragraph in listItem': {
|
|
|
|
'args': [doc, new ve.Range( 10, 16 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 10 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['d'],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 4 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['e'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 47 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'over first alien into paragraph': {
|
|
|
|
'args': [alienDoc, new ve.Range( 0, 4 )],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'alienBlock' }, { 'type': '/alienBlock' }],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['a'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 8 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'out of paragraph over last alien': {
|
|
|
|
'args': [alienDoc, new ve.Range( 6, 10 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['b'],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'alienBlock' }, { 'type': '/alienBlock' }],
|
|
|
|
'insert': []
|
2013-06-10 23:05:42 +00:00
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 2 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'merging two paragraphs inside definitionListItems': {
|
|
|
|
'args': [doc, new ve.Range( 47, 51 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 47 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }, { 'type': '/definitionListItem' }, { 'type': 'definitionListItem', 'attributes': { 'style': 'definition' } }, { 'type': 'paragraph' }],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 12 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'merging two paragraphs while also deleting some content': {
|
|
|
|
'args': [doc, new ve.Range( 56, 59 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 56 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['l', { 'type': '/paragraph' }, { 'type': 'paragraph' } ],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 4 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'removing from a heading into a paragraph': {
|
|
|
|
'args': [doc, new ve.Range( 2, 57 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData().slice( 2, 4 ),
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData().slice( 5, 55 ),
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['l'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 6 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'removing content from a paragraph in the middle': {
|
|
|
|
'args': [doc, new ve.Range( 56, 57 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 56 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['l'],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 6 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'removing content spanning metadata': {
|
|
|
|
'args': [metaDoc, new ve.Range( 7, 9 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['B', 'a'],
|
|
|
|
'insert': [],
|
|
|
|
'retainMetadata': 0,
|
|
|
|
'removeMetadata': metaDoc.getMetadata().slice( 7, 10 ),
|
|
|
|
'insertMetadata': ve.dm.MetaLinearData.static.merge( metaDoc.getMetadata().slice( 7, 10 ) )
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 4 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
2013-04-17 17:53:26 +00:00
|
|
|
},
|
|
|
|
'selection including internal nodes doesn\'t remove them': {
|
|
|
|
'args': [internalDoc, new ve.Range( 2, 24 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
'o', 'o',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 16 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'Q', 'u'
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 3 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'selection ending with internal nodes': {
|
|
|
|
'args': [internalDoc, new ve.Range( 2, 21 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
'o', 'o'
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-05 10:47:47 +00:00
|
|
|
{ 'type': 'retain', 'length': 23 }
|
2013-04-17 17:53:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'selection starting with internal nodes': {
|
|
|
|
'args': [internalDoc, new ve.Range( 5, 24 )],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 22 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [
|
|
|
|
'Q', 'u'
|
|
|
|
],
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-05 10:47:47 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-04-17 17:53:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'selection of just internal nodes returns a no-op transaction': {
|
|
|
|
'args': [internalDoc, new ve.Range( 5, 21 )],
|
|
|
|
'ops': [
|
2013-06-05 10:47:47 +00:00
|
|
|
{ 'type': 'retain', 'length': 27 }
|
2013-04-17 17:53:26 +00:00
|
|
|
]
|
2013-04-06 16:45:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2012-08-24 02:06:36 +00:00
|
|
|
for ( key in cases ) {
|
|
|
|
for ( i = 0; i < cases[key].ops.length; i++ ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
store = cases[key].args[0].getStore();
|
2012-08-24 02:06:36 +00:00
|
|
|
if ( cases[key].ops[i].remove ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].remove, store );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
if ( cases[key].ops[i].insert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].insert, store );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromRemoval, cases );
|
2012-05-31 21:39:34 +00:00
|
|
|
} );
|
|
|
|
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
QUnit.test( 'newFromDocumentInsertion', function ( assert ) {
|
|
|
|
var i, j, doc2, tx, actualStoreItems, expectedStoreItems,
|
|
|
|
doc = ve.dm.example.createExampleDocument( 'internalData' ),
|
|
|
|
complexDoc = ve.dm.example.createExampleDocument( 'complexInternalData' ),
|
|
|
|
nextIndex = doc.store.valueStore.length,
|
|
|
|
whee = [ { 'type': 'paragraph' }, 'W', 'h', 'e', 'e', { 'type': '/paragraph' } ],
|
|
|
|
wheeItem = [ { 'type': 'internalItem' } ].concat( whee ).concat( [ { 'type': '/internalItem' } ] ),
|
|
|
|
comment = { 'type': 'alienMeta', 'attributes': { 'domElements': $( '<!-- hello -->' ).get() } },
|
|
|
|
withReference = [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'B', 'a', 'r',
|
|
|
|
{ 'type': 'mwReference', 'attributes': {
|
|
|
|
'mw': {},
|
|
|
|
'about': '#mwt4',
|
|
|
|
'listIndex': 0,
|
|
|
|
'listGroup': 'mwReference/',
|
|
|
|
'listKey': null,
|
|
|
|
'refGroup': '',
|
|
|
|
'contentsUsed': true
|
|
|
|
} },
|
|
|
|
{ 'type': '/mwReference' },
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': 'internalList' },
|
|
|
|
{ 'type': 'internalItem' },
|
|
|
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
|
|
|
'B',
|
|
|
|
'a',
|
|
|
|
'z',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/internalItem' },
|
|
|
|
{ 'type': '/internalList' }
|
|
|
|
],
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'msg': 'simple insertion',
|
|
|
|
'doc': 'internalData',
|
|
|
|
'range': new ve.Range( 7, 12 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
// Change "Bar" to "Bazaar"
|
|
|
|
newDoc.commit( ve.dm.Transaction.newFromInsertion(
|
|
|
|
newDoc, 3, [ 'z', 'a', 'a' ]
|
|
|
|
) );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
2013-05-20 18:51:59 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
'remove': doc.getData( new ve.Range( 6, 20 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 6, 10 ) )
|
|
|
|
.concat( [ 'z', 'a', 'a' ] )
|
|
|
|
.concat( doc.getData( new ve.Range( 10, 20 ) ) )
|
2013-05-20 18:51:59 +00:00
|
|
|
},
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
{ 'type': 'retain', 'length': 7 }
|
2013-05-20 18:51:59 +00:00
|
|
|
]
|
|
|
|
},
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
{
|
|
|
|
'msg': 'simple annotation',
|
|
|
|
'doc': 'internalData',
|
|
|
|
'range': doc.getInternalList().getItemNode( 1 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
// Bold the first two characters
|
|
|
|
newDoc.commit( ve.dm.Transaction.newFromAnnotation(
|
|
|
|
newDoc, new ve.Range( 1, 3 ), 'set', ve.dm.example.bold
|
|
|
|
) );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
2013-05-20 18:51:59 +00:00
|
|
|
{
|
|
|
|
'type': 'replace',
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
'remove': doc.getData( new ve.Range( 6, 20 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 6, 15 ) )
|
|
|
|
.concat( [ [ doc.data.getData( 15 ), [ nextIndex ] ] ] )
|
|
|
|
.concat( [ [ doc.data.getData( 16 ), [ nextIndex ] ] ] )
|
|
|
|
.concat( doc.getData( new ve.Range( 17, 20 ) ) )
|
2013-05-20 18:51:59 +00:00
|
|
|
},
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
{ 'type': 'retain', 'length': 7 }
|
|
|
|
],
|
|
|
|
'expectedStoreItems': [
|
|
|
|
ve.dm.example.bold
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'insertion into internal list',
|
|
|
|
'doc': 'internalData',
|
|
|
|
'range': new ve.Range( 21, 27 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
var insertion = newDoc.internalList.getItemInsertion( 'test', 'whee', whee );
|
|
|
|
newDoc.commit( insertion.transaction );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData( new ve.Range( 6, 20 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 6, 20 ) ).concat( wheeItem )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData( new ve.Range( 21, 27 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 21, 27 ) )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'change in internal list',
|
|
|
|
'doc': 'internalData',
|
|
|
|
'range': new ve.Range( 21, 27 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
newDoc.commit( ve.dm.Transaction.newFromInsertion(
|
|
|
|
newDoc, 12, [ '!', '!', '!' ]
|
|
|
|
) );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData( new ve.Range( 6, 20 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 6, 11 ) )
|
|
|
|
.concat( [ '!', '!', '!' ] )
|
|
|
|
.concat( doc.getData( new ve.Range( 11, 20 ) ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData( new ve.Range( 21, 27 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 21, 27 ) )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'insertion into internal list from slice within internal list',
|
|
|
|
'doc': 'internalData',
|
|
|
|
'range': new ve.Range( 7, 12 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
var insertion = newDoc.internalList.getItemInsertion( 'test', 'whee', whee );
|
|
|
|
newDoc.commit( insertion.transaction );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': doc.getData( new ve.Range( 6, 20 ) ),
|
|
|
|
'insert': doc.getData( new ve.Range( 6, 20 ) ).concat( wheeItem )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'metadata insertion',
|
|
|
|
'doc': 'complexInternalData',
|
|
|
|
'range': new ve.Range( 0, 7 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
newDoc.commit( ve.dm.Transaction.newFromMetadataInsertion(
|
|
|
|
newDoc, 5, 0, [ comment ]
|
|
|
|
) );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': complexDoc.getData( new ve.Range( 0, 7 ) ),
|
|
|
|
'insert': complexDoc.getData( new ve.Range( 0, 7 ) ),
|
|
|
|
'retainMetadata': 0,
|
|
|
|
'removeMetadata': complexDoc.getMetadata( new ve.Range( 0, 8 ) ),
|
|
|
|
'insertMetadata': complexDoc.getMetadata( new ve.Range( 0, 5 ) )
|
|
|
|
.concat( [ [ comment ] ] )
|
|
|
|
.concat( complexDoc.getMetadata( new ve.Range( 6, 8 ) ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': complexDoc.getData( new ve.Range( 8, 32 ) ),
|
|
|
|
'insert': complexDoc.getData( new ve.Range( 8, 32 ) ),
|
|
|
|
'retainMetadata': 5,
|
|
|
|
'removeMetadata': complexDoc.getMetadata( new ve.Range( 13, 33 ) ),
|
|
|
|
'insertMetadata': complexDoc.getMetadata( new ve.Range( 13, 33 ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'metadata removal',
|
|
|
|
'doc': 'complexInternalData',
|
|
|
|
'range': new ve.Range( 24, 31 ),
|
|
|
|
'modify': function ( newDoc ) {
|
|
|
|
newDoc.commit( ve.dm.Transaction.newFromMetadataRemoval(
|
|
|
|
newDoc, 6, new ve.Range( 0, 1 )
|
|
|
|
) );
|
|
|
|
},
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 8 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': complexDoc.getData( new ve.Range( 8, 32 ) ),
|
|
|
|
'insert': complexDoc.getData( new ve.Range( 8, 32 ) ),
|
|
|
|
'retainMetadata': 5,
|
|
|
|
'removeMetadata': complexDoc.getMetadata( new ve.Range( 13, 33 ) ),
|
|
|
|
'insertMetadata': complexDoc.getMetadata( new ve.Range( 13, 30 ) )
|
|
|
|
.concat( [ [] ] )
|
|
|
|
.concat( complexDoc.getMetadata( new ve.Range( 31, 33 ) ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'msg': 'inserting a brand new document; internal lists are merged and items renumbered',
|
|
|
|
'doc': 'complexInternalData',
|
|
|
|
'range': new ve.Range( 7, 7 ),
|
|
|
|
'newDocData': withReference,
|
|
|
|
'expectedOps': [
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': withReference.slice( 0, 4 )
|
|
|
|
// Renumber listIndex from 0 to 2
|
|
|
|
.concat( [ ve.extendObject( true, {}, withReference[4],
|
|
|
|
{ 'attributes': { 'listIndex': 2 } } ) ] )
|
|
|
|
.concat( withReference.slice( 5, 7 ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': complexDoc.getData( new ve.Range( 8, 32 ) ),
|
|
|
|
'insert': complexDoc.getData( new ve.Range( 8, 32 ) )
|
|
|
|
.concat( withReference.slice( 8, 15 ) ),
|
|
|
|
'retainMetadata': 5,
|
|
|
|
'removeMetadata': complexDoc.getMetadata( new ve.Range( 13, 33 ) ),
|
|
|
|
'insertMetadata': complexDoc.getMetadata( new ve.Range( 13, 32 ) )
|
|
|
|
.concat( new Array( 7 ) )
|
|
|
|
.concat( complexDoc.getMetadata( new ve.Range( 32, 33 ) ) )
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 }
|
2013-05-20 18:51:59 +00:00
|
|
|
]
|
|
|
|
}
|
ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.
This makes editing document slices simple:
slicedDoc = doc.getDocumentSlice( captionNode );
// Edit slicedDoc using a surface
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
surface.change( tx );
Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.
This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.
ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
than [].
ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
the new one, and also store the length of the internal list. This
allows us to figure out which internal list items the two documents
have in common when we insert the modified slice back into the main
document.
* In getMetadataReplace, optionally take the inserted metadata as a
parameter, to allow for operations that insert both data and metadata.
Per Ed's review, rewrite this function to return null rather than {}
if no metadata needs to be replaced.
ve.dm.InternalList:
* Add method to merge two internal lists
ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.
Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-05-22 15:06:25 +00:00
|
|
|
];
|
|
|
|
QUnit.expect( 2 * cases.length );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
|
|
doc = ve.dm.example.createExampleDocument( cases[i].doc );
|
|
|
|
if ( cases[i].newDocData ) {
|
|
|
|
doc2 = new ve.dm.Document( cases[i].newDocData );
|
|
|
|
} else {
|
|
|
|
doc2 = doc.getDocumentSlice( cases[i].range );
|
|
|
|
cases[i].modify( doc2 );
|
|
|
|
}
|
|
|
|
tx = ve.dm.Transaction.newFromDocumentInsertion( doc, cases[i].range, doc2 );
|
|
|
|
assert.deepEqualWithDomElements( tx.getOperations(), cases[i].expectedOps, cases[i].msg + ': transaction' );
|
|
|
|
|
|
|
|
actualStoreItems = [];
|
|
|
|
expectedStoreItems = cases[i].expectedStoreItems || [];
|
|
|
|
for ( j = 0; j < expectedStoreItems.length; j++ ) {
|
|
|
|
actualStoreItems[j] = doc.store.value( doc.store.indexOfHash(
|
|
|
|
ve.getHash( expectedStoreItems[j] )
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
assert.deepEqual( actualStoreItems, expectedStoreItems, cases[i].msg + ': store items' );
|
|
|
|
}
|
2013-05-20 18:51:59 +00:00
|
|
|
} );
|
2013-06-14 19:07:55 +00:00
|
|
|
QUnit.test( 'newFromAttributeChanges', function ( assert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
var doc = ve.dm.example.createExampleDocument(),
|
2012-05-21 19:20:51 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'first element': {
|
2013-06-14 19:07:55 +00:00
|
|
|
'args': [doc, 0, { 'level': 2 }],
|
2013-04-06 16:45:26 +00:00
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'level',
|
|
|
|
'from': 1,
|
|
|
|
'to': 2
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 63 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'middle element': {
|
2013-06-14 19:07:55 +00:00
|
|
|
'args': [doc, 17, { 'style': 'number'} ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 17 },
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'style',
|
|
|
|
'from': 'bullet',
|
|
|
|
'to': 'number'
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 46 }
|
2013-06-14 19:07:55 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'multiple attributes': {
|
|
|
|
'args': [doc, 17, { 'style': 'number', 'level': 1 } ],
|
2013-04-06 16:45:26 +00:00
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 17 },
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'style',
|
|
|
|
'from': 'bullet',
|
|
|
|
'to': 'number'
|
|
|
|
},
|
2013-06-14 19:07:55 +00:00
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'level',
|
|
|
|
'from': undefined,
|
|
|
|
'to': 1
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 46 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'non-element': {
|
2013-06-14 19:07:55 +00:00
|
|
|
'args': [doc, 1, { 'level': 2 }],
|
2013-04-06 16:45:26 +00:00
|
|
|
'exception': Error
|
|
|
|
},
|
|
|
|
'closing element': {
|
2013-06-14 19:07:55 +00:00
|
|
|
'args': [doc, 4, { 'level': 2 }],
|
2013-04-06 16:45:26 +00:00
|
|
|
'exception': Error
|
|
|
|
}
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2013-06-14 19:07:55 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromAttributeChanges, cases );
|
2013-04-06 16:45:26 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'newFromAnnotation', function ( assert ) {
|
|
|
|
var bold = ve.dm.example.createAnnotation( ve.dm.example.bold ),
|
|
|
|
doc = ve.dm.example.createExampleDocument(),
|
|
|
|
cases = {
|
|
|
|
'over plain text': {
|
|
|
|
'args': [doc, new ve.Range( 1, 2 ), 'set', bold],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 61 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'over annotated text': {
|
|
|
|
'args': [doc, new ve.Range( 1, 4 ), 'set', bold],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 59 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'over elements': {
|
|
|
|
'args': [doc, new ve.Range( 4, 9 ), 'set', bold],
|
|
|
|
'ops': [
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 63 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'over elements and content': {
|
|
|
|
'args': [doc, new ve.Range( 3, 11 ), 'set', bold],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 6 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': bold
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 52 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromAnnotation, cases );
|
2012-05-21 19:20:51 +00:00
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'newFromContentBranchConversion', function ( assert ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
var i, key, store,
|
|
|
|
doc = ve.dm.example.createExampleDocument(),
|
2013-04-26 23:49:43 +00:00
|
|
|
doc2 = ve.dm.example.createExampleDocument( 'inlineAtEdges' ),
|
2012-06-11 22:58:29 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'range inside a heading, convert to paragraph': {
|
|
|
|
'args': [doc, new ve.Range( 1, 2 ), 'paragraph'],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'heading', 'attributes': { 'level': 1 } }],
|
|
|
|
'insert': [{ 'type': 'paragraph' }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/heading' }],
|
|
|
|
'insert': [{ 'type': '/paragraph' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 58 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'range around 2 paragraphs, convert to preformatted': {
|
|
|
|
'args': [doc, new ve.Range( 50, 58 ), 'preformatted'],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 50 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'preformatted' }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/preformatted' }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'preformatted' }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/preformatted' }]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 5 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
2013-04-26 23:49:43 +00:00
|
|
|
},
|
|
|
|
'zero-length range before inline node at the start': {
|
|
|
|
'args': [doc2, new ve.Range( 1, 1 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'zero-length range inside inline node at the start': {
|
|
|
|
'args': [doc2, new ve.Range( 2, 2 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'zero-length range after inline node at the start': {
|
|
|
|
'args': [doc2, new ve.Range( 3, 3 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'zero-length range before inline node at the end': {
|
|
|
|
'args': [doc2, new ve.Range( 6, 6 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'zero-length range inside inline node at the end': {
|
|
|
|
'args': [doc2, new ve.Range( 7, 7 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'zero-length range after inline node at the end': {
|
|
|
|
'args': [doc2, new ve.Range( 8, 8 ), 'heading', { 'level': 2 }],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }],
|
|
|
|
'insert': [{ 'type': 'heading', 'attributes': { 'level': 2 } }]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 7 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': '/paragraph' }],
|
|
|
|
'insert': [{ 'type': '/heading' }]
|
2013-06-05 10:47:47 +00:00
|
|
|
}
|
2013-04-26 23:49:43 +00:00
|
|
|
]
|
2013-04-06 16:45:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2012-08-24 02:06:36 +00:00
|
|
|
for ( key in cases ) {
|
|
|
|
for ( i = 0; i < cases[key].ops.length; i++ ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
store = cases[key].args[0].getStore();
|
2012-08-24 02:06:36 +00:00
|
|
|
if ( cases[key].ops[i].remove ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].remove, store );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
if ( cases[key].ops[i].insert ) {
|
2013-04-17 17:53:26 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].insert, store );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runConstructorTests(
|
|
|
|
assert,
|
|
|
|
ve.dm.Transaction.newFromContentBranchConversion,
|
|
|
|
cases
|
2012-06-11 22:58:29 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'newFromWrap', function ( assert ) {
|
2012-10-25 20:06:07 +00:00
|
|
|
var i, key,
|
2013-03-20 22:35:05 +00:00
|
|
|
doc = ve.dm.example.createExampleDocument(),
|
2012-06-13 23:17:23 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'changes a heading to a paragraph': {
|
|
|
|
'args': [doc, new ve.Range( 1, 4 ), [ { 'type': 'heading', 'attributes': { 'level': 1 } } ], [ { 'type': 'paragraph' } ], [], []],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'replace', 'remove': [ { 'type': 'heading', 'attributes': { 'level': 1 } } ], 'insert': [ { 'type': 'paragraph' } ] },
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{ 'type': 'replace', 'remove': [ { 'type': '/heading' } ], 'insert': [ { 'type': '/paragraph' } ] },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 58 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'unwraps a list': {
|
|
|
|
'args': [doc, new ve.Range( 13, 25 ), [ { 'type': 'list' } ], [], [ { 'type': 'listItem' } ], []],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 12 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [ { 'type': 'list', 'attributes': { 'style': 'bullet' } }, { 'type': 'listItem' } ],
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 10 },
|
|
|
|
{ 'type': 'replace', 'remove': [ { 'type': '/listItem' }, { 'type': '/list' } ], 'insert': [] },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 37 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'replaces a table with a list': {
|
|
|
|
'args': [doc, new ve.Range( 9, 33 ), [ { 'type': 'table' }, { 'type': 'tableSection', 'attributes': { 'style': 'body' } }, { 'type': 'tableRow' }, { 'type': 'tableCell' } ], [ { 'type': 'list' }, { 'type': 'listItem' } ], [], []],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 5 },
|
|
|
|
{ 'type': 'replace', 'remove': [ { 'type': 'table' }, { 'type': 'tableSection', 'attributes': { 'style': 'body' } }, { 'type': 'tableRow' }, { 'type': 'tableCell', 'attributes': { 'style': 'data' } } ], 'insert': [ { 'type': 'list' }, { 'type': 'listItem' } ] },
|
|
|
|
{ 'type': 'retain', 'length': 24 },
|
|
|
|
{ 'type': 'replace', 'remove': [ { 'type': '/tableCell' }, { 'type': '/tableRow' }, { 'type': '/tableSection' }, { 'type': '/table' } ], 'insert': [ { 'type': '/listItem' }, { 'type': '/list' } ] },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 26 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'wraps two adjacent paragraphs in a list': {
|
|
|
|
'args': [doc, new ve.Range( 55, 61 ), [], [ { 'type': 'list', 'attributes': { 'style': 'number' } } ], [], [ { 'type': 'listItem' } ]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 55 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [ { 'type': 'list', 'attributes': { 'style': 'number' } }, { 'type': 'listItem' } ]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{ 'type': 'replace', 'remove': [], 'insert': [ { 'type': '/listItem' }, { 'type': 'listItem' } ] },
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'replace', 'remove': [], 'insert': [ { 'type': '/listItem' }, { 'type': '/list' } ] },
|
|
|
|
{ 'type': 'retain', 'length': 2 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'wraps two adjacent paragraphs in a definitionList': {
|
|
|
|
'args': [doc, new ve.Range( 55, 61 ), [], [ { 'type': 'definitionList' } ], [], [ { 'type': 'definitionListItem', 'attributes': { 'style': 'term' } } ]],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 55 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [ { 'type': 'definitionList' }, { 'type': 'definitionListItem', 'attributes': { 'style': 'term' } } ]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [ { 'type': '/definitionListItem' }, { 'type': 'definitionListItem', 'attributes': { 'style': 'term' } } ]
|
|
|
|
},
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'replace', 'remove': [], 'insert': [ { 'type': '/definitionListItem' }, { 'type': '/definitionList' } ] },
|
|
|
|
{ 'type': 'retain', 'length': 2 }
|
2013-04-06 16:45:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'checks integrity of unwrapOuter parameter': {
|
|
|
|
'args': [doc, new ve.Range( 13, 32 ), [ { 'type': 'table' } ], [], [], []],
|
|
|
|
'exception': Error
|
|
|
|
},
|
|
|
|
'checks integrity of unwrapEach parameter': {
|
|
|
|
'args': [doc, new ve.Range( 13, 32 ), [ { 'type': 'list' } ], [], [ { 'type': 'paragraph' } ], []],
|
|
|
|
'exception': Error
|
|
|
|
},
|
|
|
|
'checks that unwrapOuter fits before the range': {
|
|
|
|
'args': [doc, new ve.Range( 1, 4 ), [ { 'type': 'listItem' }, { 'type': 'paragraph' } ], [], [], []],
|
|
|
|
'exception': Error
|
|
|
|
}
|
|
|
|
};
|
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2012-08-24 02:06:36 +00:00
|
|
|
for ( key in cases ) {
|
|
|
|
for ( i = 0; cases[key].ops && i < cases[key].ops.length; i++ ) {
|
|
|
|
if ( cases[key].ops[i].remove ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].remove, doc.getStore() );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
if ( cases[key].ops[i].insert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
ve.dm.example.preprocessAnnotations( cases[key].ops[i].insert, doc.getStore() );
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runConstructorTests(
|
|
|
|
assert,
|
|
|
|
ve.dm.Transaction.newFromWrap,
|
|
|
|
cases
|
2012-06-13 23:17:23 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
QUnit.test( 'translateOffset', function ( assert ) {
|
2013-04-06 16:45:26 +00:00
|
|
|
var mapping, offset, expected,
|
2013-06-24 17:51:59 +00:00
|
|
|
doc = new ve.dm.Document( '-----defg---h--'.split( '' ) ),
|
2013-04-06 16:45:26 +00:00
|
|
|
tx = new ve.dm.Transaction();
|
|
|
|
|
|
|
|
tx.pushReplace( doc, 0, 0, ['a','b','c'] );
|
2013-04-03 03:00:31 +00:00
|
|
|
tx.pushRetain( 5 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 5, 4, [] );
|
2012-06-20 21:37:13 +00:00
|
|
|
tx.pushRetain( 2 );
|
|
|
|
tx.pushStartAnnotating( 'set', { 'type': 'textStyle/bold' } );
|
|
|
|
tx.pushRetain( 1 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 12, 1, ['i', 'j', 'k', 'l', 'm'] );
|
2012-08-30 22:26:43 +00:00
|
|
|
tx.pushRetain( 2 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 15, 0, ['n', 'o', 'p'] );
|
2012-06-20 21:37:13 +00:00
|
|
|
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
mapping = {
|
2013-02-23 01:13:43 +00:00
|
|
|
0: [0, 3],
|
2012-06-20 21:37:13 +00:00
|
|
|
1: 4,
|
|
|
|
2: 5,
|
|
|
|
3: 6,
|
|
|
|
4: 7,
|
|
|
|
5: 8,
|
2012-06-21 07:08:23 +00:00
|
|
|
6: 8,
|
|
|
|
7: 8,
|
|
|
|
8: 8,
|
2012-06-20 21:37:13 +00:00
|
|
|
9: 8,
|
|
|
|
10: 9,
|
|
|
|
11: 10,
|
2013-02-22 20:01:02 +00:00
|
|
|
12: 11,
|
2013-02-23 01:13:43 +00:00
|
|
|
13: [12, 16],
|
2012-08-30 22:26:43 +00:00
|
|
|
14: 17,
|
2013-02-23 01:13:43 +00:00
|
|
|
15: [18, 21],
|
2012-08-30 22:26:43 +00:00
|
|
|
16: 22
|
2012-06-20 21:37:13 +00:00
|
|
|
};
|
2013-06-24 17:51:59 +00:00
|
|
|
QUnit.expect( 2*ve.getObjectKeys( mapping ).length );
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
for ( offset in mapping ) {
|
2013-02-23 01:13:43 +00:00
|
|
|
expected = ve.isArray( mapping[offset] ) ? mapping[offset] : [ mapping[offset], mapping[offset] ];
|
|
|
|
assert.strictEqual( tx.translateOffset( Number( offset ) ), expected[1], offset );
|
|
|
|
assert.strictEqual( tx.translateOffset( Number( offset ), false, true ), expected[0], offset + ' (excludeInsertion)' );
|
2012-06-20 21:37:13 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2012-10-10 18:08:33 +00:00
|
|
|
QUnit.test( 'translateOffsetReversed', function ( assert ) {
|
2013-04-06 16:45:26 +00:00
|
|
|
var mapping, offset, expected,
|
2013-06-24 17:51:59 +00:00
|
|
|
doc = new ve.dm.Document( '-----defg---h--'.split( '' ) ),
|
2013-04-06 16:45:26 +00:00
|
|
|
tx = new ve.dm.Transaction();
|
|
|
|
|
|
|
|
tx.pushReplace( doc, 0, 0, ['a','b','c'] );
|
2013-04-03 03:00:31 +00:00
|
|
|
tx.pushRetain( 5 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 5, 4, [] );
|
2012-10-10 18:08:33 +00:00
|
|
|
tx.pushRetain( 2 );
|
|
|
|
tx.pushStartAnnotating( 'set', { 'type': 'textStyle/bold' } );
|
|
|
|
tx.pushRetain( 1 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 12, 1, ['i', 'j', 'k', 'l', 'm'] );
|
2012-10-10 18:08:33 +00:00
|
|
|
tx.pushRetain( 2 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 15, 0, ['n', 'o', 'p'] );
|
2012-10-10 18:08:33 +00:00
|
|
|
|
|
|
|
mapping = {
|
|
|
|
0: 0,
|
|
|
|
1: 0,
|
|
|
|
2: 0,
|
|
|
|
3: 0,
|
|
|
|
4: 1,
|
|
|
|
5: 2,
|
|
|
|
6: 3,
|
|
|
|
7: 4,
|
2013-02-23 01:13:43 +00:00
|
|
|
8: [5, 9],
|
2012-10-10 18:08:33 +00:00
|
|
|
9: 10,
|
|
|
|
10: 11,
|
2013-02-22 20:01:02 +00:00
|
|
|
11: 12,
|
2012-10-10 18:08:33 +00:00
|
|
|
12: 13,
|
|
|
|
13: 13,
|
|
|
|
14: 13,
|
|
|
|
15: 13,
|
2013-02-23 01:13:43 +00:00
|
|
|
16: 13,
|
|
|
|
17: 14,
|
|
|
|
18: 15,
|
|
|
|
19: 15,
|
|
|
|
20: 15,
|
|
|
|
21: 15,
|
|
|
|
22: 16
|
2012-10-10 18:08:33 +00:00
|
|
|
};
|
2013-06-24 17:51:59 +00:00
|
|
|
QUnit.expect( 2*ve.getObjectKeys( mapping ).length );
|
2012-10-10 18:08:33 +00:00
|
|
|
for ( offset in mapping ) {
|
2013-02-23 01:13:43 +00:00
|
|
|
expected = ve.isArray( mapping[offset] ) ? mapping[offset] : [ mapping[offset], mapping[offset] ];
|
|
|
|
assert.strictEqual( tx.translateOffset( Number( offset ), true ), expected[1], offset );
|
|
|
|
assert.strictEqual( tx.translateOffset( Number( offset ), true, true ), expected[0], offset + ' (excludeInsertion)' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'translateRange', function ( assert ) {
|
2013-04-06 16:45:26 +00:00
|
|
|
var i, cases,
|
|
|
|
doc = ve.dm.example.createExampleDocument(),
|
|
|
|
tx = new ve.dm.Transaction();
|
2013-02-23 01:13:43 +00:00
|
|
|
tx.pushRetain( 55 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 55, 0, [ { 'type': 'list', 'attributes': { 'style': 'number' } } ] );
|
|
|
|
tx.pushReplace( doc, 55, 0, [ { 'type': 'listItem' } ] );
|
2013-02-23 01:13:43 +00:00
|
|
|
tx.pushRetain( 3 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 58, 0, [ { 'type': '/listItem' } ] );
|
|
|
|
tx.pushReplace( doc, 58, 0, [ { 'type': 'listItem' } ] );
|
2013-02-23 01:13:43 +00:00
|
|
|
tx.pushRetain( 3 );
|
2013-04-06 16:45:26 +00:00
|
|
|
tx.pushReplace( doc, 61, 0, [ { 'type': '/listItem' } ] );
|
|
|
|
tx.pushReplace( doc, 61, 0, [ { 'type': '/list' } ] );
|
2013-02-23 01:13:43 +00:00
|
|
|
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'before': new ve.Range( 55, 61 ),
|
2013-04-23 16:05:48 +00:00
|
|
|
'after': new ve.Range( 55, 67 ),
|
|
|
|
'msg': 'Wrapped range is translated to outer range'
|
2013-02-23 01:13:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'before': new ve.Range( 54, 62 ),
|
|
|
|
'after': new ve.Range( 54, 68 ),
|
|
|
|
'msg': 'Wrapped range plus one each side is translated to outer range plus one each side'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'before': new ve.Range( 54, 61 ),
|
2013-04-23 16:05:48 +00:00
|
|
|
'after': new ve.Range( 54, 67 ),
|
2013-02-23 01:13:43 +00:00
|
|
|
'msg': 'Wrapped range plus one on the left'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'before': new ve.Range( 55, 62 ),
|
2013-04-23 16:05:48 +00:00
|
|
|
'after': new ve.Range( 55, 68 ),
|
2013-02-23 01:13:43 +00:00
|
|
|
'msg': 'wrapped range plus one on the right'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
QUnit.expect( cases.length * 2 );
|
|
|
|
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
|
|
assert.deepEqual( tx.translateRange( cases[i].before ), cases[i].after, cases[i].msg );
|
|
|
|
assert.deepEqual( tx.translateRange( cases[i].before.flip() ), cases[i].after.flip(), cases[i].msg + ' (reversed)' );
|
2012-10-10 18:08:33 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2012-10-25 20:06:07 +00:00
|
|
|
QUnit.test( 'pushRetain', 4, function ( assert ) {
|
2012-05-11 23:49:31 +00:00
|
|
|
var cases = {
|
|
|
|
'retain': {
|
|
|
|
'calls': [['pushRetain', 5]],
|
|
|
|
'ops': [{ 'type': 'retain', 'length': 5 }],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'multiple retain': {
|
|
|
|
'calls': [['pushRetain', 5], ['pushRetain', 3]],
|
|
|
|
'ops': [{ 'type': 'retain', 'length': 8 }],
|
|
|
|
'diff': 0
|
2012-05-31 21:39:34 +00:00
|
|
|
}
|
|
|
|
};
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runBuilderTests( assert, cases );
|
2012-05-31 21:39:34 +00:00
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'pushReplace', function ( assert ) {
|
|
|
|
var doc = new ve.dm.Document( [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }] ),
|
|
|
|
doc2 = new ve.dm.Document( [{ 'type': 'paragraph' }, 'a', 'b', 'c', 'g', 'h', 'i', { 'type': '/paragraph' }] ),
|
2013-03-20 22:35:05 +00:00
|
|
|
cases = {
|
2013-04-06 16:45:26 +00:00
|
|
|
'insert': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc, 0, 0, [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }]]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 5
|
|
|
|
},
|
|
|
|
'multiple insert': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc, 0, 0, [{ 'type': 'paragraph' }, 'a', 'b']],
|
|
|
|
['pushReplace', doc, 0, 0, ['c', { 'type': '/paragraph' }]]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 5
|
|
|
|
},
|
|
|
|
'insert and retain': {
|
|
|
|
'calls': [
|
|
|
|
['pushRetain', 1],
|
|
|
|
['pushReplace', doc, 0, 0, ['a', 'b', 'c']]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{ 'type': 'replace', 'remove': [], 'insert': ['a', 'b', 'c'] }
|
|
|
|
],
|
|
|
|
'diff': 3
|
|
|
|
},
|
|
|
|
'remove': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc, 0, 5, []]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }],
|
|
|
|
'insert': []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': -5
|
|
|
|
},
|
|
|
|
'multiple remove': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc, 0, 3, []],
|
|
|
|
['pushReplace', doc, 3, 2, []]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': [{ 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' }],
|
|
|
|
'insert': []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': -5
|
|
|
|
},
|
|
|
|
'retain and remove': {
|
|
|
|
'calls': [
|
|
|
|
['pushRetain', 1],
|
|
|
|
['pushReplace', doc, 1, 3, []]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 1 },
|
|
|
|
{ 'type': 'replace', 'remove': ['a', 'b', 'c'], 'insert': [] }
|
|
|
|
],
|
|
|
|
'diff': -3
|
|
|
|
},
|
|
|
|
'replace': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc, 1, 3, ['d', 'e', 'f']]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['a', 'b', 'c'],
|
|
|
|
'insert': ['d', 'e', 'f']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'multiple replace': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplace', doc2, 1, 3, ['d', 'e', 'f']],
|
|
|
|
['pushReplace', doc2, 4, 3, ['j', 'k', 'l']]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'replace',
|
|
|
|
'remove': ['a', 'b', 'c', 'g', 'h', 'i'],
|
|
|
|
'insert': ['d', 'e', 'f', 'j', 'k', 'l']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
2012-08-24 02:06:36 +00:00
|
|
|
}
|
2013-04-06 16:45:26 +00:00
|
|
|
};
|
|
|
|
QUnit.expect( 2*ve.getObjectKeys( cases ).length );
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runBuilderTests( assert, cases );
|
2012-05-31 21:39:34 +00:00
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'pushReplaceElementAttribute', function ( assert ) {
|
2012-05-31 21:39:34 +00:00
|
|
|
var cases = {
|
2012-05-11 23:49:31 +00:00
|
|
|
'replace element attribute': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplaceElementAttribute', 'style', 'bullet', 'number']
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'style',
|
|
|
|
'from': 'bullet',
|
|
|
|
'to': 'number'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'replace multiple element attributes': {
|
|
|
|
'calls': [
|
|
|
|
['pushReplaceElementAttribute', 'style', 'bullet', 'number'],
|
2012-05-21 19:20:51 +00:00
|
|
|
['pushReplaceElementAttribute', 'level', 1, 2]
|
2012-05-11 23:49:31 +00:00
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'style',
|
|
|
|
'from': 'bullet',
|
|
|
|
'to': 'number'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'attribute',
|
|
|
|
'key': 'level',
|
2012-05-21 19:20:51 +00:00
|
|
|
'from': 1,
|
|
|
|
'to': 2
|
2012-05-11 23:49:31 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
2012-05-31 21:39:34 +00:00
|
|
|
}
|
|
|
|
};
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.expect( 2*ve.getObjectKeys( cases ).length );
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runBuilderTests( assert, cases );
|
2012-05-31 21:39:34 +00:00
|
|
|
} );
|
|
|
|
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.test( 'push*Annotating', function ( assert ) {
|
2012-05-31 21:39:34 +00:00
|
|
|
var cases = {
|
2012-05-11 23:49:31 +00:00
|
|
|
'start annotating': {
|
|
|
|
'calls': [
|
|
|
|
['pushStartAnnotating', 'set', { 'type': 'textStyle/bold' }]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': { 'type': 'textStyle/bold' }
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'stop annotating': {
|
|
|
|
'calls': [
|
|
|
|
['pushStopAnnotating', 'set', { 'type': 'textStyle/bold' }]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': { 'type': 'textStyle/bold' }
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'start multiple annotations': {
|
|
|
|
'calls': [
|
|
|
|
['pushStartAnnotating', 'set', { 'type': 'textStyle/bold' }],
|
|
|
|
['pushStartAnnotating', 'set', { 'type': 'textStyle/italic' }]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': { 'type': 'textStyle/bold' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'start',
|
|
|
|
'annotation': { 'type': 'textStyle/italic' }
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
},
|
|
|
|
'stop multiple annotations': {
|
|
|
|
'calls': [
|
|
|
|
['pushStopAnnotating', 'set', { 'type': 'textStyle/bold' }],
|
|
|
|
['pushStopAnnotating', 'set', { 'type': 'textStyle/italic' }]
|
|
|
|
],
|
|
|
|
'ops': [
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': { 'type': 'textStyle/bold' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'annotate',
|
|
|
|
'method': 'set',
|
|
|
|
'bias': 'stop',
|
|
|
|
'annotation': { 'type': 'textStyle/italic' }
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'diff': 0
|
|
|
|
}
|
|
|
|
};
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.expect( 2*ve.getObjectKeys( cases ).length );
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
runBuilderTests( assert, cases );
|
2012-04-20 01:11:08 +00:00
|
|
|
} );
|
2013-02-14 23:21:53 +00:00
|
|
|
|
2013-05-06 11:34:32 +00:00
|
|
|
QUnit.test( 'newFromMetadataInsertion', function ( assert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
var doc = ve.dm.example.createExampleDocument( 'withMeta' ),
|
2013-02-14 23:21:53 +00:00
|
|
|
element = {
|
2013-02-21 23:01:04 +00:00
|
|
|
'type': 'alienMeta',
|
2013-02-14 23:21:53 +00:00
|
|
|
'attributes': {
|
|
|
|
'style': 'comment',
|
|
|
|
'text': ' inline '
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cases = {
|
|
|
|
'inserting metadata element into existing element list': {
|
|
|
|
'args': [ doc, 11, 2, [ element ] ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 11 },
|
|
|
|
{ 'type': 'retainMetadata', 'length': 2 },
|
|
|
|
{
|
|
|
|
'type': 'replaceMetadata',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [ element ]
|
|
|
|
},
|
|
|
|
{ 'type': 'retainMetadata', 'length': 2 },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-02-14 23:21:53 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'inserting metadata element into empty list': {
|
|
|
|
'args': [ doc, 3, 0, [ element ] ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 3 },
|
|
|
|
{
|
|
|
|
'type': 'replaceMetadata',
|
|
|
|
'remove': [],
|
|
|
|
'insert': [ element ]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 11 }
|
2013-02-14 23:21:53 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2013-02-14 23:21:53 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromMetadataInsertion, cases );
|
|
|
|
} );
|
|
|
|
|
2013-05-06 11:34:32 +00:00
|
|
|
QUnit.test( 'newFromMetadataRemoval', function ( assert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
var doc = ve.dm.example.createExampleDocument( 'withMeta' ),
|
2013-02-14 23:21:53 +00:00
|
|
|
allElements = ve.dm.example.withMetaMetaData[11],
|
|
|
|
someElements = allElements.slice( 1, 3 ),
|
|
|
|
cases = {
|
|
|
|
'removing all metadata elements from metadata list': {
|
|
|
|
'args': [ doc, 11, new ve.Range( 0, 4 ) ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 11 },
|
|
|
|
{
|
|
|
|
'type': 'replaceMetadata',
|
|
|
|
'remove': allElements,
|
|
|
|
'insert': []
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-02-14 23:21:53 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'removing some metadata elements from metadata list': {
|
|
|
|
'args': [ doc, 11, new ve.Range( 1, 3 ) ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 11 },
|
|
|
|
{ 'type': 'retainMetadata', 'length': 1 },
|
|
|
|
{
|
|
|
|
'type': 'replaceMetadata',
|
|
|
|
'remove': someElements,
|
|
|
|
'insert': []
|
|
|
|
},
|
|
|
|
{ 'type': 'retainMetadata', 'length': 1 },
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-02-14 23:21:53 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'checks metadata at offset is non-empty': {
|
|
|
|
'args': [ doc, 5, new ve.Range( 1, 3 ) ],
|
|
|
|
'exception': Error
|
|
|
|
},
|
|
|
|
'checks range is valid for metadata at offset': {
|
|
|
|
'args': [ doc, 11, new ve.Range( 1, 5 ) ],
|
|
|
|
'exception': Error
|
|
|
|
}
|
|
|
|
};
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2013-02-14 23:21:53 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromMetadataRemoval, cases );
|
|
|
|
} );
|
|
|
|
|
2013-05-06 11:34:32 +00:00
|
|
|
QUnit.test( 'newFromMetadataElementReplacement', function ( assert ) {
|
2013-03-20 22:35:05 +00:00
|
|
|
var doc = ve.dm.example.createExampleDocument( 'withMeta' ),
|
2013-02-14 23:21:53 +00:00
|
|
|
newElement = {
|
2013-02-21 23:01:04 +00:00
|
|
|
'type': 'alienMeta',
|
2013-02-14 23:21:53 +00:00
|
|
|
'attributes': {
|
|
|
|
'style': 'comment',
|
|
|
|
'text': ' inline '
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oldElement = ve.dm.example.withMetaMetaData[11][3],
|
|
|
|
cases = {
|
|
|
|
'replacing metadata at end of list': {
|
|
|
|
'args': [ doc, 11, 3, newElement ],
|
|
|
|
'ops': [
|
|
|
|
{ 'type': 'retain', 'length': 11 },
|
|
|
|
{ 'type': 'retainMetadata', 'length': 3 },
|
|
|
|
{
|
|
|
|
'type': 'replaceMetadata',
|
|
|
|
'remove': [ oldElement ],
|
|
|
|
'insert': [ newElement ]
|
|
|
|
},
|
2013-06-10 23:05:42 +00:00
|
|
|
{ 'type': 'retain', 'length': 3 }
|
2013-02-14 23:21:53 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
'checks offset is in bounds': {
|
|
|
|
'args': [ doc, 15, 0, newElement ],
|
|
|
|
'exception': Error
|
|
|
|
},
|
|
|
|
'checks metadata index is in bounds': {
|
|
|
|
'args': [ doc, 11, 5, newElement ],
|
|
|
|
'exception': Error
|
|
|
|
}
|
|
|
|
};
|
2013-04-06 16:45:26 +00:00
|
|
|
QUnit.expect( ve.getObjectKeys( cases ).length );
|
2013-02-14 23:21:53 +00:00
|
|
|
runConstructorTests( assert, ve.dm.Transaction.newFromMetadataElementReplacement, cases );
|
|
|
|
} );
|