Skip to content

Commit 230f63e

Browse files
committed
add greater test support
1 parent 020db5c commit 230f63e

File tree

7 files changed

+253
-16
lines changed

7 files changed

+253
-16
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
npm-debug.log

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"author": "Shawn McKay <shawn.j.mckay@gmail.com>",
88
"main": "parser/index.pegjs",
99
"scripts": {
10-
"test": "ava"
10+
"test": "ava",
11+
"test:watch": "ava --watch"
1112
},
1213
"dependencies": {
1314
"pegjs": "^0.9.0",

‎test/info.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ test('parses a description', t => {
2121
const data = `# Title
2222
some description
2323
`;
24-
console.log(data);
2524
const expected = {
2625
info: {
2726
title: 'Title',
@@ -38,7 +37,6 @@ some description
3837
and more on
3938
the next line
4039
`;
41-
console.log(data);
4240
const expected = {
4341
info: {
4442
title: 'Title',
@@ -58,7 +56,6 @@ test.skip('parses a title after empty spaces', t => {
5856
# Title
5957
some description
6058
`;
61-
console.log(data);
6259
const expected = {
6360
info: {
6461
title: 'Title',

‎test/page.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,55 @@ import { readFileSync } from 'fs';
55
const parser = readFileSync('../parser/index.pegjs', 'utf8');
66
const parse = pegjs.buildParser(parser).parse;
77

8-
test.todo('parses a page title');
9-
test.todo('parses a page with empty description');
10-
test.todo('parses two pages');
8+
test('parses a page title', t => {
9+
const data = `# Title
10+
description
11+
12+
## Page One
13+
`;
14+
const expected = [{
15+
title: 'Page One',
16+
description: ''
17+
}];
18+
const result = parse(data);
19+
t.deepEqual(result.pages, expected);
20+
});
21+
22+
test('parses a page with empty description', t => {
23+
const data = `# Title
24+
description
25+
26+
## Page One
27+
page one description
28+
`;
29+
const expected = [{
30+
title: 'Page One',
31+
description: 'page one description'
32+
}];
33+
const result = parse(data);
34+
t.deepEqual(result.pages, expected);
35+
});
36+
37+
test('parses two pages', t => {
38+
const data = `# Title
39+
description
40+
41+
## Page One
42+
page one description
43+
44+
## Page Two
45+
page two description
46+
`;
47+
const expected = [{
48+
title: 'Page One',
49+
description: 'page one description'
50+
}, {
51+
title: 'Page Two',
52+
description: 'page two description'
53+
}];
54+
const result = parse(data);
55+
t.deepEqual(result.pages, expected);
56+
});
1157

1258
test.todo('parses an onPageComplete');
1359
test.todo('throws when multiple onPageCompletes');

‎test/task-hint.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import test from 'ava';
2+
import pegjs from 'pegjs';
3+
import { readFileSync } from 'fs';
4+
5+
const parser = readFileSync('../parser/index.pegjs', 'utf8');
6+
const parse = pegjs.buildParser(parser).parse;
7+
8+
test('parses a task hint', t => {
9+
const data = `# Title
10+
description
11+
12+
## Page One
13+
description
14+
15+
+ Task One
16+
@test('01, 02')
17+
@hint('do something')
18+
`;
19+
const expected = [{
20+
description: 'Task One',
21+
tests: [
22+
'01, 02'
23+
],
24+
hints: [
25+
'do something'
26+
]
27+
}];
28+
const result = parse(data);
29+
t.deepEqual(result.pages[0].tasks, expected);
30+
});
31+
32+
test('parses multiple task hints', t => {
33+
const data = `# Title
34+
description
35+
36+
## Page One
37+
description
38+
39+
+ Task One
40+
@test('01, 02')
41+
@hint('do something')
42+
@hint('do something else')
43+
`;
44+
const expected = [{
45+
description: 'Task One',
46+
tests: [
47+
'01, 02'
48+
],
49+
hints: [
50+
'do something',
51+
'do something else'
52+
]
53+
}];
54+
const result = parse(data);
55+
t.deepEqual(result.pages[0].tasks, expected);
56+
});
57+
58+
test('parses a task hint with quotes inside', t => {
59+
const data = `# Title
60+
description
61+
62+
## Page One
63+
description
64+
65+
+ Task One
66+
@test('01, 02')
67+
@hint('do \' " \` something')
68+
`;
69+
const expected = [{
70+
description: 'Task One',
71+
tests: [
72+
'01, 02'
73+
],
74+
hints: [
75+
'do \' " \` something'
76+
]
77+
}];
78+
const result = parse(data);
79+
t.deepEqual(result.pages[0].tasks, expected);
80+
});

‎test/task-test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import test from 'ava';
2+
import pegjs from 'pegjs';
3+
import { readFileSync } from 'fs';
4+
5+
const parser = readFileSync('../parser/index.pegjs', 'utf8');
6+
const parse = pegjs.buildParser(parser).parse;
7+
8+
test('parses a task test', t => {
9+
const data = `# Title
10+
description
11+
12+
## Page One
13+
description
14+
15+
+ Task One
16+
@test('01, 02')
17+
`;
18+
const expected = [{
19+
description: 'Task One',
20+
tests: [
21+
'01, 02'
22+
],
23+
hints: []
24+
}];
25+
const result = parse(data);
26+
t.deepEqual(result.pages[0].tasks, expected);
27+
});
28+
29+
test('parses multiple task tests', t => {
30+
const data = `# Title
31+
description
32+
33+
## Page One
34+
description
35+
36+
+ Task One
37+
@test('01, 02')
38+
@test('03, 04')
39+
`;
40+
const expected = [{
41+
description: 'Task One',
42+
tests: [
43+
'01, 02',
44+
'03, 04'
45+
],
46+
hints: []
47+
}];
48+
const result = parse(data);
49+
t.deepEqual(result.pages[0].tasks, expected);
50+
});
51+
52+
test('parses task tests across pages', t => {
53+
const data = `# Title
54+
description
55+
56+
## Page One
57+
description
58+
59+
+ Task One
60+
@test('01, 02')
61+
62+
+ Task Two
63+
@test('02, 01')
64+
`;
65+
const expected = [{
66+
description: 'Task One',
67+
tests: [
68+
'01, 02'
69+
],
70+
hints: []
71+
}, {
72+
description: 'Task Two',
73+
tests: [
74+
'02, 01'
75+
],
76+
hints: []
77+
}];
78+
const result = parse(data);
79+
t.deepEqual(result.pages[0].tasks, expected);
80+
});
81+
82+
test.todo('warns when missing a task test');

‎test/task.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,44 @@ import { readFileSync } from 'fs';
55
const parser = readFileSync('../parser/index.pegjs', 'utf8');
66
const parse = pegjs.buildParser(parser).parse;
77

8-
test.todo('parses a task description');
9-
test.todo('parses a second page with a task');
8+
test('parses a task description', t => {
9+
const data = `# Title
10+
description
1011
11-
test.todo('parses a task test');
12-
test.todo('warns when missing a task test');
13-
test.todo('parses multiple task tests');
14-
test.todo('parses task tests across pages');
12+
## Page One
13+
description
1514
16-
test.todo('parses a task hint');
17-
test.todo('parses multiple task hints');
18-
test.todo('parses a task hint with single quote inside');
15+
+ Task One
16+
`;
17+
const expected = [{
18+
description: 'Task One',
19+
tests: [],
20+
hints: []
21+
}];
22+
const result = parse(data);
23+
t.deepEqual(result.pages[0].tasks, expected);
24+
});
25+
26+
test('parses a second page with a task', t => {
27+
const data = `# Title
28+
description
29+
30+
## Page One
31+
description
32+
33+
+ Task One
34+
35+
+ Task Two
36+
`;
37+
const expected = [{
38+
description: 'Task One',
39+
tests: [],
40+
hints: []
41+
}, {
42+
description: 'Task Two',
43+
tests: [],
44+
hints: []
45+
}];
46+
const result = parse(data);
47+
t.deepEqual(result.pages[0].tasks, expected);
48+
});

0 commit comments

Comments
 (0)