Commit graph

344 commits

Author SHA1 Message Date
Trevor Parscal 32bddaf088 Added ve.dm.Transaction.newFromRemoval
Also:
* Refactored tests
* Added tests for ve.dm.Transaction.newFromInsertion
* Added tests for ve.dm.Transaction.newFromRemoval
* Fixed problems with ve.dm.Transaction.newFromInsertion
* Added ve.dm.Node.canBeMergedWith which is partially a port of ve.Node.getCommonAncestorPaths merged with canMerge from within ve.dm.DocumentNode.prepareRemoval from the old ve codebase

Change-Id: Ibbc3887d08286d8ab33fd6296487802d65b319fa
2012-05-31 14:39:34 -07:00
Catrope 2f18605a1a Fix buggy replace behavior when inserting content that contains nodes
Copy-pasting things like "text<IMAGE>moretext" failed spectacularly,
this commit fixes that.

* Check for content rather than structure in the inserted/removed data
* In the content case
** Run selectNodes() over the removal range, rather than just the cursor
*** i.e. no longer assume that content replacements only affect one node
** If there is structure involved, rebuild all affected nodes

Change-Id: I80e40b5b7c514a3fb105d57e4a17770d0fefaaea
2012-05-31 07:27:36 -07:00
Catrope f6ca37926d Add ve.dm.Document.isContentData()
Some of the replacement code was assuming that "does not contain
elements" and "is content" were the same. They're not any more, because
we have content nodes (like image) now, so I need a separate function
to distinguish between these cases.

Change-Id: I206ccdf082b7baddf99d382eb3cdd77ea34fb479
2012-05-31 06:19:34 -07:00
Catrope e92db86046 Fix bug in ve.dm.Document constructor for input ending with text
If the last element of the input data array was text, the resulting text
node would have length=0 rather than the expected length value.

Change-Id: I3d089a80b8a447a12ba411b2e11c1b84f14f2959
2012-05-31 06:17:23 -07:00
Trevor Parscal 14862a1212 Fixed bug in isStructuralOffset which didn't consider neighboring a non-content leaf to be a structural offset
This was caused by the fact that a non-structural leaf can not have children, which makes it appear incompatible as a sibling to an arbitrary structural element (like a paragraph) but since it can not contain content we can check that instead.

Change-Id: Ie3c58b4b43f2aa6921f8f82aa82511e231207854
2012-05-25 13:19:56 -07:00
Inez Korczynski afe18a685a Fix methods getNearestStructuralOffset and getNearestContentOffset for case of passing offsets that are already structural or content
Change-Id: I23cd2daab9cef181b01131b3b9c6ead5ec47f9f4
2012-05-24 20:53:50 -07:00
Trevor Parscal c9dddf60da Made getRelativeOffset return -1 if no valid offset is found in document
Change-Id: If4cef5fe800b241c3efe1d27cdf01cd1ceef2248
2012-05-24 11:43:47 -07:00
Trevor Parscal 8d3044bf60 Added more test cases for the unrestricted option of getRelativeStructuralOffset and getNearestStructuralOffset
Change-Id: I1ab99f1ed050950b40dd4c34abd81a43a4099a49
2012-05-24 11:43:47 -07:00
Trevor Parscal 1ddaec8acb Added getRelativeOffset and several wrappers around it
Change-Id: Ifd10922366650165bc4c21ea8cfdd2f9b7163432
2012-05-23 17:43:24 -07:00
Trevor Parscal 541d786ced Added optional "unrestricted" argument to isStructuralOffset
Using this argument will only return true if the offset is a place you can add any element to (hence the unrestricted part of it). This is good for testing if a paragraph could potentially be inserted there.

Change-Id: I6cc91da437c52493de03eb687b28966198270fea
2012-05-23 14:56:33 -07:00
Catrope 9a1ec62f0d Remove pushInsert() and pushRemove()
The 'insert' and 'remove' operations weren't implemented in the
transaction processor and were a holdover from the old DM
implementation.

Also migrated the tests, especially those that asserted that consecutive
insert/remove operations were combined (this is no longer the case now
that they are replace operations)

Change-Id: I2379fe92b331c5316f70f4b695397da41581cce9
2012-05-23 12:45:27 -07:00
Trevor Parscal 86591e5325 Restructured static node rules
Change-Id: I7023e1f334694d59767491f1010e7c4c59c0ce54
2012-05-21 17:39:12 -07:00
Trevor Parscal 0a32898f3a Added annotation and attribute tests for transaction constructors
Change-Id: I61e5f37b1f866afc4a3b9a18cd6e7e7a08e0958f
2012-05-21 12:21:07 -07:00
Rob Moen 272f502693 Modify getAnnotationsFromOffset to account for annotated leaf nodes.
Refactor remaining annotation methods
Refactor tests to use correct annotation types

Change-Id: Ia3ce42b3d11296b4d63277e0e2a1997d23236613
2012-05-21 12:02:04 -07:00
Rob Moen 3d5da75782 Merge branch 'master' of ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor into dmrewrite 2012-05-21 11:01:16 -07:00
Gabriel Wicke fb7d5418a5 Round-trip nowiki
Change-Id: I5f7e6a43f5fdc1708ee710b2a601b20db733452c
2012-05-21 18:06:09 +02:00
Rob Moen f19c5917f2 remove hasChildren method as I was using it to debug something on
previous commit.  change traverseLeafNode test name to follow
ve2 test naming scheme

Change-Id: I8b953e3405f42cd58a80da676ac9b16d64f5e72d
2012-05-18 14:11:23 -07:00
Rob Moen 62959bec7a ported traverseLeafNodes and tests to new dm
Change-Id: I98487267d6e3efc9e0c07a02b3d5acc8f8cdb4c6
2012-05-18 13:47:14 -07:00
Subramanya Sastry 9b84e931db First pass updating parserTests to verify dom->wikitext serialization.
- Just a quick first pass updating the parserTests.js script so we can
  test DOM -> wikitext serialization (but which in effect really tests
  roundtripping).
- There is no output normalization yet which is needed for now since we
  are not yet preserving white-space.

Change-Id: Ie52058e0dc3330f852c24fa05641dced19f950e0
2012-05-18 09:51:22 +02:00
Trevor Parscal 43d62ee8a7 Refactored getMatchingAnnotations and it's tests, and added offsetContainsMatchingAnnotations
Change-Id: I9098ef8d9c7f3a4f5db112cfdcb9edb7ffd17b80
2012-05-17 14:37:29 -07:00
Rob Moen a937ad22f7 Fix getAnnotatedRange to return propper contained range.
Fixed tests

Change-Id: I305eb81644fb3c804455b4fc13bdabcce97ea471
2012-05-17 13:17:18 -07:00
Trevor Parscal 3eb31dae09 Whitespace fixes and removed some console.log statements
Change-Id: Ifcf8a496fb4b649cbf3ce07290b8f6dda60f179d
2012-05-17 11:29:50 -07:00
Trevor Parscal 08765feab3 Merged ve.dm.DocumentFragment and ve.dm.Document
* Also fixed lots of whitespace issues and some global variable introductions

Change-Id: Ia6c82ef0c3b5c4938cf72afa86da6d79e4cb385a
2012-05-17 11:23:56 -07:00
Rob Moen c2a89626d5 Rewrite getMatchingAnnotations to return a hashmap of matching anntations
in the new DM.  Change method name getAnnotationRange from offset to
getAnnotatedRangeFromOffset.  Write tests

Change-Id: I7028803065409e271ceced73e4803954d4a956dc
2012-05-17 10:46:27 -07:00
Gabriel Wicke 04fc74c76a Strip RDFa attributes in parserTests
We are adding some extra information in those, which should not make tests
fail.

Change-Id: I42cca596330252efeff5d51508f97ef1c566475b
2012-05-17 17:03:44 +02:00
Catrope bcd7431818 Remove getScope(), no longer used
Change-Id: I79e067a8e6b3eb151d3ebe1dfc3aaebe242aed39
2012-05-16 20:16:47 -07:00
Rob Moen fbaea888b9 Rewrite data model methods needed for ui tools
getAnnotationRangeFromOffset and offsetContainsAnnotation
which deprecated getAnnotationBoundaries, and getIndexOfAnnotation
write unit tests for proof

Change-Id: I6c0d4e3ca96dd569b1909cd22fce68c3a6fe382c
2012-05-16 15:55:01 -07:00
Christian Williams eefbee2262 Merge branch 'dmrewrite' of ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor into dmrewrite 2012-05-16 13:41:56 -07:00
Christian Williams 189e3eddbe Another test for HTMLConverter
Change-Id: I9b0fa2de44381b363fb6e612884f9911996e941b
2012-05-16 13:41:26 -07:00
Trevor Parscal 0c69370117 Added merge test for ve.dm.TransactionProcessor
Also added 2 paragraphs at the end of the example document and updated related tests accordingly

Change-Id: Idd294cbe3975d0a04069e55682a91417160e538a
2012-05-16 13:33:42 -07:00
Gabriel Wicke 542921b5a3 Removed html5 parser patch no longer needed with 0.3.8
Change-Id: Id8c23d34e8cca49a360f536e792144a85a8468a3
2012-05-16 12:06:42 +02:00
Trevor Parscal 6d0a24bec6 Greatly simplified selection and node tree comparison tests
By first summarizing a node tree or node selection and then using the normal deepEqual function we are able to take advantage of native QUnit functionality to make diagnosing a problem easier under failing conditions and reduce the verbosity of the output under passing conditions.

Change-Id: I4af5d69596cf5459aa32f61ee6d5b8355233c3df
2012-05-15 00:25:27 -07:00
Catrope cdda5e7920 Improve verbosity of selectNodes test descriptions
* Make nodeSelectionEqual() accept a desc parameter and use it for
  building descriptions
* Put the array element number in the desciption too
* Add descriptions for selectNodes tests and pass them through

Change-Id: Icd2894d11516234598cbd984cc8d88f705bfc1d6
2012-05-14 22:54:53 -07:00
Catrope 0f0c3c9939 Improvements to nodeTreeEqual():
* Don't crash if b.children has a different length than expected
* Don't crash if b.children is absent but expected
* Check if b.children is present when it's not expected
* Add assertion when neither a.children not b.children are present; this
  makes the number of assertions for leaves equal to the number of
  assertions for branches
* Check attributes too
* Accept a desc parameter, and add node paths (like
  list/listItem/paragraph/text) to the descriptions
* Use desc parameter for all calls (some tests were already using it,
  even though it didn't actually exist)

Change-Id: Ic56d27d20377e7f4fdfa038fdf4ebe00dcb3e062
2012-05-14 22:43:36 -07:00
Trevor Parscal 3b1d8098e9 Added a replace test that splits elements
Change-Id: Ifb9c42c36611b2b936a48b911e9786e2105da09c
2012-05-14 21:50:33 -07:00
Catrope 2008858830 Fix bug in selectNodes: input (0,0) returned []
This was because the while loop was never entered as end >= left was
true from the start. Convert the while loop to a do-while loop to make
sure it runs at least once

Change-Id: I9c6436a7b296e65a36b8301095b6edd00507d321
2012-05-14 21:41:08 -07:00
Rob Moen 30a671fcea Rename some tests
Change-Id: Ie0c50023a17fead64eb28e6184f70a32b626eaff
2012-05-14 17:24:11 -07:00
Rob Moen 6e8bdde910 Add tests for getAnnotationsFromRange
Change-Id: I51aebb54d3d65c3160ac48e9ee971183fb3885bb
2012-05-14 17:22:16 -07:00
Trevor Parscal 14a4c7b780 Fixed annotation processing to support leaf nodes and detect more errors
Also added lots of tests

Change-Id: I45fe4fb569d9050d7d79f71f777d82f5b34fdd11
2012-05-14 17:16:30 -07:00
Trevor Parscal 94613589e0 Removed more trailing whitespace in multi-line comment blocks
Continues cleanup work done in e0de881a8a

Change-Id: I7165a8f8c4b468793d936fe695de92335c106271
2012-05-14 17:16:30 -07:00
Rob Moen ca48a4a8a1 Merge branch 'dmrewrite' of ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor into dmrewrite 2012-05-14 16:44:08 -07:00
Rob Moen d2fc95fa52 Optimize getAnnotationsFrom dramatically by less object manipulation
Now returning an empty array when a non annotated character is found
in the range.  No longer looping through each annotation, simply
comparing to previous characters annotations and trimming differences.
Write additional test.

Change-Id: I41d2422a931a74325693edca409aed6d5da20ba8
2012-05-14 16:40:49 -07:00
Trevor Parscal e0de881a8a Removed trailing whitespace in multi-line comment blocks
JSHint and various git tools complain about this, so let's just do away with them altogether

Change-Id: I731866bd21f1ee0088fb0a71df3abf92692aca23
2012-05-14 15:05:09 -07:00
Trevor Parscal 5708c0e02f Added transparent 1px image to make unit tests not show HTTP errors
Change-Id: I800e98ae6c47121ec652c34bd678e54e7efcb77c
2012-05-14 15:04:06 -07:00
Trevor Parscal aa9148c9ee Refactored ve.dm.TransactionProcessor tests to use data-providers
Change-Id: I0535f3ac56b6037712d731c71fc68c56ae7ea614
2012-05-14 14:32:34 -07:00
Rob Moen b8302c715f Rewrite getAnnotationsFromOffset to work with new Linear Model.
Properly init variables in getAnnotationsFromRange
Polish up tests.

Change-Id: Idc231998ce27e3a1c64363e862da22c837ea2ca2
2012-05-14 10:47:48 -07:00
Rob Moen e05863b0dc use proper assertion in getAnnotationsFromOffset
Change-Id: I41b5cfa3628d5a2ed6d3f59d157ebe372585059c
2012-05-14 09:58:30 -07:00
Trevor Parscal 6321821c86 Rewrote tests for ve.dm.Transaction to use a data provider
Change-Id: I7ecf09c627b96b4c84824152bd178fb36c1ce348
2012-05-11 16:49:31 -07:00
Rob Moen 7d8e06c78c Fix up wrapping on getAnnotationsFromRange test
Change-Id: I793cd33b88f7c7f3a17d6fbfb80218438aa878af
2012-05-11 16:33:38 -07:00
Rob Moen bd9a0b6fba Rewrite DocumentFragment getAnnotationsFromRange method
Write unit tests for getAnnotationsFromRange

Change-Id: I82ff15e97378c07e5c555a72231da4161a72993c
2012-05-11 16:14:46 -07:00