summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-15 14:07:26 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-15 14:07:26 +0100
commit354fe1274242bef87b739dbe43cdb634ea573662 (patch)
treed4a7c1f48878ba4eb6793535cc42a516a143bc0e /test
parent1b19c6660303cb6ce98ac0ad76580f66b52985f1 (diff)
downloadgitbook-354fe1274242bef87b739dbe43cdb634ea573662.zip
gitbook-354fe1274242bef87b739dbe43cdb634ea573662.tar.gz
gitbook-354fe1274242bef87b739dbe43cdb634ea573662.tar.bz2
Fix addBlock for template engine
Add test for code block
Diffstat (limited to 'test')
-rw-r--r--test/page.js34
-rw-r--r--test/template.js24
2 files changed, 55 insertions, 3 deletions
diff --git a/test/page.js b/test/page.js
index fb3e3e5..b947519 100644
--- a/test/page.js
+++ b/test/page.js
@@ -8,7 +8,13 @@ describe('Page', function() {
return mock.setupDefaultBook({
'heading.md': '# Hello\n\n## World',
'links.md': '[link](hello.md) [readme](README.md)',
+
+ 'codes/simple.md': '```hello world```',
+ 'codes/lang.md': '```js\nhello world\n```',
+ 'codes/lang.adoc': '```js\nhello world\n```',
+
'folder/paths.md': '',
+
'variables/file/mtime.md': '{{ file.mtime }}',
'variables/file/path.md': '{{ file.path }}',
'variables/page/title.md': '{{ page.title }}',
@@ -86,6 +92,34 @@ describe('Page', function() {
});
});
+ describe('Code Blocks', function() {
+ var page;
+
+ before(function() {
+ output.template.addBlock('code', function(blk) {
+ return (blk.kwargs.language || '') + blk.body + 'test';
+ });
+ });
+
+ it('should apply "code" block', function() {
+ page = book.addPage('codes/simple.md');
+ return page.toHTML(output)
+ .should.be.fulfilledWith('<p><code>hello worldtest</code></p>\n');
+ });
+
+ it('should add language as kwargs', function() {
+ page = book.addPage('codes/lang.md');
+ return page.toHTML(output)
+ .should.be.fulfilledWith('<pre><code class="lang-js">jshello world\ntest</code></pre>\n');
+ });
+
+ it('should add language as kwargs (asciidoc)', function() {
+ page = book.addPage('codes/lang.adoc');
+ return page.toHTML(output)
+ .should.be.fulfilledWith('<div class="listingblock">\n<div class="content">\n<pre class="highlight"><code class="language-js" data-lang="js">jshello worldtest</code></pre>\n</div>\n</div>');
+ });
+ });
+
describe('Links', function() {
var page;
diff --git a/test/template.js b/test/template.js
index 536043d..d12a641 100644
--- a/test/template.js
+++ b/test/template.js
@@ -6,9 +6,7 @@ describe('Template', function() {
var output;
before(function() {
- return mock.outputDefaultBook(Output, {
- 'test.md': 'World'
- })
+ return mock.outputDefaultBook(Output, {})
.then(function(_output) {
output = _output;
});
@@ -25,4 +23,24 @@ describe('Template', function() {
.should.be.fulfilledWith('Version is '+pkg.version);
});
});
+
+ describe('Blocks', function() {
+ it('should correctly add a block', function() {
+ output.template.addBlock('sayhello', function(blk) {
+ return 'Hello ' + blk.body + '!';
+ });
+
+ return output.template.renderString('{% sayhello %}World{% endsayhello %}')
+ .should.be.fulfilledWith('Hello World!');
+ });
+
+ it('should correctly add a block with kwargs', function() {
+ output.template.addBlock('sayhello_kwargs', function(blk) {
+ return 'Hello ' + blk.kwargs.name + '!';
+ });
+
+ return output.template.renderString('{% sayhello_kwargs name="World" %}{% endsayhello_kwargs %}')
+ .should.be.fulfilledWith('Hello World!');
+ });
+ });
});