|
|
@@ -796,6 +796,29 @@ describe( 'Range', () => {
|
|
|
range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should return null if ranges do not intersect nor have equal start/end', () => {
|
|
|
+ const otherRange = new Range( new Position( root, [ 5, 5 ] ), new Position( root, [ 7 ] ) );
|
|
|
+ const sum = range.getJoined( otherRange );
|
|
|
+
|
|
|
+ expect( sum ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return a range spanning both of the ranges if the ranges have equal start/end positions', () => {
|
|
|
+ const otherRange = new Range( new Position( root, [ 5, 4 ] ), new Position( root, [ 7 ] ) );
|
|
|
+ const sum = range.getJoined( otherRange );
|
|
|
+
|
|
|
+ expect( sum.start.path ).to.deep.equal( [ 3, 2 ] );
|
|
|
+ expect( sum.end.path ).to.deep.equal( [ 7 ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return a range spanning both of the ranges if the ranges have equal start/end positions (different order)', () => {
|
|
|
+ const otherRange = new Range( new Position( root, [ 1, 4 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
+ const sum = range.getJoined( otherRange );
|
|
|
+
|
|
|
+ expect( sum.start.path ).to.deep.equal( [ 1, 4 ] );
|
|
|
+ expect( sum.end.path ).to.deep.equal( [ 5, 4 ] );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should return a range spanning both of the ranges - original range contains the other range', () => {
|
|
|
const otherRange = new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) );
|
|
|
const sum = range.getJoined( otherRange );
|
|
|
@@ -825,7 +848,7 @@ describe( 'Range', () => {
|
|
|
expect( sum.isEqual( range ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- describe( 'with ranges "touching"', () => {
|
|
|
+ describe( 'with `loose` option enabled', () => {
|
|
|
beforeEach( () => {
|
|
|
prepareRichRoot( root );
|
|
|
} );
|
|
|
@@ -833,7 +856,7 @@ describe( 'Range', () => {
|
|
|
it( 'should return null if ranges are not intersecting nor touching', () => {
|
|
|
const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
|
|
|
const otherRange = new Range( new Position( root, [ 3, 1 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
- const sum = range.getJoined( otherRange );
|
|
|
+ const sum = range.getJoined( otherRange, true );
|
|
|
|
|
|
expect( sum ).to.be.null;
|
|
|
} );
|
|
|
@@ -841,7 +864,7 @@ describe( 'Range', () => {
|
|
|
it( 'should return a range spanning both of the ranges - original range end is equal to other range start position', () => {
|
|
|
const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
|
|
|
const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
- const sum = range.getJoined( otherRange );
|
|
|
+ const sum = range.getJoined( otherRange, true );
|
|
|
|
|
|
expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
|
|
|
expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
|
|
|
@@ -850,7 +873,7 @@ describe( 'Range', () => {
|
|
|
it( 'should return a range spanning both of the ranges - original range start is equal to other range end position', () => {
|
|
|
const range = new Range( new Position( root, [ 3 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
const otherRange = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
|
|
|
- const sum = range.getJoined( otherRange );
|
|
|
+ const sum = range.getJoined( otherRange, true );
|
|
|
|
|
|
expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
|
|
|
expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
|
|
|
@@ -859,7 +882,7 @@ describe( 'Range', () => {
|
|
|
it( 'should return a range spanning both of the ranges - original range is touching other range on the right side', () => {
|
|
|
const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
|
|
|
const otherRange = new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
- const sum = range.getJoined( otherRange );
|
|
|
+ const sum = range.getJoined( otherRange, true );
|
|
|
|
|
|
expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
|
|
|
expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
|
|
|
@@ -868,7 +891,7 @@ describe( 'Range', () => {
|
|
|
it( 'should return a range spanning both of the ranges - original range is touching other range on the left side', () => {
|
|
|
const range = new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 3, 2 ] ) );
|
|
|
const otherRange = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 2 ] ) );
|
|
|
- const sum = range.getJoined( otherRange );
|
|
|
+ const sum = range.getJoined( otherRange, true );
|
|
|
|
|
|
expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
|
|
|
expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
|