From 94adb53b1f9154369e85fc783e15daad866301d5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 10 Sep 2018 18:36:04 -0700 Subject: [PATCH] Eliminate complete_set_variable_names --- src/complete.cpp | 20 ++------------------ src/complete.h | 2 -- src/fish_tests.cpp | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index fbe453264..36afd5441 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -74,20 +74,6 @@ static const wcstring &C_(const wcstring &s) { return s; } static void complete_load(const wcstring &name, bool reload); -/// Testing apparatus. -const wcstring_list_t *s_override_variable_names = NULL; - -void complete_set_variable_names(const wcstring_list_t *names) { - s_override_variable_names = names; -} - -static inline wcstring_list_t complete_get_variable_names(const environment_t &vars) { - if (s_override_variable_names != NULL) { - return *s_override_variable_names; - } - return vars.get_names(0); -} - /// Struct describing a completion option entry. /// /// If option is empty, the comp field must not be empty and contains a list of arguments to the @@ -1125,10 +1111,8 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) { size_t varlen = str.length() - start_offset; bool res = false; - const wcstring_list_t names = complete_get_variable_names(vars); - for (size_t i = 0; i < names.size(); i++) { - const wcstring &env_name = names.at(i); - + const wcstring_list_t names = vars.get_names(0); + for (const wcstring &env_name : vars.get_names(0)) { string_fuzzy_match_t match = string_fuzzy_match_string(var, env_name, this->max_fuzzy_match_type()); if (match.type == fuzzy_match_none) { diff --git a/src/complete.h b/src/complete.h index 0abd68208..d73ae1d8c 100644 --- a/src/complete.h +++ b/src/complete.h @@ -196,8 +196,6 @@ void append_completion(std::vector *completions, wcstring comp, wcstring desc = wcstring(), int flags = 0, string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact)); -/// Function used for testing. -void complete_set_variable_names(const wcstring_list_t *names); /// Support for "wrap targets." A wrap target is a command that completes like another command. bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target); diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 82497060b..24decdb44 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2333,13 +2333,19 @@ static void test_colors() { static void test_complete() { say(L"Testing complete"); - const wchar_t *name_strs[] = {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3"}; - size_t count = sizeof name_strs / sizeof *name_strs; - const wcstring_list_t names(name_strs, name_strs + count); - std::vector completions; - complete_set_variable_names(&names); - env_vars_snapshot_t vars; + struct test_complete_vars_t : environment_t { + wcstring_list_t get_names(int flags) const override { + return {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3"}; + } + maybe_t get(const wcstring &key, + env_mode_flags_t mode = ENV_DEFAULT) const override { + return {}; + } + }; + test_complete_vars_t vars; + + completion_list_t completions; complete(L"$", &completions, COMPLETION_REQUEST_DEFAULT, vars); completions_sort_and_prioritize(&completions); do_test(completions.size() == 6); @@ -2510,7 +2516,6 @@ static void test_complete() { popd(); completions.clear(); - complete_set_variable_names(NULL); // Test abbreviations. auto &pvars = parser_t::principal_parser().vars();