/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
import Range from '../../src/view/range';
import Position from '../../src/view/position';
import Element from '../../src/view/element';
import DocumentFragment from '../../src/view/documentfragment';
import Text from '../../src/view/text';
import TreeWalker from '../../src/view/treewalker';
import { parse, stringify } from '../../src/dev-utils/view';
function getRange( view, options = {} ) {
const { selection } = parse( view, options );
return selection.getFirstRange();
}
describe( 'Range', () => {
describe( 'constructor()', () => {
it( 'creates range from provided positions', () => {
const start = new Position( {}, 1 );
const end = new Position( {}, 2 );
const range = new Range( start, end );
expect( range ).to.be.an.instanceof( Range );
expect( range ).to.have.property( 'start' ).that.not.equals( start );
expect( range ).to.have.property( 'end' ).that.not.equals( end );
expect( range.start.parent ).to.equal( start.parent );
expect( range.end.parent ).to.equal( end.parent );
expect( range.start.offset ).to.equal( start.offset );
expect( range.end.offset ).to.equal( end.offset );
} );
it( 'creates collapsed range', () => {
const start = new Position( {}, 1 );
const range = new Range( start );
expect( range.start.isEqual( start ) ).to.be.true;
expect( range.isCollapsed ).to.be.true;
} );
} );
describe( 'iterator', () => {
it( 'should iterate over the range returning tree walker values', () => {
const range = getRange( '
fo{o
bar
xy}z
' );
const values = Array.from( range );
expect( values.length ).to.equal( 5 );
expect( values[ 0 ].item.data ).to.equal( 'o' );
expect( values[ 1 ].item.name ).to.equal( 'p' );
expect( values[ 2 ].item.data ).to.equal( 'bar' );
expect( values[ 3 ].item.name ).to.equal( 'p' );
expect( values[ 4 ].item.data ).to.equal( 'xy' );
} );
} );
describe( 'isFlat', () => {
it( 'should be true if range start and range end are in same parent', () => {
const range = getRange( 'f{oo}
bar
' );
expect( range.isFlat ).to.be.true;
} );
it( 'should be false if range start and range end are in different parents', () => {
const range = getRange( 'fo{o
b}ar
' );
expect( range.isFlat ).to.be.false;
} );
} );
describe( 'getRoot', () => {
it( 'should return root element in which range is created', () => {
const viewRoot = new Element( 'div' );
const range = getRange( 'f{oo
ba}r
', { rootElement: viewRoot } );
expect( range.root ).to.equal( viewRoot );
} );
it( 'should return document fragment in which range is created', () => {
const viewFrag = new DocumentFragment();
const range = getRange( 'f{oo
ba}r
', { rootElement: viewFrag } );
expect( range.root ).to.equal( viewFrag );
} );
} );
describe( 'getEnlarged', () => {
it( 'case 1', () => {
expect( enlarge( 'f{oo}
bar
' ) )
.to.equal( 'f[oo]
bar
' );
} );
it( 'case 2', () => {
expect( enlarge( 'f{oo}bar
' ) )
.to.equal( 'f{oo}bar
' );
} );
it( 'case 3', () => {
expect( enlarge( 'f{oo}bar
' ) )
.to.equal( 'f[oo]bar
' );
} );
it( 'case 4', () => {
expect( enlarge( 'f
{oo}
bar
' ) )
.to.equal( 'f
[oo]
bar
' );
} );
it( 'case 5', () => {
expect( enlarge( 'f{oo}bar
' ) )
.to.equal( 'f[oo]bar
' );
} );
it( 'case6', () => {
expect( enlarge( 'foo
[bar]
bom
' ) )
.to.equal( 'foo
[bar]
bom
' );
} );
function enlarge( data ) {
data = data
.replace( //g, '' )
.replace( /<\/p>/g, '' )
.replace( //g, '' )
.replace( /<\/b>/g, '' )
.replace( /
<\/img>/g, '' )
.replace( /<\/span>/g, '' );
const viewFrag = new DocumentFragment();
const { view, selection } = parse( data, { rootElement: viewFrag } );
const range = selection.getFirstRange();
const enlargedRange = range.getEnlarged();
return stringify( view, enlargedRange );
}
} );
describe( 'getTrimmed', () => {
it( 'case 1', () => {
expect( trim( 'f[oo]
bar
' ) )
.to.equal( 'f{oo}
bar
' );
} );
it( 'case 2', () => {
expect( trim( 'f{oo}bar
' ) )
.to.equal( 'f{oo}bar
' );
} );
it( 'case 3', () => {
expect( trim( 'f[oo]bar
' ) )
.to.equal( 'f{oo}bar
' );
} );
it( 'case 4', () => {
expect( trim( 'f
[oo]
bar
' ) )
.to.equal( 'f
{oo}
bar
' );
} );
it( 'case 5', () => {
expect( trim( 'f[oo]bar
' ) )
.to.equal( 'f{oo}bar
' );
} );
it( 'case 6', () => {
expect( trim( 'foo[
bar
]bom
' ) )
.to.equal( 'foo[
bar
]bom
' );
} );
it( 'case 7', () => {
expect( trim( 'foo[
]bom
' ) )
.to.equal( 'foo[
]bom
' );
} );
// Other results may theoretically be correct too. It is not decided whether the trimmed range should
// be collapsed in attribute element, at its start or its end. This is one of possible correct results
// and we won't know for sure unless we have more cases. See #1058.
it( 'case 8', () => {
expect( trim( '[]
' ) )
.to.equal( '[]
' );
} );
// As above.
it( 'case 9', () => {
expect( trim( '[]
' ) )
.to.equal( '[]
' );
} );
// As above.
it( 'case 10', () => {
expect( trim( '[]
' ) )
.to.equal( '[]
' );
} );
// As above.
it( 'case 11', () => {
expect( trim( '[]
' ) )
.to.equal( '[]
' );
} );
function trim( data ) {
data = data
.replace( //g, '' )
.replace( /<\/p>/g, '' )
.replace( //g, '' )
.replace( /<\/b>/g, '' )
.replace( /
<\/img>/g, '' )
.replace( /<\/span>/g, '' );
const viewFrag = new DocumentFragment();
const { view, selection } = parse( data, { rootElement: viewFrag } );
const range = selection.getFirstRange();
const trimmedRange = range.getTrimmed();
return stringify( view, trimmedRange );
}
} );
describe( 'isEqual', () => {
it( 'should return true for the same range', () => {
const start = new Position( {}, 1 );
const end = new Position( {}, 2 );
const range = new Range( start, end );
expect( range.isEqual( range ) ).to.be.true;
} );
it( 'should return true for ranges with same start and end positions', () => {
const start = new Position( {}, 1 );
const end = new Position( {}, 2 );
const range1 = new Range( start, end );
const range2 = new Range( start, end );
expect( range1.isEqual( range2 ) ).to.be.true;
} );
it( 'should return false if start position is different', () => {
const start1 = new Position( {}, 1 );
const start2 = new Position( {}, 1 );
const end = new Position( {}, 2 );
const range1 = new Range( start1, end );
const range2 = new Range( start2, end );
expect( range1.isEqual( range2 ) ).to.be.false;
} );
it( 'should return false if end position is different', () => {
const start = new Position( {}, 1 );
const end1 = new Position( {}, 2 );
const end2 = new Position( {}, 2 );
const range1 = new Range( start, end1 );
const range2 = new Range( start, end2 );
expect( range1.isEqual( range2 ) ).to.be.false;
} );
it( 'should return false for ranges with same root and different offsets', () => {
const mockObject = {};
const range1 = new Range( new Position( mockObject, 0 ), new Position( mockObject, 10 ) );
const range2 = new Range( new Position( mockObject, 2 ), new Position( mockObject, 10 ) );
expect( range1.isEqual( range2 ) ).to.be.false;
} );
} );
describe( 'containsPosition', () => {
let viewRoot, range;
beforeEach( () => {
viewRoot = new Element( 'div' );
range = getRange( 'fo{o
bar
xy}z
', { rootElement: viewRoot } );
} );
it( 'should return false if position is before range', () => {
const position = new Position( viewRoot.getChild( 0 ).getChild( 0 ), 1 ); // After "f".
expect( range.containsPosition( position ) ).to.be.false;
} );
it( 'should return false if position is after range', () => {
const position = new Position( viewRoot.getChild( 2 ).getChild( 0 ), 3 ); // After "z".
expect( range.containsPosition( position ) ).to.be.false;
} );
it( 'should return true if position is inside range', () => {
const position = new Position( viewRoot.getChild( 1 ).getChild( 0 ), 1 ); // After "b".
expect( range.containsPosition( position ) ).to.be.true;
} );
} );
describe( 'containsRange', () => {
let viewRoot, range, beforeF, afterF, beforeB, afterX;
beforeEach( () => {
viewRoot = new Element( 'div' );
range = getRange( 'fo{o
bar
xy}z
', { rootElement: viewRoot } );
beforeF = new Position( viewRoot.getChild( 0 ).getChild( 0 ), 0 );
afterF = new Position( viewRoot.getChild( 0 ).getChild( 0 ), 1 );
beforeB = new Position( viewRoot.getChild( 1 ).getChild( 0 ), 0 );
afterX = new Position( viewRoot.getChild( 2 ).getChild( 0 ), 1 );
} );
it( 'should return false if ranges do not intersect', () => {
const otherRange = new Range( beforeF, afterF );
expect( range.containsRange( otherRange ) ).to.be.false;
} );
it( 'should return false if ranges intersect but only partially', () => {
const otherRange = new Range( afterF, afterX );
expect( range.containsRange( otherRange ) ).to.be.false;
} );
it( 'should return false if ranges are equal', () => {
const otherRange = Range.createFromRange( range );
expect( range.containsRange( otherRange ) ).to.be.false;
} );
it( 'should return true if given range is inside range', () => {
const otherRange = new Range( beforeB, afterX );
expect( range.containsRange( otherRange ) ).to.be.true;
} );
it( 'should return true if ranges are equal and check is not strict', () => {
const otherRange = Range.createFromRange( range );
expect( range.containsRange( otherRange, true ) ).to.be.true;
} );
it( 'should return true if ranges start at the same position and check is not strict', () => {
const otherRange = new Range( range.start, afterX );
expect( range.containsRange( otherRange, true ) ).to.be.true;
} );
it( 'should return true if ranges end at the same position and check is not strict', () => {
const otherRange = new Range( beforeB, range.end );
expect( range.containsRange( otherRange, true ) ).to.be.true;
} );
it( 'should return false if given range is collapsed and starts or ends at another range boundary', () => {
expect( range.containsRange( new Range( range.start, range.start ) ) ).to.be.false;
expect( range.containsRange( new Range( range.end, range.end ) ) ).to.be.false;
expect( range.containsRange( new Range( range.start, range.start ), true ) ).to.be.false;
expect( range.containsRange( new Range( range.end, range.end ), true ) ).to.be.false;
} );
} );
describe( 'other range interaction', () => {
let root, p1, p2, t1, t2, t3;
// root
// __________|__________
// | |
// ___p1___ p2
// | | |
// t1 t2 t3
beforeEach( () => {
t1 = new Text( 'foo' );
t2 = new Text( 'bar' );
t3 = new Text( 'baz' );
p1 = new Element( 'p', null, [ t1, t2 ] );
p2 = new Element( 'p', null, t3 );
root = new Element( 'div', null, [ p1, p2 ] );
} );
describe( 'isIntersecting', () => {
it( 'should return true if given range is equal', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t3, 2 );
const otherRange = Range.createFromRange( range );
expect( range.isIntersecting( otherRange ) ).to.be.true;
expect( otherRange.isIntersecting( range ) ).to.be.true;
} );
it( 'should return true if given range contains this range', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t3, 3 );
const otherRange = Range.createFromParentsAndOffsets( p1, 1, t2, 2 );
expect( range.isIntersecting( otherRange ) ).to.be.true;
expect( otherRange.isIntersecting( range ) ).to.be.true;
} );
it( 'should return true if given range ends in this range', () => {
const range = Range.createFromParentsAndOffsets( root, 1, t3, 3 );
const otherRange = Range.createFromParentsAndOffsets( t1, 0, p2, 0 );
expect( range.isIntersecting( otherRange ) ).to.be.true;
expect( otherRange.isIntersecting( range ) ).to.be.true;
} );
it( 'should return true if given range starts in this range', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( p1, 1, p2, 0 );
expect( range.isIntersecting( otherRange ) ).to.be.true;
expect( otherRange.isIntersecting( range ) ).to.be.true;
} );
it( 'should return false if given range is fully before/after this range', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( root, 1, t3, 0 );
expect( range.isIntersecting( otherRange ) ).to.be.false;
expect( otherRange.isIntersecting( range ) ).to.be.false;
} );
it( 'should return false if ranges are in different roots', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( new Element( 'div' ), 1, t3, 0 );
expect( range.isIntersecting( otherRange ) ).to.be.false;
expect( otherRange.isIntersecting( range ) ).to.be.false;
} );
} );
describe( 'getDifference', () => {
it( 'should return range equal to original range if other range does not intersect with it', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( root, 1, t3, 0 );
const difference = range.getDifference( otherRange );
expect( difference.length ).to.equal( 1 );
expect( difference[ 0 ].isEqual( range ) ).to.be.true;
} );
it( 'should return shrunken range if other range intersects with it', () => {
const range = Range.createFromParentsAndOffsets( root, 1, t3, 3 );
const otherRange = Range.createFromParentsAndOffsets( t1, 0, p2, 0 );
const difference = range.getDifference( otherRange );
expect( difference.length ).to.equal( 1 );
expect( difference[ 0 ].start.parent ).to.equal( p2 );
expect( difference[ 0 ].start.offset ).to.equal( 0 );
expect( difference[ 0 ].end.parent ).to.equal( t3 );
expect( difference[ 0 ].end.offset ).to.equal( 3 );
} );
it( 'should return an empty array if other range contains or is same as the original range', () => {
const range = Range.createFromParentsAndOffsets( p1, 1, t2, 2 );
const otherRange = Range.createFromParentsAndOffsets( t1, 0, t3, 3 );
const difference = range.getDifference( otherRange );
expect( difference.length ).to.equal( 0 );
} );
it( 'should two ranges if other range is contained by the original range', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t3, 3 );
const otherRange = Range.createFromParentsAndOffsets( p1, 1, t2, 2 );
const difference = range.getDifference( otherRange );
expect( difference.length ).to.equal( 2 );
expect( difference[ 0 ].start.parent ).to.equal( t1 );
expect( difference[ 0 ].start.offset ).to.equal( 0 );
expect( difference[ 0 ].end.parent ).to.equal( p1 );
expect( difference[ 0 ].end.offset ).to.equal( 1 );
expect( difference[ 1 ].start.parent ).to.equal( t2 );
expect( difference[ 1 ].start.offset ).to.equal( 2 );
expect( difference[ 1 ].end.parent ).to.equal( t3 );
expect( difference[ 1 ].end.offset ).to.equal( 3 );
} );
} );
describe( 'getIntersection', () => {
it( 'should return range equal to original range if other range contains it', () => {
const range = Range.createFromParentsAndOffsets( t2, 0, t3, 0 );
const otherRange = Range.createFromParentsAndOffsets( t1, 1, t3, 1 );
const intersection = range.getIntersection( otherRange );
expect( intersection.isEqual( range ) ).to.be.true;
} );
it( 'should return range equal to other range if it is contained in original range', () => {
const range = Range.createFromParentsAndOffsets( t1, 1, t3, 1 );
const otherRange = Range.createFromParentsAndOffsets( t2, 0, t3, 0 );
const intersection = range.getIntersection( otherRange );
expect( intersection.isEqual( otherRange ) ).to.be.true;
} );
it( 'should return null if ranges do not intersect', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( t3, 0, t3, 3 );
const intersection = range.getIntersection( otherRange );
expect( intersection ).to.be.null;
} );
it( 'should return common part if ranges intersect partially', () => {
const range = Range.createFromParentsAndOffsets( t1, 0, t2, 3 );
const otherRange = Range.createFromParentsAndOffsets( t2, 0, t3, 3 );
const intersection = range.getIntersection( otherRange );
expect( intersection.start.parent ).to.equal( t2 );
expect( intersection.start.offset ).to.equal( 0 );
expect( intersection.end.parent ).to.equal( t2 );
expect( intersection.end.offset ).to.equal( 3 );
} );
} );
} );
describe( 'getWalker', () => {
it( 'should be possible to iterate using this method', () => {
const range = getRange( 'fo{o
ba}r
xyz
' );
const values = [];
for ( const value of range.getWalker() ) {
values.push( value );
}
expect( values.length ).to.equal( 4 );
expect( values[ 0 ].item.data ).to.equal( 'o' );
expect( values[ 1 ].item.name ).to.equal( 'p' );
expect( values[ 1 ].type ).to.equal( 'elementEnd' );
expect( values[ 2 ].item.name ).to.equal( 'p' );
expect( values[ 2 ].type ).to.equal( 'elementStart' );
expect( values[ 3 ].item.data ).to.equal( 'ba' );
} );
it( 'should accept TreeWalker options', () => {
const range = getRange( 'foo
b{ar
xy}z
' );
const walker = range.getWalker( { singleCharacters: true, ignoreElementEnd: true } );
const values = [];
for ( const value of walker ) {
values.push( value );
}
expect( walker ).to.be.instanceof( TreeWalker );
expect( walker ).to.have.property( 'singleCharacters' ).that.is.true;
expect( values.length ).to.equal( 5 );
expect( values[ 0 ].item.data ).to.equal( 'a' );
expect( values[ 1 ].item.data ).to.equal( 'r' );
expect( values[ 2 ].item.name ).to.equal( 'p' );
expect( values[ 3 ].item.data ).to.equal( 'x' );
expect( values[ 4 ].item.data ).to.equal( 'y' );
} );
} );
describe( 'getItems', () => {
it( 'should return iterator that iterates over all view items in the range', () => {
const range = getRange( 'fo{o
bar
xy}z
' );
const nodes = [];
for ( const node of range.getItems() ) {
nodes.push( node );
}
expect( nodes.length ).to.equal( 5 );
expect( nodes[ 0 ].data ).to.equal( 'o' );
expect( nodes[ 1 ].name ).to.equal( 'p' );
expect( nodes[ 2 ].data ).to.equal( 'bar' );
expect( nodes[ 3 ].name ).to.equal( 'p' );
expect( nodes[ 4 ].data ).to.equal( 'xy' );
} );
it( 'should accept TreeWalker options', () => {
const range = getRange( 'foo
b{ar
xy}z
' );
const nodes = [];
for ( const node of range.getItems( { singleCharacters: true } ) ) {
nodes.push( node );
}
expect( nodes.length ).to.equal( 5 );
expect( nodes[ 0 ].data ).to.equal( 'a' );
expect( nodes[ 1 ].data ).to.equal( 'r' );
expect( nodes[ 2 ].name ).to.equal( 'p' );
expect( nodes[ 3 ].data ).to.equal( 'x' );
expect( nodes[ 4 ].data ).to.equal( 'y' );
} );
} );
describe( 'getPositions', () => {
it( 'should return iterator that iterates over all positions in the range', () => {
const range = getRange( 'fo{o
b}ar
xyz
' );
const positions = [];
for ( const position of range.getPositions() ) {
positions.push( position );
}
expect( positions.length ).to.equal( 5 );
expect( positions[ 0 ].parent.data ).to.equal( 'foo' ); // Inside text node "foo".
expect( positions[ 0 ].offset ).to.equal( 2 );
expect( positions[ 1 ].parent.name ).to.equal( 'p' ); // At the end of the first P element.
expect( positions[ 1 ].offset ).to.equal( 1 );
expect( positions[ 2 ].parent ).to.be.instanceof( DocumentFragment ); // In document fragment, between Ps.
expect( positions[ 2 ].offset ).to.equal( 1 );
expect( positions[ 3 ].parent.name ).to.equal( 'p' ); // At the beginning of the second P element.
expect( positions[ 3 ].offset ).to.equal( 0 );
expect( positions[ 4 ].parent.data ).to.equal( 'bar' ); // Inside text node "bar".
expect( positions[ 4 ].offset ).to.equal( 1 );
} );
it( 'should accept TreeWalker options', () => {
const range = getRange( 'foo
b{ar
xy}z
' );
const positions = [];
for ( const position of range.getPositions( { singleCharacters: true } ) ) {
positions.push( position );
}
expect( positions.length ).to.equal( 7 );
expect( positions[ 0 ].parent.data ).to.equal( 'bar' ); // "b^ar".
expect( positions[ 0 ].offset ).to.equal( 1 );
expect( positions[ 1 ].parent.data ).to.equal( 'bar' ); // "ba^r".
expect( positions[ 1 ].offset ).to.equal( 2 );
expect( positions[ 2 ].parent.name ).to.equal( 'p' ); // bar^
-- at the end of P node.
expect( positions[ 2 ].offset ).to.equal( 1 );
expect( positions[ 3 ].parent ).to.be.instanceof( DocumentFragment ); // "
^" -- between P nodes.
expect( positions[ 3 ].offset ).to.equal( 2 );
expect( positions[ 4 ].parent.name ).to.equal( 'p' ); //
^xyz
-- at the start of P node.
expect( positions[ 4 ].offset ).to.equal( 0 );
expect( positions[ 5 ].parent.data ).to.equal( 'xyz' ); // "x^yz".
expect( positions[ 5 ].offset ).to.equal( 1 );
expect( positions[ 6 ].parent.data ).to.equal( 'xyz' ); // "xy^z".
expect( positions[ 6 ].offset ).to.equal( 2 );
} );
} );
describe( 'static constructors', () => {
let div, p, foz;
beforeEach( () => {
foz = new Text( 'foz' );
p = new Element( 'p', null, foz );
div = new Element( 'div', null, p );
} );
describe( 'createIn', () => {
it( 'should return range', () => {
const range = Range.createIn( p );
expect( range.start.parent ).to.deep.equal( p );
expect( range.start.offset ).to.deep.equal( 0 );
expect( range.end.parent ).to.deep.equal( p );
expect( range.end.offset ).to.deep.equal( 1 );
} );
} );
describe( 'createOn', () => {
it( 'should return range', () => {
const range = Range.createOn( p );
expect( range.start.parent ).to.equal( div );
expect( range.start.offset ).to.equal( 0 );
expect( range.end.parent ).to.equal( div );
expect( range.end.offset ).to.equal( 1 );
} );
} );
describe( 'createFromParentsAndOffsets', () => {
it( 'should return range', () => {
const range = Range.createFromParentsAndOffsets( div, 0, foz, 1 );
expect( range.start.parent ).to.deep.equal( div );
expect( range.start.offset ).to.deep.equal( 0 );
expect( range.end.parent ).to.deep.equal( foz );
expect( range.end.offset ).to.deep.equal( 1 );
} );
} );
describe( 'createFromPositionAndShift', () => {
it( 'should make range from start position and offset', () => {
const position = new Position( foz, 1 );
const range = Range.createFromPositionAndShift( position, 2 );
expect( range ).to.be.instanceof( Range );
expect( range.start.isEqual( position ) ).to.be.true;
expect( range.end.parent ).to.equal( foz );
expect( range.end.offset ).to.deep.equal( 3 );
} );
it( 'should accept negative shift value', () => {
const position = new Position( foz, 3 );
const range = Range.createFromPositionAndShift( position, -1 );
expect( range ).to.be.instanceof( Range );
expect( range.end.isEqual( position ) ).to.be.true;
expect( range.start.parent ).to.equal( foz );
expect( range.start.offset ).to.deep.equal( 2 );
} );
} );
describe( 'createFromRange', () => {
it( 'should create a new instance of Range that is equal to passed range', () => {
const range = new Range( new Position( foz, 0 ), new Position( foz, 2 ) );
const clone = Range.createFromRange( range );
expect( clone ).not.to.be.equal( range ); // clone is not pointing to the same object as position
expect( clone.isEqual( range ) ).to.be.true; // but they are equal in the position-sense
} );
} );
} );
describe( 'getCommonAncestor()', () => {
it( 'should return common ancestor for positions from Range', () => {
const foz = new Text( 'foz' );
const bar = new Text( 'bar' );
const li1 = new Element( 'li', null, foz );
const li2 = new Element( 'li', null, bar );
const ul = new Element( 'ul', null, [ li1, li2 ] );
const range = new Range( new Position( li1, 0 ), new Position( li2, 2 ) );
expect( range.getCommonAncestor() ).to.equal( ul );
} );
} );
} );