model.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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( Range.createFromParentsAndOffsets( root, 0, 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( Range.createFromParentsAndOffsets( root, 0, 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( Range.createFromParentsAndOffsets( root, 2, 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( Range.createFromParentsAndOffsets( elA, 0, 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( Range.createFromParentsAndOffsets( elA, 0, 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( Range.createFromParentsAndOffsets( root, 2, root, 6 ) );
  320. } );
  321. expect( stringify( root, selection ) ).to.equal( 'நி[லைக்]கு' );
  322. } );
  323. it( 'uses range and coverts it to selection', () => {
  324. const range = Range.createFromParentsAndOffsets( elA, 0, 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. expect( selection.getFirstRange().isEqual( Range.createFromParentsAndOffsets( fragment, 0, fragment, 1 ) ) ).to.be.true;
  355. }
  356. } );
  357. test( 'returns DocumentFragment when multiple elements on root', {
  358. data: '<a></a><b></b>',
  359. check( fragment ) {
  360. expect( fragment ).to.be.instanceOf( DocumentFragment );
  361. expect( fragment.childCount ).to.equal( 2 );
  362. }
  363. } );
  364. test( 'creates elements', {
  365. data: '<a></a><b><c></c></b>'
  366. } );
  367. test( 'creates text nodes', {
  368. data: 'foo<a>bar</a>bom'
  369. } );
  370. test( 'creates text nodes with unicode text', {
  371. data: 'நிலைக்கு'
  372. } );
  373. test( 'sets elements attributes', {
  374. data: '<a bar="true" car="x y" foo="1"></a><b x="y"></b>',
  375. output: '<a bar="true" car="x y" foo="1"></a><b x="y"></b>',
  376. check( root ) {
  377. expect( root.getChild( 0 ).getAttribute( 'bar' ) ).to.equal( true );
  378. expect( root.getChild( 0 ).getAttribute( 'car' ) ).to.equal( 'x y' );
  379. expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.equal( 1 );
  380. expect( root.getChild( 1 ).getAttribute( 'x' ) ).to.equal( 'y' );
  381. }
  382. } );
  383. test( 'sets text attributes', {
  384. data: '<$text bar="true" car="x y" foo="1">foo</$text><$text x="y">bar</$text>bom',
  385. check( root ) {
  386. expect( root.childCount ).to.equal( 3 );
  387. expect( root.maxOffset ).to.equal( 9 );
  388. expect( root.getChild( 0 ).getAttribute( 'bar' ) ).to.equal( true );
  389. expect( root.getChild( 0 ).getAttribute( 'car' ) ).to.equal( 'x y' );
  390. expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.equal( 1 );
  391. expect( root.getChild( 1 ).getAttribute( 'x' ) ).to.equal( 'y' );
  392. expect( count( root.getChild( 2 ).getAttributes() ) ).to.equal( 0 );
  393. }
  394. } );
  395. test( 'creates element with complex attributes', {
  396. data: '<a foo=\'{"x":1,"y":2}\'></a>',
  397. output: '<a foo="{"x":1,"y":2}"></a>',
  398. check( a ) {
  399. expect( count( a.getAttributes() ) ).to.equal( 1 );
  400. expect( a.getAttribute( 'foo' ) ).to.have.property( 'x', 1 );
  401. expect( a.getAttribute( 'foo' ) ).to.have.property( 'y', 2 );
  402. }
  403. } );
  404. test( 'returns single parsed element', {
  405. data: '<paragraph></paragraph>',
  406. check( p ) {
  407. expect( p instanceof Element ).to.be.true;
  408. }
  409. } );
  410. test( 'returns DocumentFragment for multiple parsed elements', {
  411. data: '<paragraph></paragraph><paragraph></paragraph>',
  412. check( fragment ) {
  413. expect( fragment instanceof DocumentFragment ).to.be.true;
  414. }
  415. } );
  416. it( 'throws when invalid XML', () => {
  417. expect( () => {
  418. parse( '<a><b></a></b>', model.schema );
  419. } ).to.throw( Error, /Parse error/ );
  420. } );
  421. it( 'throws when try to set element not registered in schema', () => {
  422. expect( () => {
  423. parse( '<xyz></xyz>', model.schema );
  424. } ).to.throw( Error, 'Element \'xyz\' was not allowed in given position.' );
  425. } );
  426. it( 'throws when try to set text directly to $root without registering it', () => {
  427. const model = new Model();
  428. expect( () => {
  429. parse( 'text', model.schema );
  430. } ).to.throw( Error, 'Text was not allowed in given position.' );
  431. } );
  432. it( 'converts data in the specified context', () => {
  433. const model = new Model();
  434. model.schema.register( 'foo' );
  435. model.schema.extend( '$text', { allowIn: 'foo' } );
  436. expect( () => {
  437. parse( 'text', model.schema, { context: [ 'foo' ] } );
  438. } ).to.not.throw();
  439. } );
  440. describe( 'selection', () => {
  441. test( 'sets collapsed selection in an element', {
  442. data: '<a>[]</a>',
  443. check( root, selection ) {
  444. expect( selection.getFirstPosition().parent ).to.have.property( 'name', 'a' );
  445. }
  446. } );
  447. test( 'sets collapsed selection between elements', {
  448. data: '<a></a>[]<b></b>'
  449. } );
  450. test( 'sets collapsed selection before a text', {
  451. data: '<a></a>[]foo'
  452. } );
  453. test( 'sets collapsed selection after a text', {
  454. data: 'foo[]'
  455. } );
  456. test( 'sets collapsed selection within a text', {
  457. data: 'foo[]bar',
  458. check( text, selection ) {
  459. expect( text.offsetSize ).to.equal( 6 );
  460. expect( text.getPath() ).to.deep.equal( [ 0 ] );
  461. expect( selection.getFirstRange().start.path ).to.deep.equal( [ 3 ] );
  462. expect( selection.getFirstRange().end.path ).to.deep.equal( [ 3 ] );
  463. }
  464. } );
  465. it( 'sets selection attributes', () => {
  466. const result = parse( 'foo[]bar', model.schema, {
  467. selectionAttributes: {
  468. bold: true,
  469. italic: true
  470. }
  471. } );
  472. expect( stringify( result.model, result.selection ) ).to.equal( 'foo<$text bold="true" italic="true">[]</$text>bar' );
  473. } );
  474. test( 'sets collapsed selection between text and text with attributes', {
  475. data: 'foo[]<$text bold="true">bar</$text>',
  476. check( root, selection ) {
  477. expect( root.maxOffset ).to.equal( 6 );
  478. expect( selection.getAttribute( 'bold' ) ).to.be.undefined;
  479. }
  480. } );
  481. test( 'sets selection containing an element', {
  482. data: 'x[<a></a>]'
  483. } );
  484. it( 'sets selection with attribute containing an element', () => {
  485. const result = parse( 'x[<a></a>]', model.schema, {
  486. selectionAttributes: {
  487. bold: true
  488. }
  489. } );
  490. expect( stringify( result.model, result.selection ) ).to.equal( 'x[<a></a>]' );
  491. expect( result.selection.getAttribute( 'bold' ) ).to.be.true;
  492. } );
  493. it( 'sets a backward selection containing an element', () => {
  494. const result = parse( 'x[<a></a>]', model.schema, {
  495. lastRangeBackward: true
  496. } );
  497. expect( stringify( result.model, result.selection ) ).to.equal( 'x[<a></a>]' );
  498. expect( result.selection.isBackward ).to.true;
  499. } );
  500. test( 'sets selection within a text', {
  501. data: 'x[y]z'
  502. } );
  503. it( 'sets selection within a text with different attributes', () => {
  504. const result = parse( '<$text bold="true">fo[o</$text>ba]r', model.schema, {
  505. selectionAttributes: { bold: true }
  506. } );
  507. expect( stringify( result.model, result.selection ) ).to.equal( '<$text bold="true">fo[o</$text>ba]r' );
  508. expect( result.selection.getAttribute( 'bold' ) ).to.true;
  509. } );
  510. it( 'throws when missing selection start', () => {
  511. expect( () => {
  512. parse( 'foo]', model.schema );
  513. } ).to.throw( Error, /^Parse error/ );
  514. } );
  515. it( 'throws when missing selection end', () => {
  516. expect( () => {
  517. parse( '[foo', model.schema );
  518. } ).to.throw( Error, /^Parse error/ );
  519. } );
  520. } );
  521. function test( title, options ) {
  522. it( title, () => {
  523. const output = options.output || options.data;
  524. const data = parse( options.data, model.schema );
  525. let converted, selection;
  526. if ( data.selection && data.model ) {
  527. converted = data.model;
  528. selection = data.selection;
  529. } else {
  530. converted = data;
  531. }
  532. expect( stringify( converted, selection ) ).to.equal( output );
  533. if ( options.check ) {
  534. options.check( converted, selection );
  535. }
  536. } );
  537. }
  538. } );
  539. } );