range.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treemodel */
  6. 'use strict';
  7. import Range from '/ckeditor5/core/treemodel/range.js';
  8. import Position from '/ckeditor5/core/treemodel/position.js';
  9. import Element from '/ckeditor5/core/treemodel/element.js';
  10. import Text from '/ckeditor5/core/treemodel/text.js';
  11. import Document from '/ckeditor5/core/treemodel/document.js';
  12. describe( 'Range', () => {
  13. let range, start, end, root, otherRoot;
  14. beforeEach( () => {
  15. let doc = new Document();
  16. root = doc.createRoot( 'root' );
  17. otherRoot = doc.createRoot( 'otherRoot' );
  18. start = new Position( root, [ 1 ] );
  19. end = new Position( root, [ 2 ] );
  20. range = new Range( start, end );
  21. } );
  22. describe( 'constructor', () => {
  23. it( 'should create a range with given positions', () => {
  24. expect( range.start.isEqual( start ) ).to.be.true;
  25. expect( range.end.isEqual( end ) ).to.be.true;
  26. } );
  27. } );
  28. describe( 'root', () => {
  29. it( 'should be equal to start position root', () => {
  30. expect( range.root ).to.equal( start.root );
  31. } );
  32. } );
  33. describe( 'isCollapsed', () => {
  34. it( 'should be true if range start and end positions are equal', () => {
  35. let collapsedRange = new Range( start, start );
  36. expect( collapsedRange.isCollapsed ).to.be.true;
  37. } );
  38. it( 'should be false if range start and end positions are not equal', () => {
  39. expect( range.isCollapsed ).to.be.false;
  40. } );
  41. } );
  42. describe( 'isEqual', () => {
  43. it( 'should return true if the ranges are the same', () => {
  44. let sameStart = Position.createFromPosition( start );
  45. let sameEnd = Position.createFromPosition( end );
  46. let sameRange = new Range( sameStart, sameEnd );
  47. expect( range.isEqual( sameRange ) ).to.be.true;
  48. } );
  49. it( 'should return false if the start position is different', () => {
  50. let range = new Range( start, end );
  51. let diffStart = new Position( root, [ 0 ] );
  52. let sameEnd = Position.createFromPosition( end );
  53. let diffRange = new Range( diffStart, sameEnd );
  54. expect( range.isEqual( diffRange ) ).to.be.false;
  55. } );
  56. it( 'should return false if the end position is different', () => {
  57. let sameStart = new Position( root, [ 0 ] );
  58. let diffEnd = new Position( root, [ 0 ] );
  59. let diffRange = new Range( sameStart, diffEnd );
  60. expect( range.isEqual( diffRange ) ).to.be.false;
  61. } );
  62. it( 'should return false if ranges are in different roots', () => {
  63. let otherRootStart = new Position( otherRoot, start.path.slice() );
  64. let otherRootEnd = new Position( otherRoot, end.path.slice() );
  65. let otherRootRange = new Range( otherRootStart, otherRootEnd );
  66. expect( range.isEqual( otherRootRange ) ).to.be.false;
  67. } );
  68. } );
  69. describe( 'isIntersecting', () => {
  70. it( 'should return true if given range is equal', () => {
  71. let otherRange = Range.createFromRange( range );
  72. expect( range.isIntersecting( otherRange ) ).to.be.true;
  73. } );
  74. it( 'should return true if given range contains this range', () => {
  75. let otherRange = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
  76. expect( range.isIntersecting( otherRange ) ).to.be.true;
  77. } );
  78. it( 'should return true if given range ends in this range', () => {
  79. let otherRange = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 4 ] ) );
  80. expect( range.isIntersecting( otherRange ) ).to.be.true;
  81. } );
  82. it( 'should return true if given range starts in this range', () => {
  83. let otherRange = new Range( new Position( root, [ 1, 4 ] ), new Position( root, [ 3 ] ) );
  84. expect( range.isIntersecting( otherRange ) ).to.be.true;
  85. } );
  86. it( 'should return false if given range is fully before this range', () => {
  87. let otherRange = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
  88. expect( range.isIntersecting( otherRange ) ).to.be.false;
  89. } );
  90. it( 'should return false if given range is fully after this range', () => {
  91. let otherRange = new Range( new Position( root, [ 2 ] ), new Position( root, [ 2, 0 ] ) );
  92. expect( range.isIntersecting( otherRange ) ).to.be.false;
  93. } );
  94. it( 'should return false if ranges are in different roots', () => {
  95. let otherRange = new Range( new Position( otherRoot, [ 0 ] ), new Position( otherRoot, [ 1, 4 ] ) );
  96. expect( range.isIntersecting( otherRange ) ).to.be.false;
  97. } );
  98. } );
  99. describe( 'static constructors', () => {
  100. let p, f, o, z;
  101. // root
  102. // |- p
  103. // |- f
  104. // |- o
  105. // |- z
  106. before( () => {
  107. f = new Text( 'f' );
  108. o = new Text( 'o' );
  109. z = new Text( 'z' );
  110. p = new Element( 'p', [], [ f, o, z ] );
  111. root.insertChildren( 0, [ p ] );
  112. } );
  113. describe( 'createFromElement', () => {
  114. it( 'should return range', () => {
  115. const range = Range.createFromElement( p );
  116. expect( range.start.path ).to.deep.equal( [ 0, 0 ] );
  117. expect( range.end.path ).to.deep.equal( [ 0, 3 ] );
  118. } );
  119. } );
  120. describe( 'createFromParentsAndOffsets', () => {
  121. it( 'should return range', () => {
  122. const range = Range.createFromParentsAndOffsets( root, 0, p, 2 );
  123. expect( range.start.path ).to.deep.equal( [ 0 ] );
  124. expect( range.end.path ).to.deep.equal( [ 0, 2 ] );
  125. } );
  126. } );
  127. describe( 'createFromPositionAndShift', () => {
  128. it( 'should make range from start position and offset', () => {
  129. const position = new Position( root, [ 1, 2, 3 ] );
  130. const range = Range.createFromPositionAndShift( position, 4 );
  131. expect( range ).to.be.instanceof( Range );
  132. expect( range.start.isEqual( position ) ).to.be.true;
  133. expect( range.end.root ).to.equal( range.start.root );
  134. expect( range.end.path ).to.deep.equal( [ 1, 2, 7 ] );
  135. } );
  136. } );
  137. describe( 'createFromRange', () => {
  138. it( 'should create a new instance of Range that is equal to passed range', () => {
  139. const clone = Range.createFromRange( range );
  140. expect( clone ).not.to.be.equal( range ); // clone is not pointing to the same object as position
  141. expect( clone.isEqual( range ) ).to.be.true; // but they are equal in the position-sense
  142. } );
  143. } );
  144. } );
  145. describe( 'iterator', () => {
  146. it( 'should merge characters with same attributes', () => {
  147. prepareRichRoot( root );
  148. let range = new Range( new Position( root, [ 0, 0, 3 ] ), new Position( root, [ 3, 0, 2 ] ) );
  149. let nodes = Array.from( range ).map( value => value.item );
  150. let lengths = Array.from( range ).map( value => value.length );
  151. let nodeNames = mapNodesToNames( nodes );
  152. expect( nodeNames ).to.deep.equal( [ 'T:st', 'E:p', 'T:lorem ipsum', 'E:p', 'T:foo', 'E:p', 'T:bar', 'E:div', 'E:h', 'T:se' ] );
  153. expect( lengths ).to.deep.equal( [ 2, 1, 11, 1, 3, 1, 3, 1, 1, 2 ] );
  154. } );
  155. } );
  156. describe( 'getItems', () => {
  157. it( 'should iterate over all items in the range', () => {
  158. prepareRichRoot( root );
  159. let range = new Range( new Position( root, [ 0, 0, 3 ] ), new Position( root, [ 3, 0, 2 ] ) );
  160. let items = Array.from( range.getItems() );
  161. let nodeNames = mapNodesToNames( items );
  162. expect( nodeNames ).to.deep.equal( [ 'T:st', 'E:p', 'T:lorem ipsum', 'E:p', 'T:foo', 'E:p', 'T:bar', 'E:div', 'E:h', 'T:se' ] );
  163. } );
  164. it( 'should iterate over all items in the range as single characters', () => {
  165. const a = new Text( 'a' );
  166. const b = new Text( 'b' );
  167. const x = new Text( 'x' );
  168. const y = new Text( 'y' );
  169. const e1 = new Element( 'e1' );
  170. const e2 = new Element( 'e2' );
  171. e1.insertChildren( 0, [ a, b ] );
  172. e2.insertChildren( 0, [ x, y ] );
  173. root.insertChildren( 0, [ e1, e2 ] );
  174. let range = new Range(
  175. new Position( root, [ 0, 1 ] ),
  176. new Position( root, [ 1, 1 ] )
  177. );
  178. let items = Array.from( range.getItems( true ) );
  179. expect( items.length ).to.equal( 3 );
  180. expect( items[ 0 ].character ).to.equal( 'b' );
  181. expect( items[ 1 ] ).to.equal( e2 );
  182. expect( items[ 2 ].character ).to.equal( 'x' );
  183. } );
  184. } );
  185. describe( 'containsPosition', () => {
  186. beforeEach( () => {
  187. range = new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) );
  188. } );
  189. it( 'should return false if position is before range', () => {
  190. const position = new Position( root, [ 0, 4 ] );
  191. expect( range.containsPosition( position ) ).to.be.false;
  192. } );
  193. it( 'should return false if position is after range', () => {
  194. const position = new Position( root, [ 3, 0 ] );
  195. expect( range.containsPosition( position ) ).to.be.false;
  196. } );
  197. it( 'should return true if position is inside range', () => {
  198. const position = new Position( root, [ 2, 2 ] );
  199. expect( range.containsPosition( position ) ).to.be.true;
  200. } );
  201. } );
  202. describe( 'getTransformedByInsertion', () => {
  203. it( 'should return an array of Range objects', () => {
  204. const range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
  205. const transformed = range.getTransformedByInsertion( new Position( root, [ 2 ] ), 2 );
  206. expect( transformed ).to.be.instanceof( Array );
  207. expect( transformed[ 0 ] ).to.be.instanceof( Range );
  208. } );
  209. it( 'should update it\'s positions offsets if insertion is before range and they are affected', () => {
  210. const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 3, 4 ] ) );
  211. const transformed = range.getTransformedByInsertion( new Position( root, [ 3, 1 ] ), 2 );
  212. expect( transformed[ 0 ].start.offset ).to.equal( 4 );
  213. expect( transformed[ 0 ].end.offset ).to.equal( 6 );
  214. } );
  215. it( 'should update it\'s positions paths if insertion is before range and they are affected', () => {
  216. const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 4, 4 ] ) );
  217. const transformed = range.getTransformedByInsertion( new Position( root, [ 0 ] ), 2 );
  218. expect( transformed[ 0 ].start.path[ 0 ] ).to.equal( 5 );
  219. expect( transformed[ 0 ].end.path[ 0 ] ).to.equal( 6 );
  220. } );
  221. it( 'should return array with two ranges and updated positions if insertion was in the middle of range', () => {
  222. const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
  223. const transformed = range.getTransformedByInsertion( new Position( root, [ 4, 1, 6 ] ), 4 );
  224. expect( transformed.length ).to.equal( 2 );
  225. expect( transformed[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
  226. expect( transformed[ 0 ].end.path ).to.deep.equal( [ 4, 1, 6 ] );
  227. expect( transformed[ 1 ].start.path ).to.deep.equal( [ 4, 1, 10 ] );
  228. expect( transformed[ 1 ].end.path ).to.deep.equal( [ 5, 4 ] );
  229. } );
  230. it( 'should not updated positions if insertion is after range', () => {
  231. const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 4, 4 ] ) );
  232. const transformed = range.getTransformedByInsertion( new Position( root, [ 4, 4 ] ), 3 );
  233. expect( transformed[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
  234. expect( transformed[ 0 ].end.path ).to.deep.equal( [ 4, 4 ] );
  235. } );
  236. } );
  237. describe( 'getDifference', () => {
  238. let range;
  239. beforeEach( () => {
  240. range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
  241. } );
  242. it( 'should return an array of Range objects', () => {
  243. const otherRange = new Range( new Position( root, [ 6 ] ), new Position( root, [ 7 ] ) );
  244. const diff = range.getDifference( otherRange );
  245. expect( diff ).to.be.instanceof( Array );
  246. expect( diff[ 0 ] ).to.be.instanceof( Range );
  247. } );
  248. it( 'should return original range if other range does not intersect with it', () => {
  249. const otherRange = new Range( new Position( root, [ 6 ] ), new Position( root, [ 7 ] ) );
  250. const diff = range.getDifference( otherRange );
  251. expect( diff[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
  252. expect( diff[ 0 ].end.path ).to.deep.equal( [ 5, 4 ] );
  253. } );
  254. it( 'should return shrunken range if other range intersects with it', () => {
  255. const otherRange = new Range( new Position( root, [ 4, 1 ] ), new Position( root, [ 7 ] ) );
  256. const diff = range.getDifference( otherRange );
  257. expect( diff[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
  258. expect( diff[ 0 ].end.path ).to.deep.equal( [ 4, 1 ] );
  259. } );
  260. it( 'should return an empty array if other range contains or is same as the original range', () => {
  261. const otherRange = new Range( new Position( root, [ 2 ] ), new Position( root, [ 6 ] ) );
  262. const diff = range.getDifference( otherRange );
  263. expect( diff.length ).to.equal( 0 );
  264. } );
  265. it( 'should two ranges if other range is contained by the original range', () => {
  266. const otherRange = new Range( new Position( root, [ 3, 7 ] ), new Position( root, [ 4, 1 ] ) );
  267. const diff = range.getDifference( otherRange );
  268. expect( diff.length ).to.equal( 2 );
  269. expect( diff[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
  270. expect( diff[ 0 ].end.path ).to.deep.equal( [ 3, 7 ] );
  271. expect( diff[ 1 ].start.path ).to.deep.equal( [ 4, 1 ] );
  272. expect( diff[ 1 ].end.path ).to.deep.equal( [ 5, 4 ] );
  273. } );
  274. } );
  275. describe( 'getIntersection', () => {
  276. let range;
  277. beforeEach( () => {
  278. range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
  279. } );
  280. it( 'should return null if ranges do not intersect', () => {
  281. const otherRange = new Range( new Position( root, [ 5, 4 ] ), new Position( root, [ 7 ] ) );
  282. const common = range.getIntersection( otherRange );
  283. expect( common ).to.be.null;
  284. } );
  285. it( 'should return a range equal to the common part of ranges - original range contains the other range', () => {
  286. const otherRange = new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) );
  287. const common = range.getIntersection( otherRange );
  288. expect( common.isEqual( otherRange ) ).to.be.true;
  289. } );
  290. it( 'should return a range equal to the common part of ranges - original range is contained by the other range', () => {
  291. const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 6 ] ) );
  292. const common = range.getIntersection( otherRange );
  293. expect( common.isEqual( range ) ).to.be.true;
  294. } );
  295. it( 'should return a range equal to the common part of ranges - original range intersects with the other range', () => {
  296. const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 4, 7 ] ) );
  297. const common = range.getIntersection( otherRange );
  298. expect( common.start.path ).to.deep.equal( [ 3, 2 ] );
  299. expect( common.end.path ).to.deep.equal( [ 4, 7 ] );
  300. } );
  301. } );
  302. describe( 'getMinimalFlatRanges', () => {
  303. beforeEach( () => {
  304. prepareRichRoot( root );
  305. } );
  306. it( 'should return empty array if range is collapsed', () => {
  307. let range = new Range( new Position( root, [ 1, 3 ] ), new Position( root, [ 1, 3 ] ) );
  308. let flat = range.getMinimalFlatRanges();
  309. expect( flat.length ).to.equal( 0 );
  310. } );
  311. it( 'should return empty array if range does not contain any node', () => {
  312. let range = new Range( new Position( root, [ 1, 3 ] ), new Position( root, [ 2, 0 ] ) );
  313. let flat = range.getMinimalFlatRanges();
  314. expect( flat.length ).to.equal( 0 );
  315. } );
  316. it( 'should return a minimal set of flat ranges that covers the range (start and end in different sub-trees)', () => {
  317. let range = new Range( new Position( root, [ 0, 0, 3 ] ), new Position( root, [ 3, 0, 2 ] ) );
  318. let flat = range.getMinimalFlatRanges();
  319. expect( flat.length ).to.equal( 4 );
  320. expect( flat[ 0 ].start.path ).to.deep.equal( [ 0, 0, 3 ] );
  321. expect( flat[ 0 ].end.path ).to.deep.equal( [ 0, 0, 5 ] );
  322. expect( flat[ 1 ].start.path ).to.deep.equal( [ 0, 1 ] );
  323. expect( flat[ 1 ].end.path ).to.deep.equal( [ 0, 2 ] );
  324. expect( flat[ 2 ].start.path ).to.deep.equal( [ 1 ] );
  325. expect( flat[ 2 ].end.path ).to.deep.equal( [ 3 ] );
  326. expect( flat[ 3 ].start.path ).to.deep.equal( [ 3, 0, 0 ] );
  327. expect( flat[ 3 ].end.path ).to.deep.equal( [ 3, 0, 2 ] );
  328. } );
  329. it( 'should return a minimal set of flat ranges that covers the range (start.path is prefix of end.path)', () => {
  330. let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 0, 1, 4 ] ) );
  331. let flat = range.getMinimalFlatRanges();
  332. expect( flat.length ).to.equal( 2 );
  333. expect( flat[ 0 ].start.path ).to.deep.equal( [ 0, 0 ] );
  334. expect( flat[ 0 ].end.path ).to.deep.equal( [ 0, 1 ] );
  335. expect( flat[ 1 ].start.path ).to.deep.equal( [ 0, 1, 0 ] );
  336. expect( flat[ 1 ].end.path ).to.deep.equal( [ 0, 1, 4 ] );
  337. } );
  338. } );
  339. describe( 'getTopLevelNodes', () => {
  340. beforeEach( () => {
  341. prepareRichRoot( root );
  342. } );
  343. it( 'should iterate over all top-level nodes of this range', () => {
  344. let range = new Range( new Position( root, [ 0, 0, 3 ] ), new Position( root, [ 3, 0, 2 ] ) );
  345. let nodes = Array.from( range.getTopLevelNodes() );
  346. let nodeNames = mapNodesToNames( nodes );
  347. expect( nodeNames ).to.deep.equal( [ 'T:st', 'E:p', 'E:p', 'E:p', 'T:se' ] );
  348. } );
  349. it( 'should return single characters iterating over all top-level nodes of this range', () => {
  350. let range = new Range( new Position( root, [ 0, 0, 3 ] ), new Position( root, [ 3, 0, 2 ] ) );
  351. let nodes = Array.from( range.getTopLevelNodes( true ) );
  352. let nodeNames = mapNodesToNames( nodes );
  353. expect( nodeNames ).to.deep.equal( [ 'T:s', 'T:t', 'E:p', 'E:p', 'E:p', 'T:s', 'T:e' ] );
  354. } );
  355. } );
  356. describe( 'getPositions', () => {
  357. beforeEach( () => {
  358. prepareRichRoot( root );
  359. } );
  360. it( 'should iterate over all positions in this range', () => {
  361. let expectedPaths = [
  362. [ 1, 2 ], [ 1, 3 ],
  363. [ 2 ], [ 2, 0 ], [ 2, 3 ],
  364. [ 3 ], [ 3, 0 ], [ 3, 0, 0 ], [ 3, 0, 2 ]
  365. ];
  366. let range = new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 3, 0, 2 ] ) );
  367. let i = 0;
  368. for ( let position of range.getPositions() ) {
  369. expect( position.path ).to.deep.equal( expectedPaths[ i ] );
  370. i++;
  371. }
  372. expect( i ).to.equal( expectedPaths.length );
  373. } );
  374. it( 'should return single nodes iterating over all positions in this range', () => {
  375. let expectedPaths = [
  376. [ 1, 2 ], [ 1, 3 ],
  377. [ 2 ], [ 2, 0 ], [ 2, 1 ], [ 2, 2 ], [ 2, 3 ],
  378. [ 3 ], [ 3, 0 ], [ 3, 0, 0 ], [ 3, 0, 1 ], [ 3, 0, 2 ]
  379. ];
  380. let range = new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 3, 0, 2 ] ) );
  381. let i = 0;
  382. for ( let position of range.getPositions( true ) ) {
  383. expect( position.path ).to.deep.equal( expectedPaths[ i ] );
  384. i++;
  385. }
  386. expect( i ).to.equal( expectedPaths.length );
  387. } );
  388. } );
  389. describe( 'isFlat', () => {
  390. beforeEach( () => {
  391. prepareRichRoot( root );
  392. } );
  393. it( 'should be true if start and end position are in the same parent', () => {
  394. let range = new Range( new Position( root, [ 0, 0 ] ), new Position( root, [ 0, 2 ] ) );
  395. expect( range.isFlat ).to.be.true;
  396. } );
  397. it( 'should be false if start and end position are in different parents', () => {
  398. let range = new Range( new Position( root, [ 0, 0 ] ), new Position( root, [ 3, 0, 1 ] ) );
  399. expect( range.isFlat ).to.be.false;
  400. } );
  401. } );
  402. function mapNodesToNames( nodes ) {
  403. return nodes.map( ( node ) => {
  404. return ( node instanceof Element ) ? 'E:' + node.name : 'T:' + ( node.text || node.character );
  405. } );
  406. }
  407. function prepareRichRoot() {
  408. root.insertChildren( 0, [
  409. new Element( 'div', [], [
  410. new Element( 'h', [], 'first' ),
  411. new Element( 'p', [], 'lorem ipsum' )
  412. ] ),
  413. new Element( 'p', [], 'foo' ),
  414. new Element( 'p', [], 'bar' ),
  415. new Element( 'div', [], [
  416. new Element( 'h', [], 'second' ),
  417. new Element( 'p', [], 'lorem' )
  418. ] )
  419. ] );
  420. }
  421. } );