summaryrefslogtreecommitdiff
path: root/tests/unit/gui/test-gui-key.cpp
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-03-12 00:32:48 +0100
committerSébastien Helleu <flashcode@flashtux.org>2023-03-17 18:52:30 +0100
commit0c4a5528acfd183705f5b298b478a0a61a6df7de (patch)
treef3d29654b1ab224551a9386a4e5f35fd7a76f2fc /tests/unit/gui/test-gui-key.cpp
parent3b8f9d4547df77e4c85b3b870ba21a67d97b31dc (diff)
downloadweechat-0c4a5528acfd183705f5b298b478a0a61a6df7de.zip
core: display a warning when trying to bind a raw key code or invalid key (missing comma)
Diffstat (limited to 'tests/unit/gui/test-gui-key.cpp')
-rw-r--r--tests/unit/gui/test-gui-key.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/unit/gui/test-gui-key.cpp b/tests/unit/gui/test-gui-key.cpp
index f81cfd47d..5596279a4 100644
--- a/tests/unit/gui/test-gui-key.cpp
+++ b/tests/unit/gui/test-gui-key.cpp
@@ -35,6 +35,7 @@ extern int gui_key_get_current_context ();
extern char *gui_key_legacy_internal_code (const char *key);
extern char *gui_key_fix (const char *key);
extern int gui_key_is_safe (int context, const char *key);
+extern int gui_key_seems_valid (int context, const char *key);
extern struct t_config_option *gui_key_new_option (int context,
const char *name,
const char *value);
@@ -1036,6 +1037,44 @@ TEST(GuiKey, IsSafe)
/*
* Tests functions:
+ * gui_key_chunk_seems_valid
+ * gui_key_seems_valid
+ */
+
+TEST(GuiKey, SeemsValid)
+{
+ /* invalid: NULL or empty string */
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, NULL));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, ""));
+
+ /* raw codes: considered not valid */
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-[A"));
+
+ /* invalid keys: missing comma */
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "ab"));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "@a"));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "homeZ"));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-cb"));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-updown"));
+ LONGS_EQUAL(0, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "@chat:button1"));
+
+ /* valid keys */
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "a"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "A"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "é"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "/"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-a"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-ctrl-a"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-c,b"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "meta-w,meta-up"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "ctrl-left"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_DEFAULT, "ctrl-u"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_CURSOR, "@chat:q"));
+ LONGS_EQUAL(1, gui_key_seems_valid (GUI_KEY_CONTEXT_MOUSE, "@chat:button1"));
+}
+
+/*
+ * Tests functions:
* gui_key_option_change_cb
*/