utils.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import MarkdownDataProcessor from '../../src/gfmdataprocessor';
  6. import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view.js';
  7. /**
  8. * Tests MarkdownDataProcessor.
  9. *
  10. * @param {String} markdown Markdown to be processed to view.
  11. * @param {String} viewString Expected view structure.
  12. * @param {String} [normalizedMarkdown] When converting back to the markdown it might be different than provided input
  13. * markdown string (which will be used if this parameter is not provided).
  14. */
  15. export function testDataProcessor( markdown, viewString, normalizedMarkdown ) {
  16. const dataProcessor = new MarkdownDataProcessor();
  17. const viewFragment = dataProcessor.toView( markdown );
  18. // Check if view has correct data.
  19. expect( stringify( viewFragment ) ).to.equal( viewString );
  20. // Check if converting back gives the same result.
  21. const normalized = typeof normalizedMarkdown !== 'undefined' ? normalizedMarkdown : markdown;
  22. expect( dataProcessor.toData( viewFragment ) ).to.equal( normalized );
  23. }