summaryrefslogtreecommitdiffstats
path: root/test/parsing.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-03-09 10:43:12 +0100
committerSamy Pessé <samypesse@gmail.com>2015-03-09 10:43:12 +0100
commit34fc2831e0cf0fed01c71cec28d93472d87f455b (patch)
treea803cc907c20491ba02863b5d3dd5aedf6bfed10 /test/parsing.js
parente1594cde2c32e4ff48f6c4eff3d3d461743d74e1 (diff)
parent1bf68a5aa0703b5a1815cfe4ebb731b5fb6ed9d2 (diff)
downloadgitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.zip
gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.gz
gitbook-34fc2831e0cf0fed01c71cec28d93472d87f455b.tar.bz2
Merge branch 'version/2.0'
Diffstat (limited to 'test/parsing.js')
-rw-r--r--test/parsing.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/parsing.js b/test/parsing.js
new file mode 100644
index 0000000..fcda739
--- /dev/null
+++ b/test/parsing.js
@@ -0,0 +1,82 @@
+var path = require('path');
+var _ = require('lodash');
+var assert = require('assert');
+
+describe('Book parsing', function () {
+ it('should correctly parse the readme', function() {
+ assert.equal(books[1].options.title, 'My Book');
+ assert.equal(books[1].options.description, 'Test description');
+ });
+
+ it('should correctly parse the readme with asciidoc', function() {
+ assert.equal(books[3].options.title, 'My Book');
+ assert.equal(books[3].options.description, 'Test description');
+ });
+
+ it('should correctly parse the summary', function() {
+ var LEXED = books[1].summary;
+
+ assert.equal(LEXED.chapters[0].path, 'intro.md');
+ assert.equal(LEXED.chapters[0].exists, true);
+ assert.equal(LEXED.chapters[0].introduction, true);
+ assert.equal(LEXED.chapters[0].external, false);
+
+ assert.equal(LEXED.chapters[1].path, 'test.md');
+ assert.equal(LEXED.chapters[1].exists, false);
+ assert.equal(LEXED.chapters[1].introduction, false);
+ assert.equal(LEXED.chapters[1].external, false);
+
+ assert.equal(LEXED.chapters[2].path, 'test2.md');
+ assert.equal(LEXED.chapters[2].exists, false);
+ assert.equal(LEXED.chapters[2].introduction, false);
+ assert.equal(LEXED.chapters[2].external, false);
+
+ assert.equal(LEXED.chapters[3].path, 'https://www.google.com');
+ assert.equal(LEXED.chapters[3].exists, true);
+ assert.equal(LEXED.chapters[3].introduction, false);
+ assert.equal(LEXED.chapters[3].external, true);
+ });
+
+ it('should correctly parse the glossary', function() {
+ var LEXED = books[1].glossary;
+
+ assert.equal(LEXED[0].id, "test");
+ assert.equal(LEXED[0].name, "Test");
+ assert.equal(LEXED[0].description, "a test text");
+
+ assert.equal(LEXED[1].id, "test_2");
+ assert.equal(LEXED[1].name, "Test 2");
+ assert.equal(LEXED[1].description, "a second test");
+ });
+
+ it('should correctly parse list of files', function() {
+ var FILES = books[1].files;
+
+ assert.deepEqual(FILES, [ 'README.md', 'intro.md', 'sub/', 'sub/test1.md' ]);
+ });
+
+ it('should correctly parse the languages', function() {
+ assert.equal(books[2].books.length, 2);
+ assert(books[2].isMultilingual());
+
+ assert.equal(books[2].books[0].options.language, "en");
+ assert.equal(books[2].books[0].options.title, "English Book");
+
+ assert.equal(books[2].books[1].options.language, "fr");
+ assert.equal(books[2].books[1].options.title, "French Book");
+ });
+
+ it('should correctly parse the navigation', function() {
+ var NAVIGATION = books[1].navigation;
+
+ assert.equal(_.size(NAVIGATION), 2);
+ assert(NAVIGATION["intro.md"])
+ assert.equal(NAVIGATION["intro.md"].title, "Introduction");
+ assert.equal(NAVIGATION["intro.md"].prev, null);
+ assert.equal(NAVIGATION["intro.md"].next.title, "Article 1");
+
+ assert.equal(NAVIGATION["sub/test1.md"].title, "Article 1");
+ assert.equal(NAVIGATION["sub/test1.md"].prev.title, "Introduction");
+ assert.equal(NAVIGATION["sub/test1.md"].next, null);
+ });
+});