File tree Expand file tree Collapse file tree 7 files changed +75
-30
lines changed Expand file tree Collapse file tree 7 files changed +75
-30
lines changed Original file line number Diff line number Diff line change 1212 /** * "pegjs/_types.js" ***/
1313
1414 const pageTypes = [' onPageComplete' ];
15- const taskTypes = [' tests' , ' actions ' , ' hints ' ]
15+ const taskTypes = [' tests' , ' hints ' , ' actions ' ]
1616
1717 /** * "pegjs/_functions.js" ***/
1818
@@ -132,10 +132,13 @@ page_task
132132 actions : task_actions *
133133 break ?
134134
135- { let task = { description, tests : [], hints : [] };
135+ { let task = { description };
136136 actions .forEach (({type, value}) => {
137137 // task actions
138138 if (taskTypes .includes (type)) {
139+ if (! task .hasOwnProperty (type)) {
140+ task[type] = [];
141+ }
139142 task[type].push (value);
140143 // page actions
141144 } else if (pageTypes .includes (type)) {
@@ -199,16 +202,24 @@ on_page_complete
199202task_action
200203 = '@action'
201204 '('
202- type : action_type
203- ')'
205+ action : action_type
206+ ')'
207+ break
208+
209+ {
210+ return {
211+ type: ' actions' ,
212+ value: action,
213+ };
214+ }
204215
205216action_type
206- = action_open
207- / action_set
217+ = action : action_open
218+ /*/ action_set
208219 / action_insert
209220 / action_write
210- / action_write_from_file
211- break
221+ / action_write_from_file*/
222+
212223
213224action_open
214225 = 'open'
@@ -217,6 +228,7 @@ action_open
217228 file : file_path
218229 quote
219230 ')'
231+ { return ` open("${ file .join (' ' )} ")` ; }
220232
221233action_insert
222234 = 'insert'
Original file line number Diff line number Diff line change 11const pageTypes = [ 'onPageComplete' ] ;
2- const taskTypes = [ 'tests' , 'actions ' , 'hints ' ]
2+ const taskTypes = [ 'tests' , 'hints ' , 'actions ' ]
Original file line number Diff line number Diff line change 11task_action
22 = '@action'
33 '('
4- type : action_type
5- ')'
4+ action : action_type
5+ ')'
6+ break
7+
8+ {
9+ return {
10+ type: ' actions' ,
11+ value: action,
12+ };
13+ }
614
715action_type
8- = action_open
9- / action_set
16+ = action : action_open
17+ /*/ action_set
1018 / action_insert
1119 / action_write
12- / action_write_from_file
13- break
20+ / action_write_from_file*/
21+
1422
1523action_open
1624 = 'open'
@@ -19,6 +27,7 @@ action_open
1927 file : file_path
2028 quote
2129 ')'
30+ { return ` open("${ file .join (' ' )} ")` ; }
2231
2332action_insert
2433 = 'insert'
Original file line number Diff line number Diff line change @@ -5,10 +5,13 @@ page_task
55 actions : task_actions *
66 break ?
77
8- { let task = { description, tests : [], hints : [] };
8+ { let task = { description };
99 actions .forEach (({type, value}) => {
1010 // task actions
1111 if (taskTypes .includes (type)) {
12+ if (! task .hasOwnProperty (type)) {
13+ task[type] = [];
14+ }
1215 task[type].push (value);
1316 // page actions
1417 } else if (pageTypes .includes (type)) {
Original file line number Diff line number Diff line change 11import test from 'ava' ;
22import parse from './_parser' ;
33
4- test . todo ( 'parses an action: open' ) ;
4+ const start = `# Title
5+ description
56
7+ ## Page One
8+ description
69
7- test . todo ( 'parses multiple actions: open' ) ;
10+ + Task One
11+ @test('01, 02')
12+ ` ;
13+
14+ test ( 'parses an action: open' , t => {
15+ const data = `${ start } @action(open('file.js'))
16+ ` ;
17+ const expected = [ "open(\"file.js\")" ] ;
18+ const result = parse ( data ) ;
19+ t . deepEqual ( result . pages [ 0 ] . tasks [ 0 ] . actions , expected ) ;
20+ } ) ;
21+
22+ test . skip ( 'parses an action: set' , t => {
23+ const data = `${ start }
24+ @action(set('var a = 42;'))
25+ ` ;
26+ const expected = [ "set('var a = 42;')" ] ;
27+ const result = parse ( data ) ;
28+ t . deepEqual ( result . pages [ 0 ] . tasks [ 0 ] . actions , expected ) ;
29+ } ) ;
30+
31+ test . skip ( 'parses an action: insert' , t => {
32+ const data = `${ start }
33+ @action(insert('var a = 42;'))
34+ ` ;
35+ const expected = [ "insert('var a = 42;')" ] ;
36+ const result = parse ( data ) ;
37+ t . deepEqual ( result . pages [ 0 ] . tasks [ 0 ] . actions , expected ) ;
38+ } ) ;
839
9- test . todo ( 'parses an action: set' ) ;
10- test . todo ( 'parses an action: insert' ) ;
1140test . todo ( 'parses an action: write' ) ;
1241test . todo ( 'parses an action: writeFileFromFile' ) ;
42+
43+ test . todo ( 'parses multiple actions: open & set' ) ;
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ description
1616 tests : [
1717 '01, 02'
1818 ] ,
19- hints : [ ]
2019 } ] ;
2120 const result = parse ( data ) ;
2221 t . deepEqual ( result . pages [ 0 ] . tasks , expected ) ;
@@ -39,7 +38,6 @@ description
3938 '01, 02' ,
4039 '03, 04'
4140 ] ,
42- hints : [ ]
4341 } ] ;
4442 const result = parse ( data ) ;
4543 t . deepEqual ( result . pages [ 0 ] . tasks , expected ) ;
@@ -63,13 +61,11 @@ description
6361 tests : [
6462 '01, 02'
6563 ] ,
66- hints : [ ]
6764 } , {
6865 description : 'Task Two' ,
6966 tests : [
7067 '02, 01'
7168 ] ,
72- hints : [ ]
7369 } ] ;
7470 const result = parse ( data ) ;
7571 t . deepEqual ( result . pages [ 0 ] . tasks , expected ) ;
Original file line number Diff line number Diff line change @@ -12,8 +12,6 @@ description
1212` ;
1313 const expected = [ {
1414 description : 'Task One' ,
15- tests : [ ] ,
16- hints : [ ]
1715 } ] ;
1816 const result = parse ( data ) ;
1917 t . deepEqual ( result . pages [ 0 ] . tasks , expected ) ;
@@ -32,12 +30,8 @@ description
3230` ;
3331 const expected = [ {
3432 description : 'Task One' ,
35- tests : [ ] ,
36- hints : [ ]
3733 } , {
3834 description : 'Task Two' ,
39- tests : [ ] ,
40- hints : [ ]
4135 } ] ;
4236 const result = parse ( data ) ;
4337 t . deepEqual ( result . pages [ 0 ] . tasks , expected ) ;
You can’t perform that action at this time.
0 commit comments