summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-asciidoc/test/summary.js
blob: 981967ae542325923774e94e49241e90fb9e57f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var fs = require('fs');
var path = require('path');
var assert = require('assert');

var summary = require('../').summary;

describe('Summary parsing', function () {
    var LEXED, PART;

    before(function() {
        var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.adoc'), 'utf8');
        LEXED = summary(CONTENT);
        PART = LEXED.parts[0];
        // todo: add support for parts in asciidoc
    });

    it('should detect parts', function() {
        assert.equal(LEXED.parts.length, 1);
    });

    it('should detect articles', function() {
        assert.equal(PART.articles.length, 5);
    });

    it('should support articles', function() {
        assert.equal(PART.articles[0].articles.length, 2);
        assert.equal(PART.articles[1].articles.length, 0);
        assert.equal(PART.articles[2].articles.length, 0);
    });

    it('should detect paths and titles', function() {
        assert(PART.articles[0].path);
        assert(PART.articles[1].path);
        assert(PART.articles[2].path);
        assert(PART.articles[3].path);
        assert.equal(PART.articles[4].path, null);

        assert(PART.articles[0].title);
        assert(PART.articles[1].title);
        assert(PART.articles[2].title);
        assert(PART.articles[3].title);
        assert(PART.articles[4].title);
    });

    it('should normalize paths from .md', function() {
        assert.equal(PART.articles[0].path,'chapter-1/README.adoc');
        assert.equal(PART.articles[1].path,'chapter-2/README.adoc');
        assert.equal(PART.articles[2].path,'chapter-3/README.adoc');
    });

    it('should correctly convert it to text', function() {
        var text = summary.toText(LEXED);
        assertObjectsEqual(summary(text), LEXED);
    });
});