diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-03-09 10:43:12 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-03-09 10:43:12 +0100 |
commit | 34fc2831e0cf0fed01c71cec28d93472d87f455b (patch) | |
tree | a803cc907c20491ba02863b5d3dd5aedf6bfed10 /test/page.js | |
parent | e1594cde2c32e4ff48f6c4eff3d3d461743d74e1 (diff) | |
parent | 1bf68a5aa0703b5a1815cfe4ebb731b5fb6ed9d2 (diff) | |
download | gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.zip gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.gz gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.bz2 |
Merge branch 'version/2.0'
Diffstat (limited to 'test/page.js')
-rw-r--r-- | test/page.js | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/test/page.js b/test/page.js deleted file mode 100644 index c883367..0000000 --- a/test/page.js +++ /dev/null @@ -1,123 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var page = require('../').parse.page; - -function loadPage (name, options) { - var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8'); - return page(CONTENT, options).sections; -} - -var LEXED = loadPage('PAGE', { - dir: 'course', - outdir: '_book' -}); -var QUIZ_LEXED = loadPage('QUIZ_PAGE'); -var HR_LEXED = loadPage('HR_PAGE'); - -describe('Page parsing', function() { - it('should detect sections', function() { - assert.equal(LEXED.length, 4); - }); - - it('should detect section types', function() { - assert.equal(LEXED[0].type, 'normal'); - assert.equal(LEXED[1].type, 'exercise'); - assert.equal(LEXED[2].type, 'normal'); - assert.equal(QUIZ_LEXED[0].type, 'normal'); - assert.equal(QUIZ_LEXED[1].type, 'quiz'); - assert.equal(QUIZ_LEXED[2].type, 'normal'); - assert.equal(QUIZ_LEXED[3].type, 'quiz'); - }); - - it('should gen content for normal sections', function() { - assert(LEXED[0].content); - assert(LEXED[2].content); - }); - - it('should gen code and content for exercise sections', function() { - assert(LEXED[1].content); - assert(LEXED[1].code); - assert(LEXED[1].code.base); - assert(LEXED[1].code.solution); - assert(LEXED[1].code.validation); - assert(LEXED[1].code.context === null); - - assert(LEXED[3].content); - assert(LEXED[3].code); - assert(LEXED[3].code.base); - assert(LEXED[3].code.solution); - assert(LEXED[3].code.validation); - assert(LEXED[3].code.context); - }); - - it('should merge sections correctly', function() { - // One big section - assert.equal(HR_LEXED.length, 1); - - // HRs inserted correctly - assert.equal(HR_LEXED[0].content.match(/<hr>/g).length, 2); - }); - - it('should detect an exercise\'s language', function() { - assert.equal(LEXED[1].lang, 'python'); - }); - - it('should render a quiz', function() { - assert(QUIZ_LEXED[1].content); - assert(QUIZ_LEXED[1].quiz); - assert(QUIZ_LEXED[1].quiz[0].base); - assert(QUIZ_LEXED[1].quiz[0].solution); - assert(QUIZ_LEXED[1].quiz[0].feedback); - assert(QUIZ_LEXED[1].quiz[1].base); - assert(QUIZ_LEXED[1].quiz[1].solution); - assert(QUIZ_LEXED[1].quiz[1].feedback); - }); -}); - - -describe('Relative links', function() { - it('should replace link to .md by link to .html', function() { - var LEXED = loadPage('MARKDOWN_LINKS', { - // Imaginary folder of markdown file - dir: 'course', - outdir: 'course' - }); - - assert(LEXED[0].content.indexOf('test.html') !== -1); - assert(LEXED[0].content.indexOf('../before.html') !== -1); - }); -}); - -describe('Relative images', function() { - it('should keep image relative with considering output directory in site format', function() { - var LEXED = loadPage('IMAGES', { - // Imaginary folder of markdown file - dir: 'syntax', - outdir: 'syntax' - }); - - assert(LEXED[0].content.indexOf('"preview.png"') !== -1); - assert(LEXED[0].content.indexOf('"../preview2.png"') !== -1); - }); - - it('should keep image relative with considering output directory in page format', function() { - var LEXED = loadPage('IMAGES', { - // Imaginary folder of markdown file - dir: 'syntax', - outdir: './' - }); - - assert(LEXED[0].content.indexOf('"syntax/preview.png"') !== -1); - assert(LEXED[0].content.indexOf('"preview2.png"') !== -1); - }); -}); - -describe('Section parsing', function() { - it('should not have false positive quiz parsing', function() { - var LEXED = loadPage('FALSE_QUIZ'); - - assert.equal(LEXED[0].type, 'normal'); - }); -}); |