Explorar o código

Added tests to blockquotes and escaping characters.

Szymon Kupś %!s(int64=9) %!d(string=hai) anos
pai
achega
c91d7f5a8b

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

@@ -28,9 +28,61 @@ describe( 'GFMDataProcessor', () => {
 			} );
 
 			it( 'should process list within a blockquote', () => {
-				const viewFragment = dataProcessor.toView( '> A list within a blockquote:\n> \n> *	asterisk 1\n> *	asterisk 2\n> *	asterisk 3\n' );
+				const viewFragment = dataProcessor.toView(
+					'> A list within a blockquote:\n' +
+					'> \n' +
+					'> *	asterisk 1\n' +
+					'> *	asterisk 2\n' +
+					'> *	asterisk 3\n'
+				);
 
-				expect( stringify( viewFragment ) ).to.equal( '<blockquote><p>A list within a blockquote:</p><ul><li>asterisk 1</li><li>asterisk 2</li><li>asterisk 3</li></ul></blockquote>' );
+				expect( stringify( viewFragment ) ).to.equal(
+					'<blockquote>' +
+						'<p>A list within a blockquote:</p>' +
+						'<ul>' +
+							'<li>asterisk 1</li>' +
+							'<li>asterisk 2</li>' +
+							'<li>asterisk 3</li>' +
+						'</ul>' +
+					'</blockquote>'
+				);
+			} );
+
+			it( 'should process blockquotes with code inside', () => {
+				const viewFragment = dataProcessor.toView(
+					'> Example 1:\n' +
+					'>\n' +
+					'>     sub status {\n' +
+					'>         print "working";\n' +
+					'>     }\n' +
+					'>\n' +
+					'> Example 2:\n' +
+					'>\n' +
+					'>     sub status {\n' +
+					'>         return "working";\n' +
+					'>     }\n'
+				);
+
+				expect( stringify( viewFragment ) ).to.equal(
+					'<blockquote>' +
+						'<p>Example 1:</p>' +
+						'<pre>' +
+							'<code>' +
+								'sub status {\n' +
+								'    print "working";\n' +
+								'}' +
+							'</code>' +
+						'</pre>' +
+						'<p>Example 2:</p>' +
+						'<pre>' +
+							'<code>' +
+								'sub status {\n' +
+								'    return "working";\n' +
+								'}' +
+							'</code>' +
+						'</pre>' +
+					'</blockquote>'
+				);
 			} );
 		} );
 	} );

+ 71 - 0
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/escaping.js

@@ -0,0 +1,71 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import MarkdownDataProcessor from '/ckeditor5/markdown-gfm/gfmdataprocessor.js';
+import { stringify } from '/tests/engine/_utils/view.js';
+
+const testCases = {
+	'backslash': { test: '\\\\', result: '\\' },
+	'underscore': { test: '\\_', result: '_' },
+	'left brace': { test: '\\{', result: '{' },
+	'right brace': { test: '\\}', result: '}' },
+	'left bracket': { test: '\\[', result: '[' },
+	'right bracket': { test: '\\]', result: ']' },
+	'left paren': { test: '\\(', result: '(' },
+	'right paren': { test: '\\)', result: ')' },
+	'greater than': { test: '\\>', result: '>' },
+	'hash': { test: '\\#', result: '#' },
+	'peroid': { test: '\\.', result: '.' },
+	'exclamation mark': { test: '\\!', result: '!' },
+	'plus': { test: '\\+', result: '+' },
+	'minus': { test: '\\-', result: '-' },
+};
+
+describe( 'GFMDataProcessor', () => {
+	let dataProcessor;
+
+	beforeEach( () => {
+		dataProcessor = new MarkdownDataProcessor();
+	} );
+
+	describe( 'escaping', () => {
+		describe( 'toView', () => {
+			for ( let key in testCases ) {
+				const test = testCases[ key ].test;
+				const result = testCases[ key ].result;
+
+				it( `should escape ${key}`, () => {
+					const documentFragment = dataProcessor.toView( test );
+
+					expect( stringify( documentFragment ) ).to.equal( `<p>${ result }</p>` );
+				} );
+
+				it( `should not escape ${key} in code blocks`, () => {
+					const documentFragment = dataProcessor.toView( `	${ test }` );
+
+					expect( stringify( documentFragment ) ).to.equal( `<pre><code>${ test }</code></pre>` );
+				} );
+
+				it( `should not escape ${key} in code spans`, () => {
+					const documentFragment = dataProcessor.toView( '`' + test + '`' );
+
+					expect( stringify( documentFragment ) ).to.equal( `<p><code>${ test }</code></p>` );
+				} );
+			}
+
+			it( 'should escape backtick', () => {
+				const documentFragment = dataProcessor.toView( '\\`' );
+
+				expect( stringify( documentFragment ) ).to.equal( '<p>`</p>' );
+			} );
+
+			it( 'should not escape backtick in code blocks', () => {
+				const documentFragment = dataProcessor.toView( '	\\`' );
+
+				expect( stringify( documentFragment ) ).to.equal( '<pre><code>\\`</code></pre>' );
+			} );
+		} );
+	} );
+} );