Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(post): adding extra test cases #4238

Merged
merged 1 commit into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions test/fixtures/post_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const code = [
' sleep()'
].join('\n');

const content = [
exports.content = [
'# Title',
'``` python',
code,
Expand All @@ -24,8 +24,6 @@ const content = [
'{% endquote %}'
].join('\n');

exports.content = content;

exports.expected = [
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
highlight(code, {lang: 'python'}),
Expand All @@ -50,3 +48,27 @@ exports.expected_disable_nunjucks = [
'quote content<br>',
'{% endquote %}</p>'
].join('');

exports.content_for_issue_3346 = [
'# Title',
'```',
'{% test1 %}',
'{{ test2 }}',
'```',
'some content',
'',
'## Another title',
'{% blockquote %}',
'quote content',
'{% endblockquote %}'
].join('\n');

exports.expected_for_issue_3346 = [
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
highlight('{% test1 %}\n{{ test2 }}').replace(/{/g, '&#123;').replace(/}/g, '&#125;'), // Escaped by backtick_code_block
'\n<p>some content</p>\n',
'<h2 id="Another-title"><a href="#Another-title" class="headerlink" title="Another title"></a>Another title</h2>',
'<blockquote>',
'<p>quote content</p>\n',
'</blockquote>'
].join('');
48 changes: 48 additions & 0 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,52 @@ describe('Post', () => {
});
});

// test for Issue #3346
it('render() - swig tag inside backtick code block', async () => {
const content = fixture.content_for_issue_3346;

const data = await post.render(null, {
content,
engine: 'markdown'
});

data.content.trim().should.eql(fixture.expected_for_issue_3346);
});

// test for https://github.com/hexojs/hexo/pull/4171#issuecomment-594412367
it('render() - markdown content right after swig tag', async () => {
const content = [
'{% pullquote warning %}',
'Text',
'{% endpullquote %}',
'# Title 0',
'{% pullquote warning %}',
'Text',
'{% endpullquote %}',
'{% pullquote warning %}',
'Text',
'{% endpullquote %}',
'# Title 1',
'{% pullquote warning %}',
'Text',
'{% endpullquote %}',
'{% pullquote warning %}Text{% endpullquote %}',
'# Title 2',
'{% pullquote warning %}Text{% endpullquote %}',
'{% pullquote warning %}Text{% endpullquote %}',
'# Title 3',
'{% pullquote warning %}Text{% endpullquote %}'
].join('\n');

const data = await post.render(null, {
content,
engine: 'markdown'
});

// We only to make sure markdown content is rendered correctly
data.content.trim().should.include('<h1 id="Title-0"><a href="#Title-0" class="headerlink" title="Title 0"></a>Title 0</h1>');
data.content.trim().should.include('<h1 id="Title-1"><a href="#Title-1" class="headerlink" title="Title 1"></a>Title 1</h1>');
data.content.trim().should.include('<h1 id="Title-2"><a href="#Title-2" class="headerlink" title="Title 2"></a>Title 2</h1>');
data.content.trim().should.include('<h1 id="Title-3"><a href="#Title-3" class="headerlink" title="Title 3"></a>Title 3</h1>');
});
});