Index: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js |
— | — | @@ -801,7 +801,7 @@ |
802 | 802 | ); |
803 | 803 | } ); |
804 | 804 | |
805 | | -test( 've.dm.DocumentNode.prepareWrap', 2, function() { |
| 805 | +test( 've.dm.DocumentNode.prepareWrap', 5, function() { |
806 | 806 | var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj ); |
807 | 807 | |
808 | 808 | // Test 1 |
— | — | @@ -836,4 +836,31 @@ |
837 | 837 | ], |
838 | 838 | 'prepareWrap unwraps a list' |
839 | 839 | ); |
| 840 | + |
| 841 | + // Test 3 |
| 842 | + raises( |
| 843 | + function() { |
| 844 | + documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'table' } ], [], [], [] ); |
| 845 | + }, |
| 846 | + /^Element in unwrapOuter does not match: expected table but found list$/, |
| 847 | + 'prepareWrap checks integrity of unwrapOuter parameter' |
| 848 | + ); |
| 849 | + |
| 850 | + // Test 4 |
| 851 | + raises( |
| 852 | + function() { |
| 853 | + documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'list' } ], [], [ { 'type': 'paragraph' } ], [] ); |
| 854 | + }, |
| 855 | + /^Element in unwrapEach does not match: expected paragraph but found listItem$/, |
| 856 | + 'prepareWrap checks integrity of unwrapEach parameter' |
| 857 | + ); |
| 858 | + |
| 859 | + // Test 5 |
| 860 | + raises( |
| 861 | + function() { |
| 862 | + documentModel.prepareWrap( new ve.Range( 1, 4 ), [ { 'type': 'listItem' }, { 'type': 'paragraph' } ], [], [], [] ); |
| 863 | + }, |
| 864 | + /^unwrapOuter is longer than the data preceding the range$/, |
| 865 | + 'prepareWrap checks that unwrapOuter fits before the range' |
| 866 | + ); |
840 | 867 | } ); |
\ No newline at end of file |
Index: trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js |
— | — | @@ -1159,10 +1159,7 @@ |
1160 | 1160 | return closings; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | | - // TODO sanity checks: |
1164 | | - // * range.start > unwrapOuter.length |
1165 | | - // * unwraps actually match |
1166 | | - // * result is valid |
| 1163 | + // TODO: we're not checking for nesting validity. prepareInsertion also needs this |
1167 | 1164 | |
1168 | 1165 | var tx = new ve.dm.Transaction(), i, j, unwrapOuterData; |
1169 | 1166 | range.normalize(); |
— | — | @@ -1171,6 +1168,8 @@ |
1172 | 1169 | // The outer unwrapping takes place *outside* |
1173 | 1170 | // the range, so compensate for that |
1174 | 1171 | tx.pushRetain( range.start - unwrapOuter.length ); |
| 1172 | + } else if ( range.start < unwrapOuter.length ) { |
| 1173 | + throw 'unwrapOuter is longer than the data preceding the range'; |
1175 | 1174 | } |
1176 | 1175 | |
1177 | 1176 | // Replace the opening elements for the outer unwrap&wrap |