|
1 | | -var expect = require('chai').expect; |
2 | | -var task = require('../lib/build/parser/task').task; |
3 | | -var trimCommandValue = require('../lib/build/parser/cleanup').trimCommandValue; |
4 | | - |
5 | | -var result = function() { |
6 | | - return { |
7 | | - chapters: [{ |
8 | | - pages: [{ |
9 | | - tasks: [] |
10 | | - }] |
11 | | - }] |
12 | | - }; |
13 | | -}; |
14 | | -var index = function() { |
15 | | - return { |
16 | | - chapter: 0, |
17 | | - page: 0, |
18 | | - task: -1 |
19 | | - }; |
20 | | -}; |
21 | | - |
22 | | -describe('trimCommandValue', function() { |
23 | | - |
24 | | - it('should not effect a normal command', function() { |
| 1 | +const { expect } = require('chai'); |
| 2 | +const { task } = require('../lib/build/parser/task'); |
| 3 | +const { trimCommandValue } = require('../lib/build/parser/cleanup'); |
| 4 | + |
| 5 | +const result = () => ({ |
| 6 | + pages: [{ |
| 7 | + tasks: [] |
| 8 | + }] |
| 9 | +}); |
| 10 | + |
| 11 | +const index = () => ({ |
| 12 | + page: 0, |
| 13 | + task: -1 |
| 14 | +}); |
| 15 | + |
| 16 | +describe('trimCommandValue', () => { |
| 17 | + |
| 18 | + it('should not effect a normal command', () => { |
25 | 19 | expect(trimCommandValue("do('something')")).to.equal("do('something')"); |
26 | 20 | }); |
27 | 21 |
|
28 | | - it('should trim leading spaces', function() { |
| 22 | + it('should trim leading spaces', () => { |
29 | 23 | expect(trimCommandValue("do( 'something')")).to.equal("do('something')"); |
30 | 24 | }); |
31 | 25 |
|
32 | 26 | }); |
33 | 27 |
|
34 | | -describe('task', function() { |
| 28 | +describe('task', () => { |
35 | 29 |
|
36 | | - it('should return a trimmed task description', function() { |
37 | | - var lines = ['+ Task One']; |
38 | | - var next = task(result(), lines, index()); |
39 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
| 30 | + it('should return a trimmed task description', () => { |
| 31 | + const lines = ['+ Task One']; |
| 32 | + const next = task({ result: result(), lines, index: index() }); |
| 33 | + const nextTask = next.pages[0].tasks[0]; |
40 | 34 | expect(nextTask.description).to.equal('Task One'); |
41 | 35 | }); |
42 | 36 |
|
43 | | - it('should return a multi-line task description', function() { |
44 | | - var lines = ['+ Task One', 'with more on the next', 'line']; |
45 | | - var next = task(result(), lines, index()); |
46 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
| 37 | + it('should return a multi-line task description', () => { |
| 38 | + const lines = ['+ Task One', 'with more on the next', 'line']; |
| 39 | + const next = task({ result: result(), lines, index: index() }); |
| 40 | + const nextTask = next.pages[0].tasks[0]; |
47 | 41 | expect(nextTask.description).to.equal('Task One\nwith more on the next\nline'); |
48 | 42 | }); |
49 | 43 |
|
50 | | - it('exits on next chapter', function() { |
51 | | - var lines = ['+ Task One', 'with more on the next', '## Chapter Two']; |
52 | | - var next = task(result(), lines, index()); |
53 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
| 44 | + it('exits on next chapter', () => { |
| 45 | + const lines = ['+ Task One', 'with more on the next', '## Chapter Two']; |
| 46 | + const next = task({ result: result(), lines, index: index() }); |
| 47 | + const nextTask = next.pages[0].tasks[0]; |
54 | 48 | expect(nextTask.description).to.equal('Task One\nwith more on the next'); |
55 | 49 | }); |
56 | 50 |
|
57 | | - it('exits on next page', function() { |
58 | | - var lines = ['+ Task One', 'with more on the next', '### Page Two']; |
59 | | - var next = task(result(), lines, index()); |
60 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
| 51 | + it('exits on next page', () => { |
| 52 | + const lines = ['+ Task One', 'with more on the next', '## Page Two']; |
| 53 | + const next = task({ result: result(), lines, index: index() }); |
| 54 | + const nextTask = next.pages[0].tasks[0]; |
61 | 55 | expect(nextTask.description).to.equal('Task One\nwith more on the next'); |
62 | 56 | }); |
63 | 57 |
|
64 | | - it('exits on next task', function() { |
65 | | - var lines = ['+ Task One', 'with more on the next', '+ Task Two']; |
66 | | - var next = task(result(), lines, index()); |
67 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
| 58 | + it('exits on next task', () => { |
| 59 | + const lines = ['+ Task One', 'with more on the next', '+ Task Two']; |
| 60 | + const next = task({ result: result(), lines, index: index() }); |
| 61 | + const nextTask = next.pages[0].tasks[0]; |
68 | 62 | expect(nextTask.description).to.equal('Task One\nwith more on the next'); |
69 | 63 | }); |
70 | 64 |
|
71 | | - it('should import lines in task', function() { |
72 | | - var lines = ['+ Task description', '', "@import('./test/imports/chapter-sample')"] |
73 | | - var next = task(result(), lines, index()); |
74 | | - var nextChapter = next.chapters[1]; |
75 | | - expect(nextChapter.title).to.equal('Chapter Sample'); |
76 | | - }); |
77 | | - |
78 | | - it('should accept multpile import lines in task', function() { |
79 | | - var lines = ['+ Task description', '', |
80 | | - "@import('./test/imports/chapter-sample')", "@import('./test/imports/chapter-sample')" |
81 | | - ] |
82 | | - var next = task(result(), lines, index()); |
83 | | - var nextChapter = next.chapters[2]; |
84 | | - expect(nextChapter.title).to.equal('Chapter Sample'); |
85 | | - }); |
86 | | - |
87 | | - it('should add codeblock languages', function() { |
88 | | - var lines = ['+ Task One', '```js', 'var a = 42;', '```']; |
89 | | - var next = task(result(), lines, index()); |
90 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
91 | | - expect(nextTask.description).to.equal('Task One\n```js\nvar a = 42;\n```'); |
| 65 | + // it('should import lines in task', () => { |
| 66 | + // const lines = ['+ Task description', '', "@import('./test/imports/chapter-sample')"] |
| 67 | + // const next = task({ result: result(), lines, index: index() }); |
| 68 | + // const nextChapter = next.chapters[1]; |
| 69 | + // expect(nextChapter.title).to.equal('Chapter Sample'); |
| 70 | + // }); |
| 71 | + // |
| 72 | + // it('should accept multiple import lines in task', () => { |
| 73 | + // const lines = ['+ Task description', '', |
| 74 | + // "@import('./test/imports/chapter-sample')", "@import('./test/imports/chapter-sample')" |
| 75 | + // ] |
| 76 | + // const next = task({ result: result(), lines, index: index() }); |
| 77 | + // const nextChapter = next.chapters[2]; |
| 78 | + // expect(nextChapter.title).to.equal('Chapter Sample'); |
| 79 | + // }); |
| 80 | + |
| 81 | + it('should add codeblock languages', () => { |
| 82 | + const lines = ['+ Task One', '```js', 'const a = 42;', '```']; |
| 83 | + const next = task({ result: result(), lines, index: index() }); |
| 84 | + const nextTask = next.pages[0].tasks[0]; |
| 85 | + expect(nextTask.description).to.equal('Task One\n```js\nconst a = 42;\n```'); |
92 | 86 | }); |
93 | 87 |
|
94 | | - it('should add single line codeblocks', function() { |
95 | | - var lines = ['+ Task One', '```var a = 42;```']; |
96 | | - var next = task(result(), lines, index()); |
97 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
98 | | - expect(nextTask.description).to.equal('Task One\n```var a = 42;```'); |
| 88 | + it('should add single line codeblocks', () => { |
| 89 | + const lines = ['+ Task One', '```const a = 42;```']; |
| 90 | + const next = task({ result: result(), lines, index: index() }); |
| 91 | + const nextTask = next.pages[0].tasks[0]; |
| 92 | + expect(nextTask.description).to.equal('Task One\n```const a = 42;```'); |
99 | 93 | }); |
100 | 94 |
|
101 | | - it('should handle strangely formatted codeblocks', function() { |
102 | | - var lines = ['+ Task One', '```var a = 42;', '```']; |
103 | | - var next = task(result(), lines, index()); |
104 | | - var nextTask = next.chapters[0].pages[0].tasks[0]; |
105 | | - expect(nextTask.description).to.equal('Task One\n```var a = 42;\n```'); |
| 95 | + it('should handle strangely formatted codeblocks', () => { |
| 96 | + const lines = ['+ Task One', '```const a = 42;', '```']; |
| 97 | + const next = task({ result: result(), lines, index: index() }); |
| 98 | + const nextTask = next.pages[0].tasks[0]; |
| 99 | + expect(nextTask.description).to.equal('Task One\n```const a = 42;\n```'); |
106 | 100 | }); |
107 | 101 |
|
108 | 102 | }); // task |
0 commit comments