summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-05-18 11:10:54 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-05-18 11:10:54 +0200
commit338f7028ecb11968f12d81be31a0e04c8b6c8edf (patch)
treeee3c71972bfecaafdbdf0b689e96b4bd51234910 /tests
parenta0894a794b1a3ef502872226af4c480e0347d1d3 (diff)
downloadweechat-338f7028ecb11968f12d81be31a0e04c8b6c8edf.zip
tests: add tests on alias functions
Functions tested: - alias_valid - alias_search - alias_string_add_word - alias_string_add_word_range - alias_string_add_arguments - alias_replace_args
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/unit/plugins/alias/test-alias.cpp283
2 files changed, 289 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 980d4ce2b..d0fe4af2a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -62,6 +62,12 @@ add_library(weechat_unit_tests_core STATIC ${LIB_WEECHAT_UNIT_TESTS_CORE_SRC})
# unit tests (plugins)
set(LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC unit/plugins/test-plugins.cpp)
+if(ENABLE_ALIAS)
+ list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC
+ unit/plugins/alias/test-alias.cpp
+ )
+endif()
+
if(ENABLE_IRC)
list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC
unit/plugins/irc/test-irc-batch.cpp
diff --git a/tests/unit/plugins/alias/test-alias.cpp b/tests/unit/plugins/alias/test-alias.cpp
new file mode 100644
index 000000000..92c287082
--- /dev/null
+++ b/tests/unit/plugins/alias/test-alias.cpp
@@ -0,0 +1,283 @@
+/*
+ * test-alias.cpp - test alias functions
+ *
+ * Copyright (C) 2023 Sébastien Helleu <flashcode@flashtux.org>
+ *
+ * This file is part of WeeChat, the extensible chat client.
+ *
+ * WeeChat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WeeChat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CppUTest/TestHarness.h"
+
+#include "tests/tests.h"
+
+extern "C"
+{
+#include "src/plugins/alias/alias.h"
+
+extern char *alias_replace_args (const char *alias_args, const char *user_args);
+}
+
+TEST_GROUP(Alias)
+{
+};
+
+/*
+ * Tests functions:
+ * alias_valid
+ */
+
+TEST(Alias, Valid)
+{
+ struct t_alias *alias;
+
+ alias = alias_new ("test_alias", "/mute", NULL);
+
+ LONGS_EQUAL(0, alias_valid (NULL));
+ LONGS_EQUAL(0, alias_valid ((struct t_alias *)0x1));
+ LONGS_EQUAL(0, alias_valid (alias + 1));
+
+ LONGS_EQUAL(1, alias_valid (alias));
+
+ alias_free (alias);
+}
+
+/*
+ * Tests functions:
+ * alias_search
+ */
+
+TEST(Alias, Search)
+{
+ struct t_alias *alias;
+
+ alias = alias_new ("test_alias", "/mute", NULL);
+
+ POINTERS_EQUAL(NULL, alias_search (NULL));
+ POINTERS_EQUAL(NULL, alias_search (""));
+ POINTERS_EQUAL(NULL, alias_search ("does_not_exist"));
+
+ POINTERS_EQUAL(alias, alias_search ("test_alias"));
+
+ alias_free (alias);
+}
+
+/*
+ * Tests functions:
+ * alias_string_add_word
+ * alias_string_add_word_range
+ * alias_string_add_arguments
+ * alias_replace_args
+ */
+
+TEST(Alias, ReplaceArgs)
+{
+ char *str;
+
+ POINTERS_EQUAL(NULL, alias_replace_args (NULL, NULL));
+ POINTERS_EQUAL(NULL, alias_replace_args (NULL, ""));
+ POINTERS_EQUAL(NULL, alias_replace_args ("", NULL));
+
+ WEE_TEST_STR("", alias_replace_args ("", ""));
+ WEE_TEST_STR("", alias_replace_args ("", "abc def"));
+ WEE_TEST_STR("/test", alias_replace_args ("/test", ""));
+ WEE_TEST_STR("/test $1", alias_replace_args ("/test \\$1", "abc def"));
+
+ /* arguments by index: $n */
+ WEE_TEST_STR("/test $0", alias_replace_args ("/test $0", ""));
+ WEE_TEST_STR("/test $0", alias_replace_args ("/test $0", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $1", ""));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $9", "abc def"));
+ WEE_TEST_STR("/test abc", alias_replace_args ("/test $1", "abc def"));
+ WEE_TEST_STR("/test def abc", alias_replace_args ("/test $2 $1", "abc def"));
+ WEE_TEST_STR("/test def abc", alias_replace_args ("/test $2 $1", "abc def"));
+
+ /* arguments from 1 to m: $-m */
+ WEE_TEST_STR("/test $-0", alias_replace_args ("/test $-0", ""));
+ WEE_TEST_STR("/test $-0", alias_replace_args ("/test $-0", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $-1", ""));
+ WEE_TEST_STR("/test abc", alias_replace_args ("/test $-1", "abc def"));
+ WEE_TEST_STR("/test abc def", alias_replace_args ("/test $-2", "abc def"));
+ WEE_TEST_STR("/test abc def", alias_replace_args ("/test $-3", "abc def"));
+ WEE_TEST_STR("/test abc def", alias_replace_args ("/test $-9", "abc def"));
+
+ /* arguments from n to last: $n- */
+ WEE_TEST_STR("/test $0-", alias_replace_args ("/test $0-", ""));
+ WEE_TEST_STR("/test $0-", alias_replace_args ("/test $0-", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $1-", ""));
+ WEE_TEST_STR("/test abc def", alias_replace_args ("/test $1-", "abc def"));
+ WEE_TEST_STR("/test def", alias_replace_args ("/test $2-", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $3-", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $9-", "abc def"));
+
+ /* arguments from n to m: $n-m */
+ WEE_TEST_STR("/test $0-0", alias_replace_args ("/test $0-0", ""));
+ WEE_TEST_STR("/test $0-0", alias_replace_args ("/test $0-0", "abc def"));
+ WEE_TEST_STR("/test $0-1", alias_replace_args ("/test $0-1", ""));
+ WEE_TEST_STR("/test $0-1", alias_replace_args ("/test $0-1", "abc def"));
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $1-1", ""));
+ WEE_TEST_STR("/test abc", alias_replace_args ("/test $1-1", "abc def"));
+ WEE_TEST_STR("/test abc def", alias_replace_args ("/test $1-2", "abc def"));
+ WEE_TEST_STR("/test def", alias_replace_args ("/test $2-2", "abc def"));
+ WEE_TEST_STR("/test def", alias_replace_args ("/test $2-3", "abc def"));
+ WEE_TEST_STR("/test def", alias_replace_args ("/test $2-9", "abc def"));
+
+ /* all arguments: $* */
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $*", ""));
+ WEE_TEST_STR("/test abc \"def\"", alias_replace_args ("/test $*", "abc \"def\""));
+
+ /* all arguments with double quotes escaped: $& */
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $&", ""));
+ WEE_TEST_STR("/test abc \\\"def\\\"", alias_replace_args ("/test $&", "abc \"def\""));
+
+ /* last argument: $~ */
+ WEE_TEST_STR("/test ", alias_replace_args ("/test $~", ""));
+ WEE_TEST_STR("/test abc", alias_replace_args ("/test $~", "abc"));
+ WEE_TEST_STR("/test def", alias_replace_args ("/test $~", "abc def"));
+
+ /* multiple arguments */
+ WEE_TEST_STR("/test def abc 'ghi jkl'",
+ alias_replace_args("/test $2 $1 '$3-'", "abc def ghi jkl"));
+}
+
+/*
+ * Tests functions:
+ * alias_run_command
+ */
+
+TEST(Alias, RunCommand)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_cb
+ */
+
+TEST(Alias, Cb)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_hook_command
+ */
+
+TEST(Alias, HookCommand)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_find_pos
+ */
+
+TEST(Alias, FindPos)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_insert
+ */
+
+TEST(Alias, Insert)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_remove_from_list
+ */
+
+TEST(Alias, RemoveFromList)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_rename
+ */
+
+TEST(Alias, Rename)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_free
+ */
+
+TEST(Alias, Free)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_free_all
+ */
+
+TEST(Alias, FreeAll)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_update_completion
+ */
+
+TEST(Alias, UpdateCompletion)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_name_valid
+ */
+
+TEST(Alias, NameValid)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_new
+ */
+
+TEST(Alias, New)
+{
+ /* TODO: write tests */
+}
+
+/*
+ * Tests functions:
+ * alias_add_to_infolist
+ */
+
+TEST(Alias, AddToInfolist)
+{
+ /* TODO: write tests */
+}