summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@friendco.de>2014-04-10 02:27:42 -0700
committerAaron O'Mullan <aaron.omullan@friendco.de>2014-04-10 02:27:42 -0700
commit04774df3724ba96a80a07371244c2d47426720c0 (patch)
treeb9b0a2018056b25aae4c35ff739cc5404337b9d7
parent619ded93adc01a870b8ee29722ff5e426c6fb8d7 (diff)
downloadgitbook-04774df3724ba96a80a07371244c2d47426720c0.zip
gitbook-04774df3724ba96a80a07371244c2d47426720c0.tar.gz
gitbook-04774df3724ba96a80a07371244c2d47426720c0.tar.bz2
Add better tests for ambiguous section detection
-rw-r--r--test/fixtures/SECTIONS.md68
-rw-r--r--test/sections.js22
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');
+ });
+});