Beef up completion tests

This commit is contained in:
ridiculousfish 2013-10-12 12:04:31 -07:00
parent b60db79866
commit cbd8a27a6d
3 changed files with 40 additions and 4 deletions

View file

@ -1122,12 +1122,42 @@ static void test_complete(void)
assert(completions.at(1).completion == L"$Bar1");
completions.clear();
complete(L"echo (/bin/ech", completions, COMPLETION_REQUEST_DEFAULT);
complete(L"echo (/bin/mkdi", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 1);
assert(completions.at(0).completion == L"o");
assert(completions.at(0).completion == L"r");
completions.clear();
complete(L"echo (ls /bin/mkdi", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 1);
assert(completions.at(0).completion == L"r");
completions.clear();
complete(L"echo (command ls /bin/mkdi", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 1);
assert(completions.at(0).completion == L"r");
/* Add a function and test completing it in various ways */
struct function_data_t func_data;
func_data.name = L"scuttlebutt";
func_data.definition = L"echo gongoozle";
function_add(func_data, parser_t::principal_parser());
/* Complete a function name */
completions.clear();
complete(L"echo (scuttlebut", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 1);
assert(completions.at(0).completion == L"t");
/* But not with the command prefix */
completions.clear();
complete(L"echo (command scuttlebut", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 0);
/* Not with the builtin prefix */
completions.clear();
complete(L"echo (builtin scuttlebut", completions, COMPLETION_REQUEST_DEFAULT);
assert(completions.size() == 0);
complete_set_variable_names(NULL);
}

View file

@ -192,7 +192,13 @@ void function_add(const function_data_t &data, const parser_t &parser)
/* Create and store a new function */
const wchar_t *filename = reader_current_filename();
int def_offset = parser.line_number_of_character_at_offset(parser.current_block->tok_pos) - 1;
int def_offset = -1;
if (parser.current_block != NULL)
{
def_offset = parser.line_number_of_character_at_offset(parser.current_block->tok_pos);
}
const function_map_t::value_type new_pair(data.name, function_info_t(data, filename, def_offset, is_autoload));
loaded_functions.insert(new_pair);

View file

@ -39,7 +39,7 @@ struct function_data_t
/**
Function definition
*/
wchar_t *definition;
const wchar_t *definition;
/**
List of all event handlers for this function
*/