diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-10 11:34:56 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-10 11:34:56 +0200 |
commit | 02d8272c74b8b7f2da4e39c432e6521047ea8900 (patch) | |
tree | 597c0f89600a5c35e1e6f32cc67a6a1ed66579c5 /test | |
parent | 2e85380cd822e05072b00d5f2493c263ac194395 (diff) | |
parent | e54b8080933f7e85df6b2182cc171dd3dc28f8a4 (diff) | |
download | gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.zip gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.tar.gz gitbook-02d8272c74b8b7f2da4e39c432e6521047ea8900.tar.bz2 |
Merge pull request #77 from GitbookIO/improve/sections_lexing
Improve/sections lexing
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/SECTIONS.md | 68 | ||||
-rw-r--r-- | test/sections.js | 22 |
2 files changed, 90 insertions, 0 deletions
diff --git a/test/fixtures/SECTIONS.md b/test/fixtures/SECTIONS.md new file mode 100644 index 0000000..3405605 --- /dev/null +++ b/test/fixtures/SECTIONS.md @@ -0,0 +1,68 @@ +# 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/sections.js b/test/sections.js new file mode 100644 index 0000000..ef4abf9 --- /dev/null +++ b/test/sections.js @@ -0,0 +1,22 @@ +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'); + }); +}); |