From dacd29b1d75182bcc463a0d110ea8e1584f38ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 11 Nov 2025 10:43:26 +0100 Subject: [PATCH] tests: add unit tests on command `/print` --- tests/unit/core/test-core-command.cpp | 93 ++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/tests/unit/core/test-core-command.cpp b/tests/unit/core/test-core-command.cpp index a0a2daed5..dff5dfb20 100644 --- a/tests/unit/core/test-core-command.cpp +++ b/tests/unit/core/test-core-command.cpp @@ -1187,7 +1187,98 @@ TEST(CoreCommand, Plugin) TEST(CoreCommand, Print) { - /* TODO: write tests */ + WEE_CMD_CORE_ERROR_GENERIC("/print -xxx"); + + /* /print */ + WEE_CMD_CORE("/print"); + WEE_CHECK_MSG_CORE("", ""); + WEE_CMD_CORE("/print hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print \\-hello"); + WEE_CHECK_MSG_CORE("", "-hello"); + WEE_CMD_CORE("/print prefix\\thello"); + WEE_CHECK_MSG_CORE("prefix", "hello"); + + /* /print -buffer */ + WEE_CMD_CORE("/buffer add test"); + WEE_CMD_CORE_ERROR_GENERIC("/print -buffer"); + WEE_CMD_CORE_ERROR_GENERIC("/print -buffer xxx"); + WEE_CMD_CORE("/print -buffer core.test hello"); + WEE_CHECK_MSG_BUFFER("core.test", "", "hello"); + WEE_CMD_CORE("/print -buffer core.weechat hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/buffer close test"); + + /* /print -core, /print -current */ + WEE_CMD_CORE("/print -core hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print -current hello"); + WEE_CHECK_MSG_CORE("", "hello"); + + /* /print -newbuffer */ + WEE_CMD_CORE_ERROR_GENERIC("/print -newbuffer"); + WEE_CMD_CORE_ERROR_MSG("/print -newbuffer weechat", + "Buffer name \"weechat\" is reserved for WeeChat"); + WEE_CMD_CORE("/print -newbuffer test hello"); + WEE_CHECK_MSG_BUFFER("core.test", "", "hello"); + WEE_CMD_CORE("/buffer close test"); + WEE_CMD_CORE("/print -newbuffer test -free -switch hello"); + WEE_CHECK_MSG_BUFFER("core.test", "", "hello"); + WEE_CMD_CORE("/buffer close test"); + + /* /print -escape */ + WEE_CMD_CORE("/print -escape hello\\a"); + WEE_CHECK_MSG_CORE("", "hello\a"); + + /* /print -y */ + WEE_CMD_CORE("/buffer add -free test"); + WEE_CMD_CORE_ERROR_GENERIC("/print -buffer core.test -y"); + WEE_CMD_CORE_ERROR_GENERIC("/print -buffer core.test -y xxx hello"); + WEE_CMD_CORE("/print -buffer core.test -y 5 hello"); + WEE_CHECK_MSG_BUFFER("core.test", "", "hello"); + WEE_CMD_CORE("/print -buffer core.test -y -1 hello"); + WEE_CHECK_MSG_BUFFER("core.test", "", "hello"); + WEE_CMD_CORE("/buffer close test"); + + /* /print -date */ + WEE_CMD_CORE_ERROR_GENERIC("/print -date"); + WEE_CMD_CORE_ERROR_GENERIC("/print -date xxx"); + WEE_CMD_CORE_ERROR_GENERIC("/print -date -x"); + WEE_CMD_CORE_ERROR_GENERIC("/print -date +x"); + WEE_CMD_CORE("/print -date 0 hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print -date -1 hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print -date +1 hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print -date 10:32:05 hello"); + WEE_CHECK_MSG_CORE("", "hello"); + WEE_CMD_CORE("/print -date 2025-10-11T10:32:09.123456Z hello"); + WEE_CHECK_MSG_CORE("", "hello"); + + /* /print -tags */ + WEE_CMD_CORE_ERROR_GENERIC("/print -tags"); + WEE_CMD_CORE("/print -tags tag1,tag2,tag3 hello"); + WEE_CHECK_MSG_CORE("", "hello"); + + /* /print -action, /print -error, /print -join, /print -network, /print -quit */ + WEE_CMD_CORE("/print -action hello"); + WEE_CHECK_MSG_CORE(GUI_CHAT_PREFIX_ACTION_DEFAULT, "hello"); + WEE_CMD_CORE("/print -error hello"); + WEE_CHECK_MSG_CORE(GUI_CHAT_PREFIX_ERROR_DEFAULT, "hello"); + WEE_CMD_CORE("/print -join hello"); + WEE_CHECK_MSG_CORE(GUI_CHAT_PREFIX_JOIN_DEFAULT, "hello"); + WEE_CMD_CORE("/print -network hello"); + WEE_CHECK_MSG_CORE(GUI_CHAT_PREFIX_NETWORK_DEFAULT, "hello"); + WEE_CMD_CORE("/print -quit hello"); + WEE_CHECK_MSG_CORE(GUI_CHAT_PREFIX_QUIT_DEFAULT, "hello"); + + /* /print -stdout, /print -stderr */ + WEE_CMD_CORE("/print -stdout hello"); + WEE_CMD_CORE("/print -stderr hello"); + + /* /print -beep */ + WEE_CMD_CORE("/print -beep"); } /*