From afddb5dd3e47c22d6ae4f984b9be459d570fd660 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 9 Dec 2023 19:20:43 +0100 Subject: [PATCH] Port test_new_parser_correctness --- fish-rust/src/tests/parser.rs | 27 +++++++++++++++++++++++ src/fish_tests.cpp | 40 ----------------------------------- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/fish-rust/src/tests/parser.rs b/fish-rust/src/tests/parser.rs index 0433a560a..b2da9f1c5 100644 --- a/fish-rust/src/tests/parser.rs +++ b/fish-rust/src/tests/parser.rs @@ -293,6 +293,33 @@ fn detect_argument_errors(src: &str) -> Result<(), ParserTestErrorBits> { ); }); +add_test!("test_new_parser_correctness", || { + macro_rules! validate { + ($src:expr, $ok:expr) => { + let ast = Ast::parse(L!($src), ParseTreeFlags::default(), None); + assert_eq!(ast.errored(), !$ok); + }; + } + validate!("; ; ; ", true); + validate!("if ; end", false); + validate!("if true ; end", true); + validate!("if true; end ; end", false); + validate!("if end; end ; end", false); + validate!("if end", false); + validate!("end", false); + validate!("for i i", false); + validate!("for i in a b c ; end", true); + validate!("begin end", true); + validate!("begin; end", true); + validate!("begin if true; end; end;", true); + validate!("begin if true ; echo hi ; end; end", true); + validate!("true && false || false", true); + validate!("true || false; and true", true); + validate!("true || ||", false); + validate!("|| true", false); + validate!("true || \n\n false", true); +}); + add_test!("test_eval_recursion_detection", || { // Ensure that we don't crash on infinite self recursion and mutual recursion. These must use // the principal parser because we cannot yet execute jobs on other parsers. diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5f817e0c1..a4e85728e 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1077,45 +1077,6 @@ static void test_input() { } } -// todo!("port this") -static void test_new_parser_correctness() { - say(L"Testing parser correctness"); - const struct parser_test_t { - const wchar_t *src; - bool ok; - } parser_tests[] = { - {L"; ; ; ", true}, - {L"if ; end", false}, - {L"if true ; end", true}, - {L"if true; end ; end", false}, - {L"if end; end ; end", false}, - {L"if end", false}, - {L"end", false}, - {L"for i i", false}, - {L"for i in a b c ; end", true}, - {L"begin end", true}, - {L"begin; end", true}, - {L"begin if true; end; end;", true}, - {L"begin if true ; echo hi ; end; end", true}, - {L"true && false || false", true}, - {L"true || false; and true", true}, - {L"true || ||", false}, - {L"|| true", false}, - {L"true || \n\n false", true}, - }; - - for (const auto &test : parser_tests) { - auto ast = ast_parse(test.src); - bool success = !ast->errored(); - if (success && !test.ok) { - err(L"\"%ls\" should NOT have parsed, but did", test.src); - } else if (!success && test.ok) { - err(L"\"%ls\" should have parsed, but failed", test.src); - } - } - say(L"Parse tests complete"); -} - // Given that we have an array of 'fuzz_count' strings, we wish to enumerate all permutations of // 'len' values. We do this by incrementing an integer, interpreting it as "base fuzz_count". static inline bool string_for_permutation(const wcstring *fuzzes, size_t fuzz_count, size_t len, @@ -1807,7 +1768,6 @@ static const test_t s_tests[]{ {TEST_GROUP("new_parser_ll2"), test_new_parser_ll2}, {TEST_GROUP("test_abbreviations"), test_abbreviations}, {TEST_GROUP("new_parser_fuzzing"), test_new_parser_fuzzing}, - {TEST_GROUP("new_parser_correctness"), test_new_parser_correctness}, {TEST_GROUP("new_parser_ad_hoc"), test_new_parser_ad_hoc}, {TEST_GROUP("new_parser_errors"), test_new_parser_errors}, {TEST_GROUP("error_messages"), test_error_messages},