Browse Source

Aligned some of the tests with the current expected behavior of features after the recent dependencies upgrade.

fredck 5 years ago
parent
commit
8b63c53984

+ 2 - 1
packages/ckeditor5-markdown-gfm/src/markdown2html/markdown2html.js

@@ -14,6 +14,7 @@ export default function markdown2html( markdown ) {
 		gfm: true,
 		breaks: true,
 		tables: true,
-		xhtml: true
+		xhtml: true,
+		headerIds: false
 	} );
 }

+ 18 - 2
packages/ckeditor5-markdown-gfm/tests/_utils/utils.js

@@ -21,11 +21,27 @@ export function testDataProcessor( markdown, viewString, normalizedMarkdown ) {
 	const dataProcessor = new MarkdownDataProcessor( viewDocument );
 	const viewFragment = dataProcessor.toView( markdown );
 
+	const html = cleanHtml( stringify( viewFragment ) );
+
 	// Check if view has correct data.
-	expect( stringify( viewFragment ) ).to.equal( viewString );
+	expect( html ).to.equal( viewString );
 
 	// Check if converting back gives the same result.
 	const normalized = typeof normalizedMarkdown !== 'undefined' ? normalizedMarkdown : markdown;
 
-	expect( dataProcessor.toData( viewFragment ) ).to.equal( normalized );
+	expect( cleanMarkdown( dataProcessor.toData( viewFragment ) ) ).to.equal( normalized );
+}
+
+function cleanHtml( html ) {
+	// Space between table elements.
+	html = html.replace( /(th|td|tr)>\s+<(\/?(?:th|td|tr))/g, '$1><$2' );
+	return html;
+}
+
+function cleanMarkdown( markdown ) {
+	// Trim spaces at the end of the lines.
+	markdown = markdown.replace( /\s+$/gm, '' );
+	// Trim linebreak at the very beginning.
+	markdown = markdown.replace( /^\n/g, '' );
+	return markdown;
 }

+ 9 - 9
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/blockquotes.js

@@ -23,9 +23,9 @@ describe( 'GFMDataProcessor', () => {
 		it( 'should process nested blockquotes', () => {
 			testDataProcessor(
 				'> foo\n' +
-				'> \n' +
+				'>\n' +
 				'> > bar\n' +
-				'> \n' +
+				'>\n' +
 				'> foo',
 
 				// GitHub is rendering as:
@@ -51,7 +51,7 @@ describe( 'GFMDataProcessor', () => {
 		it( 'should process list within a blockquote', () => {
 			testDataProcessor(
 				'> A list within a blockquote:\n' +
-				'> \n' +
+				'>\n' +
 				'> *   asterisk 1\n' +
 				'> *   asterisk 2\n' +
 				'> *   asterisk 3',
@@ -80,13 +80,13 @@ describe( 'GFMDataProcessor', () => {
 		it( 'should process blockquotes with code inside with ```', () => {
 			testDataProcessor(
 				'> Example 1:\n' +
-				'> \n' +
+				'>\n' +
 				'> ```\n' +
 				'> code 1\n' +
 				'> ```\n' +
-				'> \n' +
+				'>\n' +
 				'> Example 2:\n' +
-				'> \n' +
+				'>\n' +
 				'> ```\n' +
 				'> code 2\n' +
 				'> ```',
@@ -159,13 +159,13 @@ describe( 'GFMDataProcessor', () => {
 
 				// When converting back to data, DataProcessor will normalize tabs to ```.
 				'> Example 1:\n' +
-				'> \n' +
+				'>\n' +
 				'> ```\n' +
 				'> code 1\n' +
 				'> ```\n' +
-				'> \n' +
+				'>\n' +
 				'> Example 2:\n' +
-				'> \n' +
+				'>\n' +
 				'> ```\n' +
 				'> code 2\n' +
 				'> ```'

+ 18 - 18
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/code.js

@@ -45,7 +45,7 @@ describe( 'GFMDataProcessor', () => {
 
 		it( 'should properly process backticks inside code spans #2', () => {
 			testDataProcessor(
-				'`` some `backticks` inside ``',
+				'``some `backticks` inside``',
 
 				'<p><code>some `backticks` inside</code></p>'
 			);
@@ -142,17 +142,17 @@ describe( 'GFMDataProcessor', () => {
 				'<pre><code>the lines in this block  \n' +
 				'all contain trailing spaces  </code></pre>',
 
-				// When converting back tabs are normalized to ```.
+				// When converting back tabs are normalized to ```, while the test function remove trailing spaces.
 				'```\n' +
-				'the lines in this block  \n' +
-				'all contain trailing spaces  \n' +
+				'the lines in this block\n' +
+				'all contain trailing spaces\n' +
 				'```'
 			);
 		} );
 
 		it( 'should process code block with language name', () => {
 			testDataProcessor(
-				'``` js\n' +
+				'```js\n' +
 				'var a = \'hello\';\n' +
 				'console.log(a + \' world\');\n' +
 				'```',
@@ -160,7 +160,7 @@ describe( 'GFMDataProcessor', () => {
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-js">var a = \'hello\';\n' +
+				'<pre><code class="language-js">var a = \'hello\';\n' +
 				'console.log(a + \' world\');</code></pre>'
 			);
 		} );
@@ -174,11 +174,11 @@ describe( 'GFMDataProcessor', () => {
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-bash">#!/bin/bash</code></pre>',
+				'<pre><code class="language-bash">#!/bin/bash</code></pre>',
 
 				// When converting back ~~~ are normalized to ```.
 
-				'``` bash\n' +
+				'```bash\n' +
 				'#!/bin/bash\n' +
 				'```'
 			);
@@ -186,7 +186,7 @@ describe( 'GFMDataProcessor', () => {
 
 		it( 'should process code block with language name and using ``````` as delimiter', () => {
 			testDataProcessor(
-				'``````` js\n' +
+				'```````js\n' +
 				'var a = \'hello\';\n' +
 				'console.log(a + \' world\');\n' +
 				'```````',
@@ -194,12 +194,12 @@ describe( 'GFMDataProcessor', () => {
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-js">var a = \'hello\';\n' +
+				'<pre><code class="language-js">var a = \'hello\';\n' +
 				'console.log(a + \' world\');</code></pre>',
 
 				// When converting back ``````` are normalized to ```.
 
-				'``` js\n' +
+				'```js\n' +
 				'var a = \'hello\';\n' +
 				'console.log(a + \' world\');\n' +
 				'```'
@@ -216,12 +216,12 @@ describe( 'GFMDataProcessor', () => {
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-js">var a = \'hello\';\n' +
+				'<pre><code class="language-js">var a = \'hello\';\n' +
 				'console.log(a + \' world\');</code></pre>',
 
 				// When converting back ~~~~~~~~~~ are normalized to ```.
 
-				'``` js\n' +
+				'```js\n' +
 				'var a = \'hello\';\n' +
 				'console.log(a + \' world\');\n' +
 				'```'
@@ -230,13 +230,13 @@ describe( 'GFMDataProcessor', () => {
 
 		it( 'should process empty code block', () => {
 			testDataProcessor(
-				'``` js\n' +
+				'```js\n' +
 				'```',
 
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-js"></code></pre>',
+				'<pre><code class="language-js"></code></pre>',
 
 				// When converting back, empty code blocks will be removed.
 				// This might be an issue when switching from source to editor
@@ -247,14 +247,14 @@ describe( 'GFMDataProcessor', () => {
 
 		it( 'should process code block with empty line', () => {
 			testDataProcessor(
-				'``` js\n' +
+				'```js\n' +
 				'\n' +
 				'```',
 
 				// GitHub is rendering as special html with syntax highlighting.
 				// We will need to handle this separately by some feature.
 
-				'<pre><code class="lang-js"></code></pre>',
+				'<pre><code class="language-js"></code></pre>',
 
 				// When converting back, empty code blocks will be removed.
 				// This might be an issue when switching from source to editor
@@ -273,7 +273,7 @@ describe( 'GFMDataProcessor', () => {
 				'<p><code>code `` code ```</code></p>',
 
 				// When converting back ````` will be normalized to ``.
-				'`` code `` code ``` ``'
+				'`code `` code ``` `'
 			);
 		} );
 	} );

+ 12 - 2
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/headers.js

@@ -95,7 +95,11 @@ describe( 'GFMDataProcessor', () => {
 				'# header\n' +
 				'# header',
 
-				'<h1>header</h1><h1>header</h1>'
+				'<h1>header</h1><h1>header</h1>',
+
+				'# header\n' +
+				'\n' +
+				'# header'
 			);
 		} );
 
@@ -105,7 +109,13 @@ describe( 'GFMDataProcessor', () => {
 				'## header\n' +
 				'### header',
 
-				'<h1>header</h1><h2>header</h2><h3>header</h3>'
+				'<h1>header</h1><h2>header</h2><h3>header</h3>',
+
+				'# header\n' +
+				'\n' +
+				'## header\n' +
+				'\n' +
+				'### header'
 			);
 		} );
 

+ 26 - 26
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/horizontal-rules.js

@@ -6,24 +6,24 @@
 import { testDataProcessor } from '../_utils/utils';
 
 describe( 'GFMDataProcessor', () => {
-	// Horizontal rules are are always rendered by GitHub as <hr> and normalized when converting
-	// back to * * *.
+	// Horizontal rules are always rendered by GitHub as <hr> and normalized when converting
+	// back to ---.
 	describe( 'horizontal rules', () => {
 		describe( 'dashes', () => {
 			it( '#1', () => {
-				testDataProcessor( '---', '<hr></hr>', '* * *' );
+				testDataProcessor( '---', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' ---', '<hr></hr>', '* * *' );
+				testDataProcessor( ' ---', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  ---', '<hr></hr>', '* * *' );
+				testDataProcessor( '  ---', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   ---', '<hr></hr>', '* * *' );
+				testDataProcessor( '   ---', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {
@@ -43,19 +43,19 @@ describe( 'GFMDataProcessor', () => {
 
 		describe( 'dashes with spaces', () => {
 			it( '#1', () => {
-				testDataProcessor( '- - -', '<hr></hr>', '* * *' );
+				testDataProcessor( '- - -', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' - - -', '<hr></hr>', '* * *' );
+				testDataProcessor( ' - - -', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  - - -', '<hr></hr>', '* * *' );
+				testDataProcessor( '  - - -', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   - - -', '<hr></hr>', '* * *' );
+				testDataProcessor( '   - - -', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {
@@ -75,19 +75,19 @@ describe( 'GFMDataProcessor', () => {
 
 		describe( 'asterisks', () => {
 			it( '#1', () => {
-				testDataProcessor( '***', '<hr></hr>', '* * *' );
+				testDataProcessor( '***', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' ***', '<hr></hr>', '* * *' );
+				testDataProcessor( ' ***', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  ***', '<hr></hr>', '* * *' );
+				testDataProcessor( '  ***', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   ***', '<hr></hr>', '* * *' );
+				testDataProcessor( '   ***', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {
@@ -107,19 +107,19 @@ describe( 'GFMDataProcessor', () => {
 
 		describe( 'asterisks with spaces', () => {
 			it( '#1', () => {
-				testDataProcessor( '* * *', '<hr></hr>', '* * *' );
+				testDataProcessor( '* * *', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' * * *', '<hr></hr>', '* * *' );
+				testDataProcessor( ' * * *', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  * * *', '<hr></hr>', '* * *' );
+				testDataProcessor( '  * * *', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   * * *', '<hr></hr>', '* * *' );
+				testDataProcessor( '   * * *', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {
@@ -139,19 +139,19 @@ describe( 'GFMDataProcessor', () => {
 
 		describe( 'underscores', () => {
 			it( '#1', () => {
-				testDataProcessor( '___', '<hr></hr>', '* * *' );
+				testDataProcessor( '___', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' ___', '<hr></hr>', '* * *' );
+				testDataProcessor( ' ___', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  ___', '<hr></hr>', '* * *' );
+				testDataProcessor( '  ___', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   ___', '<hr></hr>', '* * *' );
+				testDataProcessor( '   ___', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {
@@ -171,19 +171,19 @@ describe( 'GFMDataProcessor', () => {
 
 		describe( 'underscores with spaces', () => {
 			it( '#1', () => {
-				testDataProcessor( '_ _ _', '<hr></hr>', '* * *' );
+				testDataProcessor( '_ _ _', '<hr></hr>', '---' );
 			} );
 
 			it( '#2', () => {
-				testDataProcessor( ' _ _ _', '<hr></hr>', '* * *' );
+				testDataProcessor( ' _ _ _', '<hr></hr>', '---' );
 			} );
 
 			it( '#3', () => {
-				testDataProcessor( '  _ _ _', '<hr></hr>', '* * *' );
+				testDataProcessor( '  _ _ _', '<hr></hr>', '---' );
 			} );
 
 			it( '#4', () => {
-				testDataProcessor( '   _ _ _', '<hr></hr>', '* * *' );
+				testDataProcessor( '   _ _ _', '<hr></hr>', '---' );
 			} );
 
 			it( '#5 - code', () => {

+ 5 - 24
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/paragraphs.js

@@ -38,11 +38,7 @@ describe( 'GFMDataProcessor', () => {
 				// <p>single line</p>
 				//
 				// <h1>header</h1>
-				'<p>single line</p><h1>header</h1>',
-
-				// To-markdown always put 2 empty lines after paragraph.
-				'single line\n\n' +
-				'# header'
+				'<p>single line</p><h1>header</h1>'
 			);
 		} );
 
@@ -56,12 +52,7 @@ describe( 'GFMDataProcessor', () => {
 				// <p>single line</p>
 				//
 				// <h1>header</h1>
-				'<p>single line</p><h1>header</h1>',
-
-				// To-markdown always put 2 empty lines after paragraph and normalize header to #.
-				'single line\n' +
-				'\n' +
-				'# header'
+				'<p>single line</p><h1>header</h1>'
 			);
 		} );
 
@@ -76,19 +67,14 @@ describe( 'GFMDataProcessor', () => {
 				// <blockquote>
 				// <p>quote</p>
 				// </blockquote>
-				'<p>single line</p><blockquote><p>quote</p></blockquote>',
-
-				// To-markdown always put 2 empty lines after paragraph.
-				'single line\n' +
-				'\n' +
-				'> quote'
+				'<p>single line</p><blockquote><p>quote</p></blockquote>'
 			);
 		} );
 
 		it( 'with list after', () => {
 			testDataProcessor(
 				'single line\n' +
-				'* item',
+				'*   item',
 
 				// GitHub is rendering as:
 				// <p>single line</p>
@@ -96,12 +82,7 @@ describe( 'GFMDataProcessor', () => {
 				// <ul>
 				// <li>item</li>
 				// </ul>
-				'<p>single line</p><ul><li>item</li></ul>',
-
-				// To-markdown always put 2 empty lines after paragraph.
-				'single line\n' +
-				'\n' +
-				'*   item'
+				'<p>single line</p><ul><li>item</li></ul>'
 			);
 		} );
 

+ 12 - 0
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/strong-emphasis.js

@@ -78,6 +78,18 @@ describe( 'GFMDataProcessor', () => {
 			testDataProcessor(
 				'This should_not_be_emp.',
 
+				'<p>This should_not_be_emp.</p>',
+
+				// Turndow escape markdown markup characters used inside text.
+				'This should\\_not\\_be\\_emp.',
+			);
+		} );
+
+		it( 'should not render escape marks', () => {
+			testDataProcessor(
+				// Following the previous test.
+				'This should\\_not\\_be\\_emp.',
+
 				'<p>This should_not_be_emp.</p>'
 			);
 		} );