diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 09:47:36 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-19 09:47:36 +0100 |
commit | ec586dd3cdf06e9567f5d3e4961022ddc3c94778 (patch) | |
tree | cc7825ab73110b4e6fbedee404427b052edffa17 /test | |
parent | 80432161708357bdcf0e00533d9e6d327636dab6 (diff) | |
download | gitbook-ec586dd3cdf06e9567f5d3e4961022ddc3c94778.zip gitbook-ec586dd3cdf06e9567f5d3e4961022ddc3c94778.tar.gz gitbook-ec586dd3cdf06e9567f5d3e4961022ddc3c94778.tar.bz2 |
Clear folder
Diffstat (limited to 'test')
30 files changed, 0 insertions, 998 deletions
diff --git a/test/bin/lex.js b/test/bin/lex.js deleted file mode 100755 index c35d399..0000000 --- a/test/bin/lex.js +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env node - -var fs = require('fs'); - -var gitbook = require('../../'); - -if(process.argv < 3) { - console.error('Please specify a filename'); - process.exit(1); -} - -var content = fs.readFileSync(process.argv[2], 'utf8'); - -var lexed = gitbook.parse.lex(content); - -console.log(JSON.stringify(lexed, null, 2)); diff --git a/test/bin/summary.js b/test/bin/summary.js deleted file mode 100755 index 78c20dc..0000000 --- a/test/bin/summary.js +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env node - -var fs = require('fs'); - -var gitbook = require('../../'); - -if(process.argv < 3) { - console.error('Please specify a filename'); - process.exit(1); -} - -var content = fs.readFileSync(process.argv[2], 'utf8'); - -var lexed = gitbook.parse.summary(content); - -console.log(JSON.stringify(lexed, null, 2)); diff --git a/test/fixtures/ALTERNATIVE_SUMMARY.md b/test/fixtures/ALTERNATIVE_SUMMARY.md deleted file mode 100644 index e0d0114..0000000 --- a/test/fixtures/ALTERNATIVE_SUMMARY.md +++ /dev/null @@ -1,13 +0,0 @@ -# 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/fixtures/FALSE_QUIZ.md b/test/fixtures/FALSE_QUIZ.md deleted file mode 100644 index 46f9a00..0000000 --- a/test/fixtures/FALSE_QUIZ.md +++ /dev/null @@ -1,120 +0,0 @@ -# Learn Node.js by Example - - -## Requirements - -- [x] A computer with internet access -- [ ] Time: 30h (e.g. 2 months 30 mins per day or **1 week intensive**) - - -## What is Node.js ? - -Node.js lets you *easily* build networked software (websites, applications "apps", -using JavaScript). - -Its not "*point-and-click*" like WordPress, SquareSpace or Salesforce; -you will need to write some "code". But as I will demonstrate, that's -a *lot* easier than it sounds and gives you more power/flexibility -and puts you in full control. - -## Node.js is not "Version 1.0" yet can I used it in Production? - -Yes! Some of the biggest organisations/companies in the world -are using Node.js in Production systems: - -[Alibaba](https://github.com/alibaba/node-hbase-client), -[Ajax.org](Ajax.org), -[Box.com](http://tech.blog.box.com/2014/06/node-js-high-availability-at-box/), British Sky Broadcasting (Sky/Now TV), -CNN, -[Cloudup](https://cloudup.com/), -Conde Nast, -[DirectTV](http://strongloop.com/strongblog/node-summit-media-companies-embrace-node-js-for-rapidly-developing-responsive-apps/), -[Dow Jones](http://nodejs.org/industry), -eBay, -[FeedHenry](http://www.feedhenry.com/), -[GitHub](https://twitter.com/github/status/16979699217465344), -[Google](http://venturebeat.com/2012/01/24/node-at-google-mozilla-yahoo/), -[Groupon](http://nodeup.com/fiftyeight), -HBO, -Help.com, -[HP](https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node), -iTV, -[Joyent](https://www.joyent.com/) (duh!), -[Klout](https://klout.com), -LinkedIn, -McDonalds, -[Medium](https://medium.com/the-story), -Mozilla, -NetFlix, -[OpenTable](http://hapijs.com/community), -PayPal, -Pearson, -~~Q~~, -[Revolt](http://revolt.tv/), -[Square](https://modulus.io/companies-using-node), -Tesco, -ThomasCook, -Trello, -Uber, -Voxer, -Walmart, -Wikimedia (in progress of moving to SOA with node!) -Yahoo, -Yammer, -[Yandex](https://www.youtube.com/watch?v=zdCxgdH4wZo), -[Zendesk](http://radar.zendesk.com/) - -Want more? See: http://nodejs.org/industry/ and <br /> -https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node - - -# Try it! - -## Download & Install - -> http://nodejs.org/download/ - - -## Node.js (Core) API - -The node.js ("core") has many useful modules. - -Bookmark: [http://nodejs.org/api](http://nodejs.org/api/) (you will come back to it) - - - -## Stability (Can we use it?) - -> *Which node.js* ***core*** *package(s) can/should I use?* - -Every core module has a -["***Stability Index***"](http://nodejs.org/api/documentation.html#documentation_stability_index) -rating on the node.js API. - -**General rule**: If you are being *paid* to write code -that runs in node.js, <br /> pick core modules/methods -with stability **Stable**, **API Frozen** and **Locked**. - - - - -### Examples - -- [**cluster**](http://nodejs.org/api/cluster.html) is ***Experimental*** - don't use -- [**domain**](http://nodejs.org/api/domain.html) is ***Unstable*** - don't use -- [**path**](http://nodejs.org/api/path.html) is ***Stable*** - use -- [**events**](http://nodejs.org/api/events.html) is ***Frozen*** - use -- [**assert**](http://nodejs.org/api/assert.html) is ***Locked*** - use - -Core Modules to Learn - -- path -- os - - - -Community Modules to Learn: - -- [jscs](https://www.npmjs.org/package/jscs) - code style checker -- [q](https://www.npmjs.org/package/q) - promises library -- [nd](https://www.npmjs.org/package/nd) - view documentation for a module diff --git a/test/fixtures/GITHUB_LINKS.md b/test/fixtures/GITHUB_LINKS.md deleted file mode 100644 index f0039dd..0000000 --- a/test/fixtures/GITHUB_LINKS.md +++ /dev/null @@ -1,3 +0,0 @@ -# Nice course - -Check out this source file [in C++](../src/something.cpp) diff --git a/test/fixtures/GLOSSARY.md b/test/fixtures/GLOSSARY.md deleted file mode 100644 index 5969902..0000000 --- a/test/fixtures/GLOSSARY.md +++ /dev/null @@ -1,30 +0,0 @@ -# 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/test/fixtures/HR_PAGE.md b/test/fixtures/HR_PAGE.md deleted file mode 100644 index 49115d0..0000000 --- a/test/fixtures/HR_PAGE.md +++ /dev/null @@ -1,11 +0,0 @@ -## Wow such book - -Some nice content here - ---- - -A beautiful separator, but non an exercise or a quiz ! - ---- - -Some more beautiful text, because `this` book is awesome ... diff --git a/test/fixtures/IMAGES.md b/test/fixtures/IMAGES.md deleted file mode 100644 index 99ffa00..0000000 --- a/test/fixtures/IMAGES.md +++ /dev/null @@ -1,12 +0,0 @@ -# Images Test - -This is a test for images path calculation. It supposed this fiel is in a syntax/ folder - -### # - -[](./preview.png) - -### 2 - -[](./preview2.png) - diff --git a/test/fixtures/INCLUDES.md b/test/fixtures/INCLUDES.md deleted file mode 100644 index 22e3a61..0000000 --- a/test/fixtures/INCLUDES.md +++ /dev/null @@ -1,29 +0,0 @@ -# Beautiful chapter - -Here is a nice included snippet : - -```c -{{ included.c }} -``` - ----- - -An exercise using includes - -```c -{{ included.c }} - -Remove this extra code at the end -``` - -```c -{{ included.c }} -``` - -```c -{{ included.c }} - -This validation code is wrong but who cares ? -``` - ----- diff --git a/test/fixtures/MARKDOWN_LINKS.md b/test/fixtures/MARKDOWN_LINKS.md deleted file mode 100644 index e0d5820..0000000 --- a/test/fixtures/MARKDOWN_LINKS.md +++ /dev/null @@ -1,5 +0,0 @@ -# Nice course - -Check out this other chapter [Test](test.md) - -Check out this other chapter [Test](../before.md) diff --git a/test/fixtures/PAGE.md b/test/fixtures/PAGE.md deleted file mode 100644 index 77a6ce9..0000000 --- a/test/fixtures/PAGE.md +++ /dev/null @@ -1,68 +0,0 @@ -# Python basics - -Python is a nice language, you can add stuff. Bla bla bla. - -Lets jump into an exercise : - ---- - -It's dead simple, `c` must be the sum of `a` and `b` - -```py -a = 1 -b = 2 -``` - -```py -a = 1 -b = 2 -c = a + b -``` - -```py -assert(c, 3) -``` - ---- - -Some more nice content .... - -[Cool stuff](http://gitbook.com) - -[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 : - ---- - -Exercise with some context code : - -Using the `double` function provided, build a `quadruple` function - -```py - -``` - -```py - -def quadruple(x): - return double(double(x)) - -``` - -```py -assert(quadruple(8), 32) -``` - -```py - -def double(x): - return x * 2 - -``` - ---- - diff --git a/test/fixtures/QUIZ_PAGE.md b/test/fixtures/QUIZ_PAGE.md deleted file mode 100644 index 21b2a9d..0000000 --- a/test/fixtures/QUIZ_PAGE.md +++ /dev/null @@ -1,48 +0,0 @@ -# Gitbook quiz - -Gitbook lets you write a quiz using GFM tables: - ---- - -Here's a quiz about Gitbook - -| | Good | Bad | -| ---------------- | ---- | --- | -| What is Gitbook? | (x) | ( ) | - -> Gitbook is good - -What does Gitbook support? -- [x] Table-based questions with radio buttons -- [x] Table-based questions with checkboxes -- [ ] Telepathy -- [x] List-based questions with checkboxes -- [x] List-based questions with radio buttons -- [ ] Moon-on-a-stick - -> Gitbook supports table and list based quiz questions using either radio buttons or checkboxes. -> -> Gitbook is not telepathic and does not give you the moon on a stick. - ---- - -Some more nice content .... - -[Cool stuff](http://gitbook.com) - -[Link to another Markdown file](./xyz/file.md) - ---- - -Quiz test 2: What does Gitbook support? -- [x] Table-based questions with radio buttons -- [x] Table-based questions with checkboxes -- [ ] Telepathy -- [x] List-based questions with checkboxes -- [x] List-based questions with radio buttons -- [ ] Moon-on-a-stick - -> Gitbook supports table and list based quiz questions using either radio buttons or checkboxes. - ---- - diff --git a/test/fixtures/README.md b/test/fixtures/README.md deleted file mode 100644 index 7e20198..0000000 --- a/test/fixtures/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# This is the title - -This is the book description. - -other content -... - diff --git a/test/fixtures/SECTIONS.md b/test/fixtures/SECTIONS.md deleted file mode 100644 index 3405605..0000000 --- a/test/fixtures/SECTIONS.md +++ /dev/null @@ -1,68 +0,0 @@ -# Title - -Some text - ---- - -## NOT Exercise - -Simple subsection NOT exercise - -``` -x = 1 -``` - -What is this - -``` -y = [1, 2, 3] -``` - -``` -z = {a: 1, b: 2} -``` - ---- - -## Exercise - -Define a variable `x` equal to 10. - -```js -var x = -``` - -```js -var x = 10; -``` - -```js -assert(x == 10); -``` - -```js -// This is context code available everywhere -// The user will be able to call magicFunc in his code -function magicFunc() { - return 3; -} -``` - ---- - -## Another exercise - -Bla bla bla ... This time with no `context` code. - - -```js -var x = -``` - -```js -var x = 10; -``` - -```js -assert(x == 10); -``` diff --git a/test/fixtures/SUMMARY.md b/test/fixtures/SUMMARY.md deleted file mode 100644 index 3bf4a88..0000000 --- a/test/fixtures/SUMMARY.md +++ /dev/null @@ -1,12 +0,0 @@ -# Summary - -* [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/fixtures/SUMMARY_WHITESPACE.md b/test/fixtures/SUMMARY_WHITESPACE.md deleted file mode 100644 index 10a7100..0000000 --- a/test/fixtures/SUMMARY_WHITESPACE.md +++ /dev/null @@ -1,15 +0,0 @@ -# Summary - -* [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/fixtures/book1/README.md b/test/fixtures/book1/README.md deleted file mode 100644 index c01d3fb..0000000 --- a/test/fixtures/book1/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# This is a test - diff --git a/test/fixtures/book1/SUMMARY.md b/test/fixtures/book1/SUMMARY.md deleted file mode 100644 index 20ec7b8..0000000 --- a/test/fixtures/book1/SUMMARY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Summary - -* [test](test.md)
\ No newline at end of file diff --git a/test/fixtures/book1/test.md b/test/fixtures/book1/test.md deleted file mode 100644 index 8ae0569..0000000 --- a/test/fixtures/book1/test.md +++ /dev/null @@ -1 +0,0 @@ -# Test diff --git a/test/fixtures/book2/README.md b/test/fixtures/book2/README.md deleted file mode 100644 index 13c54db..0000000 --- a/test/fixtures/book2/README.md +++ /dev/null @@ -1 +0,0 @@ -# This should fail diff --git a/test/fixtures/included.c b/test/fixtures/included.c deleted file mode 100644 index d9323e3..0000000 --- a/test/fixtures/included.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main(int argc, char *argv[]) { - printf("All is well\n"); - - return 0; -} diff --git a/test/generate.js b/test/generate.js deleted file mode 100644 index c38566a..0000000 --- a/test/generate.js +++ /dev/null @@ -1,46 +0,0 @@ -var _ = require('lodash'); -var Q = require('q'); -var path = require('path'); -var tmp = require('tmp'); -var assert = require('assert'); - -var generate = require("../lib/generate"); - -var generateTmpBook = function(path) { - return ; -}; - - -var BOOKS = { - "book1": true, - "book2": false -}; - -describe('Site Generation', function () { - var ret = {}; - - beforeEach(function(done){ - Q.all(_.map(BOOKS, function(state, bookName) { - return Q.nfcall(tmp.dir) - .then(function(_dir) { - return generate.folder({ - input: path.join(__dirname, "fixtures", bookName), - output: _dir - }); - }) - .then(function(_book) { - ret[bookName] = _book; - }, function(err) { - // ignore errors here - }); - })) - .fin(done); - }); - - - it('should generate the valid sites', function() { - _.each(BOOKS, function(state, bookName) { - assert((ret[bookName] != null) == state); - }); - }); -}); diff --git a/test/glossary.js b/test/glossary.js deleted file mode 100644 index bf40e16..0000000 --- a/test/glossary.js +++ /dev/null @@ -1,20 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var glossary = require('../').parse.glossary; - -var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GLOSSARY.md'), '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/test/includes.js b/test/includes.js deleted file mode 100644 index 6954d3f..0000000 --- a/test/includes.js +++ /dev/null @@ -1,42 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var page = require('../').parse.page; -var includer = require('../').parse.includer; - -var FIXTURES_DIR = path.join(__dirname, './fixtures/'); - -function loadPage (name, options) { - var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8'); - return page(CONTENT, options).sections; -} - - -describe('Code includes', function() { - - var LEXED = loadPage('INCLUDES', { - 'dir': FIXTURES_DIR, - 'includer': includer({}, [ - FIXTURES_DIR - ], path.join, fs.readFileSync) - }); - - var INCLUDED_C = fs.readFileSync(path.join(FIXTURES_DIR, 'included.c'), 'utf8'); - - it('should work for snippets', function() { - assert.equal(LEXED[0].type, 'normal'); - // Has replaced include - assert.equal( - LEXED[0].content.indexOf('{{ included.c }}'), - -1 - ); - }); - - it('should work for exercises', function() { - assert.equal(LEXED[1].type, 'exercise'); - - // Solution is trimmed version of source - assert.equal(LEXED[1].code.solution, INCLUDED_C.trim()); - }); -}); diff --git a/test/navigation.js b/test/navigation.js deleted file mode 100644 index df29509..0000000 --- a/test/navigation.js +++ /dev/null @@ -1,101 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var summary = require('../').parse.summary; -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() { - it('should provide next & prev entries for a file', function() { - var nav = navigation(LEXED, [ - 'README.md', - 'chapter-1/README.md', - 'chapter-1/ARTICLE1.md', - 'chapter-1/ARTICLE2.md', - 'chapter-2/README.md', - 'chapter-1/ARTICLE-1-2-1.md', - 'chapter-1/ARTICLE-1-2-2.md' - ]); - - // Make sure it found the files we gave it - assert(nav['README.md']); - assert(nav['chapter-1/README.md']); - assert(nav['chapter-1/ARTICLE1.md']); - assert(nav['chapter-1/ARTICLE2.md']); - assert(nav['chapter-2/README.md']); - assert(nav['chapter-1/ARTICLE-1-2-1.md']); - assert(nav['chapter-1/ARTICLE-1-2-2.md']); - - - assert.equal(nav['README.md'].prev, null); - assert.equal(nav['README.md'].next.path, 'chapter-1/README.md'); - - assert.equal(nav['chapter-1/README.md'].prev.path, 'README.md'); - assert.equal(nav['chapter-1/README.md'].next.path, 'chapter-1/ARTICLE1.md'); - - assert.equal(nav['chapter-1/ARTICLE1.md'].prev.path, 'chapter-1/README.md'); - assert.equal(nav['chapter-1/ARTICLE1.md'].next.path, 'chapter-1/ARTICLE2.md'); - - assert.equal(nav['chapter-1/ARTICLE2.md'].prev.path, 'chapter-1/ARTICLE1.md'); - assert.equal(nav['chapter-1/ARTICLE2.md'].next.path, 'chapter-1/ARTICLE-1-2-1.md'); - - assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].prev.path, 'chapter-1/ARTICLE2.md'); - assert.equal(nav['chapter-1/ARTICLE-1-2-1.md'].next.path, 'chapter-1/ARTICLE-1-2-2.md'); - - assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].prev.path, 'chapter-1/ARTICLE-1-2-1.md'); - assert.equal(nav['chapter-1/ARTICLE-1-2-2.md'].next.path, 'chapter-2/README.md'); - - assert.equal(nav['chapter-2/README.md'].prev.path, 'chapter-1/ARTICLE-1-2-2.md'); - assert.equal(nav['chapter-2/README.md'].next.path, 'chapter-3/README.md'); - }); - - it('should give full tree, when not limited', function() { - var nav = navigation(LEXED); - - assert(nav['README.md']); - assert(nav['chapter-1/README.md']); - assert(nav['chapter-1/ARTICLE1.md']); - assert(nav['chapter-1/ARTICLE2.md']); - assert(nav['chapter-2/README.md']); - assert(nav['chapter-3/README.md']); - }); - - it('should detect levels correctly', function() { - var nav = navigation(LEXED); - - assert.equal(nav['README.md'].level, '0'); - assert.equal(nav['chapter-1/README.md'].level, '1'); - assert.equal(nav['chapter-1/ARTICLE1.md'].level, '1.1'); - assert.equal(nav['chapter-1/ARTICLE2.md'].level, '1.2'); - assert.equal(nav['chapter-2/README.md'].level, '2'); - 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); - - assert(!nav[null]); - }); -}); diff --git a/test/page.js b/test/page.js deleted file mode 100644 index c883367..0000000 --- a/test/page.js +++ /dev/null @@ -1,123 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var page = require('../').parse.page; - -function loadPage (name, options) { - var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8'); - return page(CONTENT, options).sections; -} - -var LEXED = loadPage('PAGE', { - dir: 'course', - outdir: '_book' -}); -var QUIZ_LEXED = loadPage('QUIZ_PAGE'); -var HR_LEXED = loadPage('HR_PAGE'); - -describe('Page parsing', function() { - it('should detect sections', function() { - assert.equal(LEXED.length, 4); - }); - - it('should detect section types', function() { - assert.equal(LEXED[0].type, 'normal'); - assert.equal(LEXED[1].type, 'exercise'); - assert.equal(LEXED[2].type, 'normal'); - assert.equal(QUIZ_LEXED[0].type, 'normal'); - assert.equal(QUIZ_LEXED[1].type, 'quiz'); - assert.equal(QUIZ_LEXED[2].type, 'normal'); - assert.equal(QUIZ_LEXED[3].type, 'quiz'); - }); - - it('should gen content for normal sections', function() { - assert(LEXED[0].content); - assert(LEXED[2].content); - }); - - it('should gen code and content for exercise sections', function() { - assert(LEXED[1].content); - assert(LEXED[1].code); - assert(LEXED[1].code.base); - assert(LEXED[1].code.solution); - assert(LEXED[1].code.validation); - assert(LEXED[1].code.context === null); - - assert(LEXED[3].content); - assert(LEXED[3].code); - assert(LEXED[3].code.base); - assert(LEXED[3].code.solution); - assert(LEXED[3].code.validation); - assert(LEXED[3].code.context); - }); - - it('should merge sections correctly', function() { - // One big section - assert.equal(HR_LEXED.length, 1); - - // HRs inserted correctly - assert.equal(HR_LEXED[0].content.match(/<hr>/g).length, 2); - }); - - it('should detect an exercise\'s language', function() { - assert.equal(LEXED[1].lang, 'python'); - }); - - it('should render a quiz', function() { - assert(QUIZ_LEXED[1].content); - assert(QUIZ_LEXED[1].quiz); - assert(QUIZ_LEXED[1].quiz[0].base); - assert(QUIZ_LEXED[1].quiz[0].solution); - assert(QUIZ_LEXED[1].quiz[0].feedback); - assert(QUIZ_LEXED[1].quiz[1].base); - assert(QUIZ_LEXED[1].quiz[1].solution); - assert(QUIZ_LEXED[1].quiz[1].feedback); - }); -}); - - -describe('Relative links', function() { - it('should replace link to .md by link to .html', function() { - var LEXED = loadPage('MARKDOWN_LINKS', { - // Imaginary folder of markdown file - dir: 'course', - outdir: 'course' - }); - - assert(LEXED[0].content.indexOf('test.html') !== -1); - assert(LEXED[0].content.indexOf('../before.html') !== -1); - }); -}); - -describe('Relative images', function() { - it('should keep image relative with considering output directory in site format', function() { - var LEXED = loadPage('IMAGES', { - // Imaginary folder of markdown file - dir: 'syntax', - outdir: 'syntax' - }); - - assert(LEXED[0].content.indexOf('"preview.png"') !== -1); - assert(LEXED[0].content.indexOf('"../preview2.png"') !== -1); - }); - - it('should keep image relative with considering output directory in page format', function() { - var LEXED = loadPage('IMAGES', { - // Imaginary folder of markdown file - dir: 'syntax', - outdir: './' - }); - - assert(LEXED[0].content.indexOf('"syntax/preview.png"') !== -1); - assert(LEXED[0].content.indexOf('"preview2.png"') !== -1); - }); -}); - -describe('Section parsing', function() { - it('should not have false positive quiz parsing', function() { - var LEXED = loadPage('FALSE_QUIZ'); - - assert.equal(LEXED[0].type, 'normal'); - }); -}); diff --git a/test/plugin.js b/test/plugin.js deleted file mode 100644 index fcde67c..0000000 --- a/test/plugin.js +++ /dev/null @@ -1,58 +0,0 @@ -var _ = require('lodash'); -var path = require('path'); -var assert = require('assert'); - -var Plugin = require('../').generate.Plugin; - -describe('Plugin validation', function () { - var plugin = new Plugin("plugin", __dirname); - - it('should be valid', function() { - assert(plugin.isValid()); - }); -}); - -describe('Plugins list', function () { - var firstDefault = _.first(Plugin.defaults); - - it('should convert string to array', function() { - var _name = "test"; - assert(_.contains(Plugin.normalizeNames(_name), _name)); - }); - - it('should contains default plugins', function() { - assert(_.contains(Plugin.normalizeNames([]), firstDefault)); - }); - - it('should remove name starting with -', function() { - assert(!_.contains(Plugin.normalizeNames(["-"+firstDefault]), firstDefault)); - }); - - it('should accept version', function() { - var _name = "test@0.3.0,exercises@1.2.0,test2"; - var plugins = Plugin.normalizeList(_name); - - assert(_.find(plugins, {'name': "test"}).version = "0.3.0"); - assert(_.find(plugins, {'name': "exercises"}).version = "1.2.0"); - assert(!_.find(plugins, {'name': "test2"}).version); - }); -}); - -describe('Plugin defaults loading', function () { - var ret = true; - - beforeEach(function(done){ - Plugin.fromList(Plugin.defaults, __dirname) - .then(function(_r) { - ret = _r; - }, function(err) { - ret = null; - }) - .fin(done); - }); - - - it('should load defaults addons', function() { - assert(ret != null); - }); -}); diff --git a/test/readme.js b/test/readme.js deleted file mode 100644 index 811591c..0000000 --- a/test/readme.js +++ /dev/null @@ -1,28 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var readme = require('../').parse.readme; - - -var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.md'), '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/test/sections.js b/test/sections.js deleted file mode 100644 index ef4abf9..0000000 --- a/test/sections.js +++ /dev/null @@ -1,22 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var lex = require('../').parse.lex; - - -var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SECTIONS.md'), 'utf8'); -var LEXED = lex(CONTENT); - - -describe('Section parsing', function() { - it('should correctly split sections', function() { - assert.equal(LEXED.length, 3); - }); - - it('should robustly detect exercises', function() { - assert.equal(LEXED[0].type, 'normal'); - assert.equal(LEXED[1].type, 'exercise'); - assert.equal(LEXED[2].type, 'exercise'); - }); -}); diff --git a/test/summary.js b/test/summary.js deleted file mode 100644 index 616b983..0000000 --- a/test/summary.js +++ /dev/null @@ -1,71 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var summary = require('../').parse.summary; - -function lex(fixtureFile) { - return summary( - fs.readFileSync( - path.join(__dirname, 'fixtures', fixtureFile), - 'utf8' - ) - ); -} - -var LEXED = lex('SUMMARY.md'); - -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 to .html', 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'); - }); - - it('should allow lists separated by whitespace', function() { - var l = lex('SUMMARY_WHITESPACE.md'); - - assert.equal(l.chapters.length, 6); - }); -}); |