mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Port test_new_parser_correctness
This commit is contained in:
parent
3fab9adab6
commit
afddb5dd3e
2 changed files with 27 additions and 40 deletions
|
@ -293,6 +293,33 @@ add_test!("test_parser", || {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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", || {
|
add_test!("test_eval_recursion_detection", || {
|
||||||
// Ensure that we don't crash on infinite self recursion and mutual recursion. These must use
|
// 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.
|
// the principal parser because we cannot yet execute jobs on other parsers.
|
||||||
|
|
|
@ -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
|
// 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".
|
// '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,
|
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("new_parser_ll2"), test_new_parser_ll2},
|
||||||
{TEST_GROUP("test_abbreviations"), test_abbreviations},
|
{TEST_GROUP("test_abbreviations"), test_abbreviations},
|
||||||
{TEST_GROUP("new_parser_fuzzing"), test_new_parser_fuzzing},
|
{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_ad_hoc"), test_new_parser_ad_hoc},
|
||||||
{TEST_GROUP("new_parser_errors"), test_new_parser_errors},
|
{TEST_GROUP("new_parser_errors"), test_new_parser_errors},
|
||||||
{TEST_GROUP("error_messages"), test_error_messages},
|
{TEST_GROUP("error_messages"), test_error_messages},
|
||||||
|
|
Loading…
Reference in a new issue