Merge pull request #541 from Mingun/correct-options-in-tests

Auto-add `allowedStartRules` to test options for `changeAST` method if it not defined
master
Futago-za Ryuu 6 years ago committed by GitHub
commit a02f8091e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.` );
}
} );
}
}
} );
}

@ -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(
@ -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 {

Loading…
Cancel
Save