Convert some of the fixture grammars from JSON to JS

These tests are easier to write and maintain if the grammars are just JS,
like grammars normally are. It doesn't slow the tests down significantly
to shell out to `node` for each of these grammars.
This commit is contained in:
Max Brunsfeld 2021-10-22 18:47:13 -06:00
parent ddb12dc0c6
commit d05c665863
43 changed files with 386 additions and 792 deletions

View file

@ -157,7 +157,7 @@ fn generate_parser_for_grammar_with_opts(
})
}
fn load_grammar_file(grammar_path: &Path) -> Result<String> {
pub fn load_grammar_file(grammar_path: &Path) -> Result<String> {
match grammar_path.extension().and_then(|e| e.to_str()) {
Some("js") => Ok(load_js_grammar_file(grammar_path)?),
Some("json") => Ok(fs::read_to_string(grammar_path)?),

View file

@ -269,9 +269,12 @@ fn test_feature_corpus_files() {
}
let test_path = entry.path();
let grammar_path = test_path.join("grammar.json");
let mut grammar_path = test_path.join("grammar.js");
if !grammar_path.exists() {
grammar_path = test_path.join("grammar.json");
}
let error_message_path = test_path.join("expected_error.txt");
let grammar_json = fs::read_to_string(grammar_path).unwrap();
let grammar_json = generate::load_grammar_file(&grammar_path).unwrap();
let generate_result = generate::generate_parser_for_grammar(&grammar_json);
if error_message_path.exists() {