diff options
Diffstat (limited to 'packages/gitbook-asciidoc/test')
-rwxr-xr-x | packages/gitbook-asciidoc/test/fixtures/GLOSSARY.adoc | 32 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/fixtures/LANGS.adoc | 4 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/fixtures/PAGE.adoc | 14 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/fixtures/README.adoc | 6 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/fixtures/SUMMARY.adoc | 12 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/glossary.js | 20 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/langs.js | 20 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/page.js | 22 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/readme.js | 28 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/test/summary.js | 56 |
10 files changed, 214 insertions, 0 deletions
diff --git a/packages/gitbook-asciidoc/test/fixtures/GLOSSARY.adoc b/packages/gitbook-asciidoc/test/fixtures/GLOSSARY.adoc new file mode 100755 index 0000000..75be225 --- /dev/null +++ b/packages/gitbook-asciidoc/test/fixtures/GLOSSARY.adoc @@ -0,0 +1,32 @@ += Glossary + +== Magic +Sufficiently advanced technology, beyond the understanding of the observer producing a sense of wonder. + +Hello, I am random noise in the middle of this beautiful Glossary. (Really astonishing !) + +== PHP +An atrocious language, invented for the sole purpose of inflicting pain and suffering amongst the proframming wizards of this world. + +== Clojure +Lisp re-invented for hipsters. + +== Go +Go Go Google [Wow](https://www.google.com) + +Fantastic, I love code too ! : + +```py + +def f(x): + return x * 4 + +# Wow this is some really awesome code +# totally mind blowing +# but we don't care, it shouldn't be in our glossary ! +print(f(9)) +``` + +== Gitbook + +Awesome project. Really amazing, I'm really at a loss for words ... diff --git a/packages/gitbook-asciidoc/test/fixtures/LANGS.adoc b/packages/gitbook-asciidoc/test/fixtures/LANGS.adoc new file mode 100755 index 0000000..8ea9e11 --- /dev/null +++ b/packages/gitbook-asciidoc/test/fixtures/LANGS.adoc @@ -0,0 +1,4 @@ += Languages + +. link:en/[English] +. link:en/[French] diff --git a/packages/gitbook-asciidoc/test/fixtures/PAGE.adoc b/packages/gitbook-asciidoc/test/fixtures/PAGE.adoc new file mode 100755 index 0000000..a9afbac --- /dev/null +++ b/packages/gitbook-asciidoc/test/fixtures/PAGE.adoc @@ -0,0 +1,14 @@ += Python basics + +Python is a nice language, you can add stuff. Bla bla bla. + +Some more nice content .... + +[Cool stuff](http://gitbook.io) + +[Link to another Markdown file](./xyz/file.md) + +And look at this pretty picture: + + +Lets go for another exercise but this time with some context : diff --git a/packages/gitbook-asciidoc/test/fixtures/README.adoc b/packages/gitbook-asciidoc/test/fixtures/README.adoc new file mode 100755 index 0000000..12687b6 --- /dev/null +++ b/packages/gitbook-asciidoc/test/fixtures/README.adoc @@ -0,0 +1,6 @@ += This is the title + +This is the book description. + +other content +... diff --git a/packages/gitbook-asciidoc/test/fixtures/SUMMARY.adoc b/packages/gitbook-asciidoc/test/fixtures/SUMMARY.adoc new file mode 100755 index 0000000..8f97fa0 --- /dev/null +++ b/packages/gitbook-asciidoc/test/fixtures/SUMMARY.adoc @@ -0,0 +1,12 @@ += Summary + +. link:chapter-1/README.adoc[Chapter 1] +.. link:chapter-1/ARTICLE1.adoc[Article 1] +.. link:chapter-1/ARTICLE2.adoc[Article 2] +... link:\chapter-1\ARTICLE-1-2-1.adoc[Article 1.2.1] +... link:\chapter-1\ARTICLE-1-2-2.adoc[Article 1.2.2] +. link:chapter-2/README.adoc[Chapter 2] +. link:chapter-3/README.adoc[Chapter 3] +. link:chapter-4/README.adoc[Chapter 4] +.. Unfinished article +. Unfinished Chapter diff --git a/packages/gitbook-asciidoc/test/glossary.js b/packages/gitbook-asciidoc/test/glossary.js new file mode 100755 index 0000000..eb26f4a --- /dev/null +++ b/packages/gitbook-asciidoc/test/glossary.js @@ -0,0 +1,20 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var glossary = require('../').glossary; + +var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GLOSSARY.adoc'), 'utf8'); +var LEXED = glossary(CONTENT); + +describe('Glossary parsing', function () { + it('should only get heading + paragraph pairs', function() { + assert.equal(LEXED.length, 5); + }); + + it('should output simple name/description objects', function() { + assert.equal(true, !(LEXED.some(function(e) { + return !Boolean(e.name && e.description); + }))); + }); +}); diff --git a/packages/gitbook-asciidoc/test/langs.js b/packages/gitbook-asciidoc/test/langs.js new file mode 100755 index 0000000..bbf3c68 --- /dev/null +++ b/packages/gitbook-asciidoc/test/langs.js @@ -0,0 +1,20 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var langs = require('../').langs; + +var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/LANGS.adoc'), 'utf8'); +var LEXED = langs(CONTENT); + +describe('Languages parsing', function () { + it('should detect paths and titles', function() { + assert.equal(LEXED[0].path,'en/'); + assert.equal(LEXED[0].lang,'en'); + assert.equal(LEXED[0].title,'English'); + + assert.equal(LEXED[1].path,'fr/'); + assert.equal(LEXED[1].lang,'fr'); + assert.equal(LEXED[1].title,'French'); + }); +}); diff --git a/packages/gitbook-asciidoc/test/page.js b/packages/gitbook-asciidoc/test/page.js new file mode 100755 index 0000000..9579725 --- /dev/null +++ b/packages/gitbook-asciidoc/test/page.js @@ -0,0 +1,22 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var page = require('../').page; + +function loadPage (name, options) { + var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.adoc'), 'utf8'); + return page(CONTENT, options).sections; +} + +var LEXED = loadPage('PAGE'); + +describe('Page parsing', function() { + it('should detect sections', function() { + assert.equal(LEXED.length, 1); + }); + + it('should gen content for normal sections', function() { + assert(LEXED[0].content); + }); +}); diff --git a/packages/gitbook-asciidoc/test/readme.js b/packages/gitbook-asciidoc/test/readme.js new file mode 100755 index 0000000..0bca343 --- /dev/null +++ b/packages/gitbook-asciidoc/test/readme.js @@ -0,0 +1,28 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var readme = require('../').readme; + + +var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.adoc'), 'utf8'); +var LEXED = readme(CONTENT); + +describe('Readme parsing', function () { + + it('should contain a title', function() { + assert(LEXED.title); + }); + + it('should contain a description', function() { + assert(LEXED.description); + }); + + it('should extract the right title', function() { + assert.equal(LEXED.title, "This is the title"); + }); + + it('should extract the right description', function() { + assert.equal(LEXED.description, "This is the book description."); + }); +}); diff --git a/packages/gitbook-asciidoc/test/summary.js b/packages/gitbook-asciidoc/test/summary.js new file mode 100755 index 0000000..5c9bbcc --- /dev/null +++ b/packages/gitbook-asciidoc/test/summary.js @@ -0,0 +1,56 @@ +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); + +var summary = require('../').summary; + +var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.adoc'), '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', 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'); + }); +}); |