Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d16577e

Browse files
author
Aaron O'Mullan
committed
Add tests for includes
1 parent 15b4053 commit d16577e

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

test/fixtures/INCLUDES.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Beautiful chapter
2+
3+
Here is a nice included snippet :
4+
5+
```c
6+
{{ included.c }}
7+
```
8+
9+
----
10+
11+
An exercise using includes
12+
13+
```c
14+
{{ included.c }}
15+
16+
Remove this extra code at the end
17+
```
18+
19+
```c
20+
{{ included.c }}
21+
```
22+
23+
```c
24+
{{ included.c }}
25+
26+
This validation code is wrong but who cares ?
27+
```
28+
29+
----

test/fixtures/included.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char *argv[]) {
4+
printf("All is well\n");
5+
6+
return 0;
7+
}

test/includes.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
var assert = require('assert');
4+
5+
var page = require('../').parse.page;
6+
7+
var FIXTURES_DIR = path.join(__dirname, './fixtures/');
8+
9+
function loadPage (name, options) {
10+
var CONTENT = fs.readFileSync(FIXTURES_DIR + name + '.md', 'utf8');
11+
return page(CONTENT, options);
12+
}
13+
14+
15+
describe('Code includes', function() {
16+
17+
var LEXED = loadPage('INCLUDES', {
18+
'dir': FIXTURES_DIR,
19+
});
20+
21+
var INCLUDED_C = fs.readFileSync(path.join(FIXTURES_DIR, 'included.c'), 'utf8');
22+
23+
it('should work for snippets', function() {
24+
assert.equal(LEXED[0].type, 'normal');
25+
// Has replaced include
26+
assert.equal(
27+
LEXED[0].content.indexOf('{{ included.c }}'),
28+
-1
29+
);
30+
});
31+
32+
it('should work for exercises', function() {
33+
assert.equal(LEXED[1].type, 'exercise');
34+
35+
// Solution is trimmed version of source
36+
assert.equal(LEXED[1].code.solution, INCLUDED_C.trim());
37+
});
38+
});

0 commit comments

Comments
 (0)