Fix for issue where 'function' would not define a function if the

arguments came before its name. Fixes #1240
This commit is contained in:
ridiculousfish
2014-01-14 02:29:53 -08:00
parent ff5e2746da
commit 28c7094f5b
4 changed files with 53 additions and 4 deletions

View File

@@ -2417,6 +2417,38 @@ static void test_new_parser_ll2(void)
if (deco != tests[i].deco)
err(L"When parsing '%ls', expected decoration %d but got %d on line %ld", tests[i].src.c_str(), (int)tests[i].deco, (int)deco, (long)__LINE__);
}
/* Verify that 'function -h' and 'function --help' are plain statements but 'function --foo' is not (#1240) */
const struct
{
wcstring src;
parse_token_type_t type;
}
tests2[] =
{
{L"function -h", symbol_plain_statement},
{L"function --help", symbol_plain_statement},
{L"function --foo ; end", symbol_function_header},
{L"function foo ; end", symbol_function_header},
};
for (size_t i=0; i < sizeof tests2 / sizeof *tests2; i++)
{
parse_node_tree_t tree;
if (! parse_tree_from_string(tests2[i].src, parse_flag_none, &tree, NULL))
{
err(L"Failed to parse '%ls'", tests2[i].src.c_str());
}
const parse_node_tree_t::parse_node_list_t node_list = tree.find_nodes(tree.at(0), tests2[i].type);
if (node_list.size() == 0)
{
err(L"Failed to find node of type '%ls'", token_type_description(tests2[i].type).c_str());
}
else if (node_list.size() > 1)
{
err(L"Found too many nodes of type '%ls'", token_type_description(tests2[i].type).c_str());
}
}
}
static void test_new_parser_ad_hoc()