From 293610a432f156e0febaecbcc32f5907559e3174 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 16 Aug 2018 21:09:51 +1000 Subject: [PATCH] Add a test case for -once hooks and code style tweaks --- src/commands.cc | 4 ++-- src/hook_manager.cc | 5 +---- test/hooks/once/cmd | 1 + test/hooks/once/in | 1 + test/hooks/once/out | 1 + test/hooks/once/rc | 1 + 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 test/hooks/once/cmd create mode 100644 test/hooks/once/in create mode 100644 test/hooks/once/out create mode 100644 test/hooks/once/rc diff --git a/src/commands.cc b/src/commands.cc index 9d33e85d..98cbdbad 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -861,8 +861,8 @@ const CommandDesc add_hook_cmd = { Regex regex{parser[2], RegexCompileFlags::Optimize}; const String& command = parser[3]; auto group = parser.get_switch("group").value_or(StringView{}); - const auto flags = (parser.get_switch("always") ? HookFlags::Always : HookFlags::None) \ - | (parser.get_switch("once") ? HookFlags::Once : HookFlags::None); + const auto flags = (parser.get_switch("always") ? HookFlags::Always : HookFlags::None) | + (parser.get_switch("once") ? HookFlags::Once : HookFlags::None); get_scope(parser[0], context).hooks().add_hook(parser[1], group.str(), flags, std::move(regex), command); } diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 8dabb66a..3b63ee56 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -126,10 +126,7 @@ void HookManager::run_hook(StringView hook_name, StringView param, Context& cont if (to_run.hook->flags & HookFlags::Once) { - auto it = std::find_if(hook_list->value.begin(), hook_list->value.end(), - [&](const std::unique_ptr& h) - { return h.get() == to_run.hook; }); - + auto it = find(hook_list->value, to_run.hook); m_hooks_trash.push_back(std::move(*it)); hook_list->value.erase(it); } diff --git a/test/hooks/once/cmd b/test/hooks/once/cmd new file mode 100644 index 00000000..b1164fb4 --- /dev/null +++ b/test/hooks/once/cmd @@ -0,0 +1 @@ +iaaa diff --git a/test/hooks/once/in b/test/hooks/once/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/hooks/once/in @@ -0,0 +1 @@ + diff --git a/test/hooks/once/out b/test/hooks/once/out new file mode 100644 index 00000000..d0b67bf0 --- /dev/null +++ b/test/hooks/once/out @@ -0,0 +1 @@ +abaa diff --git a/test/hooks/once/rc b/test/hooks/once/rc new file mode 100644 index 00000000..2a7453bd --- /dev/null +++ b/test/hooks/once/rc @@ -0,0 +1 @@ +hook global -once InsertChar a 'exec b'