model.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { stringify, parse, getData, setData } from '../../src/dev-utils/model';
  6. import Model from '../../src/model/model';
  7. import DocumentFragment from '../../src/model/documentfragment';
  8. import Element from '../../src/model/element';
  9. import Text from '../../src/model/text';
  10. import Range from '../../src/model/range';
  11. import Position from '../../src/model/position';
  12. import count from '@ckeditor/ckeditor5-utils/src/count';
  13. describe( 'model test utils', () => {
  14. let model, document, root, selection;
  15. beforeEach( () => {
  16. model = new Model();
  17. document = model.document;
  18. root = document.createRoot();
  19. selection = document.selection;
  20. model.change( writer => {
  21. writer.setSelection( null );
  22. } );
  23. model.schema.register( 'a', {
  24. allowWhere: '$text',
  25. allowIn: '$root',
  26. allowAttributes: [ 'bar', 'car', 'foo' ]
  27. } );
  28. model.schema.register( 'b', {
  29. allowWhere: '$text',
  30. allowIn: '$root',
  31. allowAttributes: [ 'barFoo', 'fooBar', 'x' ]
  32. } );
  33. model.schema.register( 'c', {
  34. allowWhere: '$text',
  35. allowIn: [ '$root', 'b' ]
  36. } );
  37. model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  38. model.schema.extend( '$text', {
  39. allowIn: [ '$root', 'a', 'b' ]
  40. } );
  41. } );
  42. afterEach( () => {
  43. sinon.restore();
  44. } );
  45. describe( 'getData', () => {
  46. it( 'should use stringify method', () => {
  47. const stringifySpy = sinon.spy( getData, '_stringify' );
  48. root._appendChild( new Element( 'b', null, new Text( 'btext' ) ) );
  49. expect( getData( model, { withoutSelection: true } ) ).to.equal( '<b>btext</b>' );
  50. sinon.assert.calledOnce( stringifySpy );
  51. sinon.assert.calledWithExactly( stringifySpy, root, null, null );
  52. } );
  53. it( 'should use stringify method with selection', () => {
  54. const stringifySpy = sinon.spy( getData, '_stringify' );
  55. root._appendChild( new Element( 'b', null, new Text( 'btext' ) ) );
  56. model.change( writer => {
  57. writer.setSelection( new Range( Position._createAt( root, 0 ), Position._createAt( root, 1 ) ) );
  58. } );
  59. expect( getData( model ) ).to.equal( '[<b>btext</b>]' );
  60. sinon.assert.calledOnce( stringifySpy );
  61. sinon.assert.calledWithExactly( stringifySpy, root, document.selection, null );
  62. } );
  63. it( 'should throw an error when passing invalid document', () => {
  64. expect( () => {
  65. getData( { invalid: 'document' } );
  66. } ).to.throw( TypeError, 'Model needs to be an instance of module:engine/model/model~Model.' );
  67. } );
  68. } );
  69. describe( 'setData', () => {
  70. it( 'should use parse method', () => {
  71. const parseSpy = sinon.spy( setData, '_parse' );
  72. const options = {};
  73. const data = '<b>btext</b>text';
  74. setData( model, data, options );
  75. expect( getData( model, { withoutSelection: true } ) ).to.equal( data );
  76. sinon.assert.calledOnce( parseSpy );
  77. const args = parseSpy.firstCall.args;
  78. expect( args[ 0 ] ).to.equal( data );
  79. } );
  80. it( 'should use parse method with selection', () => {
  81. const parseSpy = sinon.spy( setData, '_parse' );
  82. const options = {};
  83. const data = '[<b>btext</b>]';
  84. setData( model, data, options );
  85. expect( getData( model ) ).to.equal( data );
  86. sinon.assert.calledOnce( parseSpy );
  87. const args = parseSpy.firstCall.args;
  88. expect( args[ 0 ] ).to.equal( data );
  89. } );
  90. it( 'should insert text', () => {
  91. test( 'this is test text', '[]this is test text' );
  92. } );
  93. it( 'should insert text with selection around', () => {
  94. test( '[this is test text]' );
  95. } );
  96. it( 'should insert text with selection inside #1', () => {
  97. test( 'this [is test] text' );
  98. } );
  99. it( 'should insert text with selection inside #2', () => {
  100. test( '[this is test] text' );
  101. } );
  102. it( 'should insert text with selection inside #3', () => {
  103. test( 'this is [test text]' );
  104. } );
  105. it( 'should insert unicode text with selection', () => {
  106. test( 'நி[லைக்]கு' );
  107. } );
  108. it( 'should insert element', () => {
  109. test( '<b>foo bar</b>', '[]<b>foo bar</b>' );
  110. } );
  111. it( 'should insert element with selection inside #1', () => {
  112. test( '<b>[foo ]bar</b>' );
  113. } );
  114. it( 'should insert element with selection inside #2', () => {
  115. test( '[<b>foo ]bar</b>' );
  116. } );
  117. it( 'should insert element with selection inside #3', () => {
  118. test( '<b>[foo bar</b>]' );
  119. } );
  120. it( 'should insert backward selection', () => {
  121. setData( model, '<b>[foo bar</b>]', { lastRangeBackward: true } );
  122. expect( getData( model ) ).to.equal( '<b>[foo bar</b>]' );
  123. expect( document.selection.isBackward ).to.true;
  124. } );
  125. it( 'should throw an error when passing invalid document', () => {
  126. expect( () => {
  127. setData( { invalid: 'document' } );
  128. } ).to.throw( TypeError, 'Model needs to be an instance of module:engine/model/model~Model.' );
  129. } );
  130. it( 'should set attributes to the selection', () => {
  131. setData( model, '<b>[foo bar]</b>', { selectionAttributes: { foo: 'bar' } } );
  132. expect( document.selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  133. } );
  134. // #815.
  135. it( 'should work in a special root', () => {
  136. const model = new Model();
  137. model.schema.register( 'textOnly' );
  138. model.schema.extend( '$text', { allowIn: 'textOnly' } );
  139. model.document.createRoot( 'textOnly', 'textOnly' );
  140. setData( model, 'a[b]c', { rootName: 'textOnly' } );
  141. expect( getData( model, { rootName: 'textOnly' } ) ).to.equal( 'a[b]c' );
  142. } );
  143. function test( data, expected ) {
  144. expected = expected || data;
  145. setData( model, data );
  146. expect( getData( model ) ).to.equal( expected );
  147. }
  148. } );
  149. describe( 'stringify', () => {
  150. it( 'should stringify text', () => {
  151. const text = new Text( 'text', { underline: true, bold: true } );
  152. expect( stringify( text ) ).to.equal( '<$text bold="true" underline="true">text</$text>' );
  153. } );
  154. it( 'should stringify element', () => {
  155. const element = new Element( 'a', null, [
  156. new Element( 'b', null, new Text( 'btext' ) ),
  157. new Text( 'atext' )
  158. ] );
  159. expect( stringify( element ) ).to.equal( '<a><b>btext</b>atext</a>' );
  160. } );
  161. it( 'should stringify document fragment', () => {
  162. const fragment = new DocumentFragment( [
  163. new Element( 'b', null, new Text( 'btext' ) ),
  164. new Text( 'atext' )
  165. ] );
  166. expect( stringify( fragment ) ).to.equal( '<b>btext</b>atext' );
  167. } );
  168. it( 'writes elements and texts', () => {
  169. root._appendChild( [
  170. new Element( 'a', null, new Text( 'atext' ) ),
  171. new Element( 'b', null, [
  172. new Element( 'c1' ),
  173. new Text( 'ctext' ),
  174. new Element( 'c2' )
  175. ] ),
  176. new Element( 'd' )
  177. ] );
  178. expect( stringify( root ) ).to.equal(
  179. '<a>atext</a><b><c1></c1>ctext<c2></c2></b><d></d>'
  180. );
  181. } );
  182. it( 'writes element attributes', () => {
  183. root._appendChild(
  184. new Element( 'a', { foo: true, bar: 1, car: false }, [
  185. new Element( 'b', { fooBar: 'x y', barFoo: { x: 1, y: 2 } } )
  186. ] )
  187. );
  188. // Note: attributes are written in a very simplistic way, because they are not to be parsed. They are just
  189. // to be compared in the tests with some patterns.
  190. expect( stringify( root ) ).to.equal(
  191. '<a bar="1" car="false" foo="true"><b barFoo="{"x":1,"y":2}" fooBar="x y"></b></a>'
  192. );
  193. } );
  194. it( 'writes text attributes', () => {
  195. root._appendChild( [
  196. new Text( 'foo', { bold: true } ),
  197. new Text( 'bar' ),
  198. new Text( 'bom', { bold: true, italic: true } ),
  199. new Element( 'a', null, [
  200. new Text( 'pom', { underline: true, bold: true } )
  201. ] )
  202. ] );
  203. expect( stringify( root ) ).to.equal(
  204. '<$text bold="true">foo</$text>bar<$text bold="true" italic="true">bom</$text>' +
  205. '<a><$text bold="true" underline="true">pom</$text></a>'
  206. );
  207. } );
  208. it( 'writes unicode text', () => {
  209. root._appendChild( new Text( 'நிலைக்கு' ) );
  210. expect( stringify( root ) ).to.equal( 'நிலைக்கு' );
  211. } );
  212. describe( 'selection', () => {
  213. let elA, elB;
  214. beforeEach( () => {
  215. elA = new Element( 'a' );
  216. elB = new Element( 'b' );
  217. root._appendChild( [
  218. elA,
  219. new Text( 'foo' ),
  220. new Text( 'bar', { bold: true } ),
  221. elB
  222. ] );
  223. } );
  224. it( 'writes selection in an empty root', () => {
  225. const root = document.createRoot( '$root', 'empty' );
  226. model.change( writer => {
  227. writer.setSelection( root, 0 );
  228. } );
  229. expect( stringify( root, selection ) ).to.equal(
  230. '[]'
  231. );
  232. } );
  233. it( 'writes selection collapsed in an element', () => {
  234. model.change( writer => {
  235. writer.setSelection( root, 0 );
  236. } );
  237. expect( stringify( root, selection ) ).to.equal(
  238. '[]<a></a>foo<$text bold="true">bar</$text><b></b>'
  239. );
  240. } );
  241. it( 'writes selection collapsed in a text', () => {
  242. model.change( writer => {
  243. writer.setSelection( root, 3 );
  244. } );
  245. expect( stringify( root, selection ) ).to.equal(
  246. '<a></a>fo[]o<$text bold="true">bar</$text><b></b>'
  247. );
  248. } );
  249. it( 'writes selection collapsed at the text left boundary', () => {
  250. model.change( writer => {
  251. writer.setSelection( elA, 'after' );
  252. } );
  253. expect( stringify( root, selection ) ).to.equal(
  254. '<a></a>[]foo<$text bold="true">bar</$text><b></b>'
  255. );
  256. } );
  257. it( 'writes selection collapsed at the text right boundary', () => {
  258. model.change( writer => {
  259. writer.setSelection( elB, 'before' );
  260. } );
  261. expect( stringify( root, selection ) ).to.equal(
  262. '<a></a>foo<$text bold="true">bar[]</$text><b></b>'
  263. );
  264. } );
  265. it( 'writes selection collapsed at the end of the root', () => {
  266. model.change( writer => {
  267. writer.setSelection( root, 'end' );
  268. // Needed due to https://github.com/ckeditor/ckeditor5-engine/issues/320.
  269. writer.removeSelectionAttribute( model.document.selection.getAttributeKeys() );
  270. } );
  271. expect( stringify( root, selection ) ).to.equal(
  272. '<a></a>foo<$text bold="true">bar</$text><b></b>[]'
  273. );
  274. } );
  275. it( 'writes selection collapsed selection in a text with attributes', () => {
  276. model.change( writer => {
  277. writer.setSelection( root, 5 );
  278. } );
  279. expect( stringify( root, selection ) ).to.equal(
  280. '<a></a>foo<$text bold="true">b[]ar</$text><b></b>'
  281. );
  282. } );
  283. it( 'writes flat selection containing couple of nodes', () => {
  284. model.change( writer => {
  285. writer.setSelection( new Range( Position._createAt( root, 0 ), Position._createAt( root, 4 ) ) );
  286. } );
  287. expect( stringify( root, selection ) ).to.equal(
  288. '[<a></a>foo]<$text bold="true">bar</$text><b></b>'
  289. );
  290. } );
  291. it( 'writes flat selection within text', () => {
  292. model.change( writer => {
  293. writer.setSelection( new Range( Position._createAt( root, 2 ), Position._createAt( root, 3 ) ) );
  294. } );
  295. expect( stringify( root, selection ) ).to.equal(
  296. '<a></a>f[o]o<$text bold="true">bar</$text><b></b>'
  297. );
  298. } );
  299. it( 'writes multi-level selection', () => {
  300. model.change( writer => {
  301. writer.setSelection( new Range( Position._createAt( elA, 0 ), Position._createAt( elB, 0 ) ) );
  302. } );
  303. expect( stringify( root, selection ) ).to.equal(
  304. '<a>[</a>foo<$text bold="true">bar</$text><b>]</b>'
  305. );
  306. } );
  307. it( 'writes selection when is backward', () => {
  308. model.change( writer => {
  309. writer.setSelection( new Range( Position._createAt( elA, 0 ), Position._createAt( elB, 0 ) ), { backward: true } );
  310. } );
  311. expect( stringify( root, selection ) ).to.equal(
  312. '<a>[</a>foo<$text bold="true">bar</$text><b>]</b>'
  313. );
  314. } );
  315. it( 'writes selection in unicode text', () => {
  316. const root = document.createRoot( '$root', 'empty' );
  317. root._appendChild( new Text( 'நிலைக்கு' ) );
  318. model.change( writer => {
  319. writer.setSelection( new Range( Position._createAt( root, 2 ), Position._createAt( root, 6 ) ) );
  320. } );
  321. expect( stringify( root, selection ) ).to.equal( 'நி[லைக்]கு' );
  322. } );
  323. it( 'uses range and coverts it to selection', () => {
  324. const range = new Range( Position._createAt( elA, 0 ), Position._createAt( elB, 0 ) );
  325. expect( stringify( root, range ) ).to.equal(
  326. '<a>[</a>foo<$text bold="true">bar</$text><b>]</b>'
  327. );
  328. } );
  329. it( 'uses position and converts it to collapsed selection', () => {
  330. const position = new Position( root, [ 0 ] );
  331. expect( stringify( root, position ) ).to.equal(
  332. '[]<a></a>foo<$text bold="true">bar</$text><b></b>'
  333. );
  334. } );
  335. } );
  336. } );
  337. describe( 'parse', () => {
  338. test( 'creates empty DocumentFragment from empty string', {
  339. data: '',
  340. check( fragment ) {
  341. expect( fragment ).to.be.instanceOf( DocumentFragment );
  342. }
  343. } );
  344. test( 'creates empty DocumentFragment with selection', {
  345. data: '[]'
  346. } );
  347. test( 'returns Element if range is around single element', {
  348. data: '[<a></a>]',
  349. check( el, selection ) {
  350. const fragment = el.parent;
  351. expect( el ).to.be.instanceOf( Element );
  352. expect( fragment ).to.be.instanceOf( DocumentFragment );
  353. expect( selection.rangeCount ).to.equal( 1 );
  354. const range = new Range( Position._createAt( fragment, 0 ), Position._createAt( fragment, 1 ) );
  355. expect( selection.getFirstRange().isEqual( range ) ).to.be.true;
  356. }
  357. } );
  358. test( 'returns DocumentFragment when multiple elements on root', {
  359. data: '<a></a><b></b>',
  360. check( fragment ) {
  361. expect( fragment ).to.be.instanceOf( DocumentFragment );
  362. expect( fragment.childCount ).to.equal( 2 );
  363. }
  364. } );
  365. test( 'creates elements', {
  366. data: '<a></a><b><c></c></b>'
  367. } );
  368. test( 'creates text nodes', {
  369. data: 'foo<a>bar</a>bom'
  370. } );
  371. test( 'creates text nodes with unicode text', {
  372. data: 'நிலைக்கு'
  373. } );
  374. test( 'sets elements attributes', {
  375. data: '<a bar="true" car="x y" foo="1"></a><b x="y"></b>',
  376. output: '<a bar="true" car="x y" foo="1"></a><b x="y"></b>',
  377. check( root ) {
  378. expect( root.getChild( 0 ).getAttribute( 'bar' ) ).to.equal( true );
  379. expect( root.getChild( 0 ).getAttribute( 'car' ) ).to.equal( 'x y' );
  380. expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.equal( 1 );
  381. expect( root.getChild( 1 ).getAttribute( 'x' ) ).to.equal( 'y' );
  382. }
  383. } );
  384. test( 'sets text attributes', {
  385. data: '<$text bar="true" car="x y" foo="1">foo</$text><$text x="y">bar</$text>bom',
  386. check( root ) {
  387. expect( root.childCount ).to.equal( 3 );
  388. expect( root.maxOffset ).to.equal( 9 );
  389. expect( root.getChild( 0 ).getAttribute( 'bar' ) ).to.equal( true );
  390. expect( root.getChild( 0 ).getAttribute( 'car' ) ).to.equal( 'x y' );
  391. expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.equal( 1 );
  392. expect( root.getChild( 1 ).getAttribute( 'x' ) ).to.equal( 'y' );
  393. expect( count( root.getChild( 2 ).getAttributes() ) ).to.equal( 0 );
  394. }
  395. } );
  396. test( 'creates element with complex attributes', {
  397. data: '<a foo=\'{"x":1,"y":2}\'></a>',
  398. output: '<a foo="{"x":1,"y":2}"></a>',
  399. check( a ) {
  400. expect( count( a.getAttributes() ) ).to.equal( 1 );
  401. expect( a.getAttribute( 'foo' ) ).to.have.property( 'x', 1 );
  402. expect( a.getAttribute( 'foo' ) ).to.have.property( 'y', 2 );
  403. }
  404. } );
  405. test( 'returns single parsed element', {
  406. data: '<paragraph></paragraph>',
  407. check( p ) {
  408. expect( p instanceof Element ).to.be.true;
  409. }
  410. } );
  411. test( 'returns DocumentFragment for multiple parsed elements', {
  412. data: '<paragraph></paragraph><paragraph></paragraph>',
  413. check( fragment ) {
  414. expect( fragment instanceof DocumentFragment ).to.be.true;
  415. }
  416. } );
  417. it( 'throws when invalid XML', () => {
  418. expect( () => {
  419. parse( '<a><b></a></b>', model.schema );
  420. } ).to.throw( Error, /Parse error/ );
  421. } );
  422. it( 'throws when try to set element not registered in schema', () => {
  423. expect( () => {
  424. parse( '<xyz></xyz>', model.schema );
  425. } ).to.throw( Error, 'Element \'xyz\' was not allowed in given position.' );
  426. } );
  427. it( 'throws when try to set text directly to $root without registering it', () => {
  428. const model = new Model();
  429. expect( () => {
  430. parse( 'text', model.schema );
  431. } ).to.throw( Error, 'Text was not allowed in given position.' );
  432. } );
  433. it( 'converts data in the specified context', () => {
  434. const model = new Model();
  435. model.schema.register( 'foo' );
  436. model.schema.extend( '$text', { allowIn: 'foo' } );
  437. expect( () => {
  438. parse( 'text', model.schema, { context: [ 'foo' ] } );
  439. } ).to.not.throw();
  440. } );
  441. describe( 'selection', () => {
  442. test( 'sets collapsed selection in an element', {
  443. data: '<a>[]</a>',
  444. check( root, selection ) {
  445. expect( selection.getFirstPosition().parent ).to.have.property( 'name', 'a' );
  446. }
  447. } );
  448. test( 'sets collapsed selection between elements', {
  449. data: '<a></a>[]<b></b>'
  450. } );
  451. test( 'sets collapsed selection before a text', {
  452. data: '<a></a>[]foo'
  453. } );
  454. test( 'sets collapsed selection after a text', {
  455. data: 'foo[]'
  456. } );
  457. test( 'sets collapsed selection within a text', {
  458. data: 'foo[]bar',
  459. check( text, selection ) {
  460. expect( text.offsetSize ).to.equal( 6 );
  461. expect( text.getPath() ).to.deep.equal( [ 0 ] );
  462. expect( selection.getFirstRange().start.path ).to.deep.equal( [ 3 ] );
  463. expect( selection.getFirstRange().end.path ).to.deep.equal( [ 3 ] );
  464. }
  465. } );
  466. it( 'sets selection attributes', () => {
  467. const result = parse( 'foo[]bar', model.schema, {
  468. selectionAttributes: {
  469. bold: true,
  470. italic: true
  471. }
  472. } );
  473. expect( stringify( result.model, result.selection ) ).to.equal( 'foo<$text bold="true" italic="true">[]</$text>bar' );
  474. } );
  475. test( 'sets collapsed selection between text and text with attributes', {
  476. data: 'foo[]<$text bold="true">bar</$text>',
  477. check( root, selection ) {
  478. expect( root.maxOffset ).to.equal( 6 );
  479. expect( selection.getAttribute( 'bold' ) ).to.be.undefined;
  480. }
  481. } );
  482. test( 'sets selection containing an element', {
  483. data: 'x[<a></a>]'
  484. } );
  485. it( 'sets selection with attribute containing an element', () => {
  486. const result = parse( 'x[<a></a>]', model.schema, {
  487. selectionAttributes: {
  488. bold: true
  489. }
  490. } );
  491. expect( stringify( result.model, result.selection ) ).to.equal( 'x[<a></a>]' );
  492. expect( result.selection.getAttribute( 'bold' ) ).to.be.true;
  493. } );
  494. it( 'sets a backward selection containing an element', () => {
  495. const result = parse( 'x[<a></a>]', model.schema, {
  496. lastRangeBackward: true
  497. } );
  498. expect( stringify( result.model, result.selection ) ).to.equal( 'x[<a></a>]' );
  499. expect( result.selection.isBackward ).to.true;
  500. } );
  501. test( 'sets selection within a text', {
  502. data: 'x[y]z'
  503. } );
  504. it( 'sets selection within a text with different attributes', () => {
  505. const result = parse( '<$text bold="true">fo[o</$text>ba]r', model.schema, {
  506. selectionAttributes: { bold: true }
  507. } );
  508. expect( stringify( result.model, result.selection ) ).to.equal( '<$text bold="true">fo[o</$text>ba]r' );
  509. expect( result.selection.getAttribute( 'bold' ) ).to.true;
  510. } );
  511. it( 'throws when missing selection start', () => {
  512. expect( () => {
  513. parse( 'foo]', model.schema );
  514. } ).to.throw( Error, /^Parse error/ );
  515. } );
  516. it( 'throws when missing selection end', () => {
  517. expect( () => {
  518. parse( '[foo', model.schema );
  519. } ).to.throw( Error, /^Parse error/ );
  520. } );
  521. } );
  522. function test( title, options ) {
  523. it( title, () => {
  524. const output = options.output || options.data;
  525. const data = parse( options.data, model.schema );
  526. let converted, selection;
  527. if ( data.selection && data.model ) {
  528. converted = data.model;
  529. selection = data.selection;
  530. } else {
  531. converted = data;
  532. }
  533. expect( stringify( converted, selection ) ).to.equal( output );
  534. if ( options.check ) {
  535. options.check( converted, selection );
  536. }
  537. } );
  538. }
  539. } );
  540. } );