diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-10-28 13:12:00 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-10-28 13:12:00 +0200 |
commit | b8c6a5a2e1d954f38ef730bec00869ee9912346a (patch) | |
tree | ba8652040f0448d840c2bb82f9adce8e782c5a11 /tests/scripts | |
parent | 1c4bb40c93e3ae441f7b7a1a78830a869bd5ce3c (diff) | |
download | weechat-b8c6a5a2e1d954f38ef730bec00869ee9912346a.zip |
tests: add tests on command/completion hooks scripting API functions
Diffstat (limited to 'tests/scripts')
-rw-r--r-- | tests/scripts/python/testapi.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py index 2c63856f2..e6b826e63 100644 --- a/tests/scripts/python/testapi.py +++ b/tests/scripts/python/testapi.py @@ -147,6 +147,50 @@ def test_display(): check(weechat.color('unknown') == '') +def completion_cb(data, completion_item, buf, completion): + """Completion callback.""" + check(data == 'completion_data') + check(completion_item == 'SCRIPT_NAME') + check(weechat.hook_completion_get_string(completion, 'args') == 'w') + weechat.hook_completion_list_add(completion, 'word_completed', + 0, weechat.WEECHAT_LIST_POS_END) + return weechat.WEECHAT_RC_OK + + +def command_cb(data, buf, args): + """Command callback.""" + check(data == 'command_data') + check(args == 'word_completed') + return weechat.WEECHAT_RC_OK + + +def command_run_cb(data, buf, command): + """Command_run callback.""" + check(data == 'command_run_data') + check(command == '/cmd' + 'SCRIPT_NAME' + ' word_completed') + return weechat.WEECHAT_RC_OK + + +def test_hooks(): + """Test function hook_command.""" + # hook_completion / hook_completion_args / and hook_command + hook_cmplt = weechat.hook_completion('SCRIPT_NAME', 'description', + 'completion_cb', 'completion_data') + hook_cmd = weechat.hook_command('cmd' + 'SCRIPT_NAME', 'description', + 'arguments', 'description arguments', + '%(' + 'SCRIPT_NAME' + ')', + 'command_cb', 'command_data') + weechat.command('', '/input insert /cmd' + 'SCRIPT_NAME' + ' w') + weechat.command('', '/input complete_next') + # hook_command_run + hook_cmd_run = weechat.hook_command_run('/cmd' + 'SCRIPT_NAME' + '*', + 'command_run_cb', 'command_run_data') + weechat.command('', '/input return') + weechat.unhook(hook_cmd_run) + weechat.unhook(hook_cmd) + weechat.unhook(hook_cmplt) + + def cmd_test_cb(data, buf, args): """Run all the tests.""" weechat.prnt('', '>>>') @@ -158,6 +202,7 @@ def cmd_test_cb(data, buf, args): test_lists() test_key() test_display() + test_hooks() weechat.prnt('', ' > TESTS END') return weechat.WEECHAT_RC_OK |