Skip to content

Commit

Permalink
Auto-add allowedStartRules to test options for changeAST and `rep…
Browse files Browse the repository at this point in the history
…ortError` methods if it not defined
  • Loading branch information
Mingun committed Dec 18, 2017
1 parent 75d6554 commit 3e89534
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/compiler/passes/report-undefined-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ function reportUndefinedRules( ast, options ) {

check( ast );

if ( options.allowedStartRules ) {
options.allowedStartRules.forEach( rule => {

options.allowedStartRules.forEach( rule => {
if ( ! asts.findRule( ast, rule ) ) {

if ( ! asts.findRule( ast, rule ) ) {
throw new GrammarError( `Start rule "${ rule }" is not defined.` );

throw new GrammarError( `Start rule "${ rule }" is not defined.` );

}

} );
}

}
} );

}

Expand Down
16 changes: 16 additions & 0 deletions test/spec/unit/compiler/passes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ module.exports = function ( chai, utils ) {

const ast = parser.parse( grammar );

if ( ! options.allowedStartRules ) {

options.allowedStartRules = ast.rules.length > 0
? [ ast.rules[ 0 ].name ]
: [];

}

utils.flag( this, "object" )( ast, options );

this.assert(
Expand All @@ -73,6 +81,14 @@ module.exports = function ( chai, utils ) {

const ast = parser.parse( grammar );

if ( ! options.allowedStartRules ) {

options.allowedStartRules = ast.rules.length > 0
? [ ast.rules[ 0 ].name ]
: [];

}

let passed, result;

try {
Expand Down

0 comments on commit 3e89534

Please sign in to comment.