diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 10:24:43 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 15:00:28 +0100 |
commit | 3f1041209582c26abc595be9c2c99189f5b85f3f (patch) | |
tree | 9bd3ef143b64712bee64b293e74e5a0dfe48e6fd /packages/gitbook-markdown/test | |
parent | 8e513c8e60063358286fc286037da1969f17bba0 (diff) | |
download | gitbook-3f1041209582c26abc595be9c2c99189f5b85f3f.zip gitbook-3f1041209582c26abc595be9c2c99189f5b85f3f.tar.gz gitbook-3f1041209582c26abc595be9c2c99189f5b85f3f.tar.bz2 |
Add base summary parser and test associated
Diffstat (limited to 'packages/gitbook-markdown/test')
-rw-r--r-- | packages/gitbook-markdown/test/fixtures/SUMMARY.md | 12 | ||||
-rw-r--r-- | packages/gitbook-markdown/test/summary.js | 59 |
2 files changed, 71 insertions, 0 deletions
diff --git a/packages/gitbook-markdown/test/fixtures/SUMMARY.md b/packages/gitbook-markdown/test/fixtures/SUMMARY.md new file mode 100644 index 0000000..3bf4a88 --- /dev/null +++ b/packages/gitbook-markdown/test/fixtures/SUMMARY.md @@ -0,0 +1,12 @@ +# Summary + +* [Chapter 1](chapter-1/README.md) + * [Article 1](chapter-1/ARTICLE1.md) + * [Article 2](chapter-1/ARTICLE2.md) + * [article 1.2.1](\chapter-1\ARTICLE-1-2-1.md) + * [article 1.2.2](/chapter-1/ARTICLE-1-2-2.md) +* [Chapter 2](chapter-2/README.md) +* [Chapter 3](chapter-3/README.md) +* [Chapter 4](chapter-4/README.md) + * Unfinished article +* Unfinished Chapter diff --git a/packages/gitbook-markdown/test/summary.js b/packages/gitbook-markdown/test/summary.js new file mode 100644 index 0000000..2993817 --- /dev/null +++ b/packages/gitbook-markdown/test/summary.js @@ -0,0 +1,59 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var summary = require('../').parse.summary; + + +var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8'); +var LEXED = summary(CONTENT); + + +describe('Summary parsing', function () { + + it('should detect chapters', function() { + assert.equal(LEXED.chapters.length, 6); + }); + + it('should support articles', function() { + assert.equal(LEXED.chapters[1].articles.length, 2); + assert.equal(LEXED.chapters[2].articles.length, 0); + assert.equal(LEXED.chapters[3].articles.length, 0); + }); + + it('should detect paths and titles', function() { + assert(LEXED.chapters[0].path); + assert(LEXED.chapters[1].path); + assert(LEXED.chapters[2].path); + assert(LEXED.chapters[3].path); + assert(LEXED.chapters[4].path); + assert.equal(LEXED.chapters[5].path, null); + + assert(LEXED.chapters[0].title); + assert(LEXED.chapters[1].title); + assert(LEXED.chapters[2].title); + assert(LEXED.chapters[3].title); + assert(LEXED.chapters[4].title); + assert(LEXED.chapters[5].title); + }); + + it('should normalize paths from .md to .html', function() { + assert.equal(LEXED.chapters[0].path,'README.md'); + assert.equal(LEXED.chapters[1].path,'chapter-1/README.md'); + assert.equal(LEXED.chapters[2].path,'chapter-2/README.md'); + assert.equal(LEXED.chapters[3].path,'chapter-3/README.md'); + }); + + it('should detect levels correctly', function() { + var c = LEXED.chapters; + + assert.equal(c[0].level, '0'); + assert.equal(c[1].level, '1'); + assert.equal(c[2].level, '2'); + assert.equal(c[3].level, '3'); + + assert.equal(c[1].articles[0].level, '1.1'); + assert.equal(c[1].articles[1].level, '1.2'); + assert.equal(c[1].articles[1].articles[0].level, '1.2.1'); + }); +}); |