diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/ALTERNATIVE_SUMMARY.md | 13 | ||||
-rw-r--r-- | test/navigation.js | 17 | ||||
-rw-r--r-- | test/summary.js | 30 |
3 files changed, 47 insertions, 13 deletions
diff --git a/test/fixtures/ALTERNATIVE_SUMMARY.md b/test/fixtures/ALTERNATIVE_SUMMARY.md new file mode 100644 index 0000000..e0d0114 --- /dev/null +++ b/test/fixtures/ALTERNATIVE_SUMMARY.md @@ -0,0 +1,13 @@ +# Summary + +* [Custom name for Introduction](README.md) +* [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/test/navigation.js b/test/navigation.js index 0330d74..df29509 100644 --- a/test/navigation.js +++ b/test/navigation.js @@ -7,7 +7,9 @@ var navigation = require('../').parse.navigation; var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8'); +var ALT_CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/ALTERNATIVE_SUMMARY.md'), 'utf8'); var LEXED = summary(CONTENT); +var ALT_LEXED = summary(ALT_CONTENT); describe('Summary navigation', function() { @@ -76,6 +78,21 @@ describe('Summary navigation', function() { assert.equal(nav['chapter-3/README.md'].level, '3'); }); + it('should have a default README node', function() { + var nav = navigation(LEXED); + + assert.equal(nav['README.md'].level, '0'); + assert.equal(nav['README.md'].title, 'Introduction'); + }); + + it('Should allow README node to be customized', function() { + var nav = navigation(ALT_LEXED); + + assert(nav['README.md']); + assert.equal(nav['README.md'].level, '0'); + assert.notEqual(nav['README.md'].title, 'Introduction'); + }); + it('should not accept null paths', function() { var nav = navigation(LEXED); diff --git a/test/summary.js b/test/summary.js index 0316b31..2993817 100644 --- a/test/summary.js +++ b/test/summary.js @@ -12,13 +12,13 @@ var LEXED = summary(CONTENT); describe('Summary parsing', function () { it('should detect chapters', function() { - assert.equal(LEXED.chapters.length, 5); + assert.equal(LEXED.chapters.length, 6); }); it('should support articles', function() { - assert.equal(LEXED.chapters[0].articles.length, 2); - assert.equal(LEXED.chapters[1].articles.length, 0); + 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() { @@ -26,30 +26,34 @@ describe('Summary parsing', function () { assert(LEXED.chapters[1].path); assert(LEXED.chapters[2].path); assert(LEXED.chapters[3].path); - assert.equal(LEXED.chapters[4].path, null); + 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,'chapter-1/README.md'); - assert.equal(LEXED.chapters[1].path,'chapter-2/README.md'); - assert.equal(LEXED.chapters[2].path,'chapter-3/README.md'); + 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, '1'); - assert.equal(c[1].level, '2'); - assert.equal(c[2].level, '3'); + 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[0].articles[0].level, '1.1'); - assert.equal(c[0].articles[1].level, '1.2'); - assert.equal(c[0].articles[1].articles[0].level, '1.2.1'); + 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'); }); }); |