UNPKG

2.75 kBJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3var assert = require('assert');
4
5var summary = require('../../src/parse/summary.js');
6
7describe('Summary parsing', function () {
8 var LEXED, PART;
9 var LEXED_EMPTY;
10
11 before(function() {
12 var CONTENT = fs.readFileSync(
13 path.join(__dirname, './fixtures/summary.html'), 'utf8');
14 LEXED = summary(CONTENT);
15 PART = LEXED[0];
16
17 var CONTENT_EMPTY = fs.readFileSync(
18 path.join(__dirname, './fixtures/summary-empty.html'), 'utf8');
19 LEXED_EMPTY = summary(CONTENT_EMPTY);
20 });
21
22 describe('Parts', function() {
23 it('should detect parts', function() {
24 assert.equal(LEXED.length, 3);
25 });
26
27 it('should detect title', function() {
28 assert.equal(LEXED[0].title, '');
29 assert.equal(LEXED[1].title, 'Part 2');
30 assert.equal(LEXED[2].title, '');
31 });
32
33 it('should detect empty parts', function() {
34 var partTitles = LEXED_EMPTY.map(function (part) {
35 return part.title;
36 });
37 var expectedTitles = [
38 'First empty part',
39 'Part 1',
40 '',
41 'Empty part',
42 'Part 2',
43 'Penultimate empty part',
44 'Last empty part'
45 ];
46 assert.equal(LEXED_EMPTY.length, 7);
47 expectedTitles.forEach(function (title, index) {
48 assert.equal(partTitles[index], title);
49 });
50 });
51 });
52
53 it('should detect chapters', function() {
54 assert.equal(PART.articles.length, 5);
55 });
56
57 it('should detect chapters in other parts', function() {
58 assert.equal(LEXED[1].articles.length, 1);
59 });
60
61 it('should support articles', function() {
62 assert.equal(PART.articles[0].articles.length, 2);
63 assert.equal(PART.articles[1].articles.length, 0);
64 assert.equal(PART.articles[2].articles.length, 0);
65 });
66
67 it('should detect paths and titles', function() {
68 assert(PART.articles[0].ref);
69 assert(PART.articles[1].ref);
70 assert(PART.articles[2].ref);
71 assert(PART.articles[3].ref);
72 assert.equal(PART.articles[4].ref, null);
73
74 assert(PART.articles[0].title);
75 assert(PART.articles[1].title);
76 assert(PART.articles[2].title);
77 assert(PART.articles[3].title);
78 assert(PART.articles[4].title);
79 });
80
81 it('should normalize paths from .md', function() {
82 assert.equal(PART.articles[0].ref,'chapter-1/README.md');
83 assert.equal(PART.articles[1].ref,'chapter-2/README.md');
84 assert.equal(PART.articles[2].ref,'chapter-3/README.md');
85 });
86});
\No newline at end of file