summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2020-08-22 08:55:16 +0200
committerSébastien Helleu <flashcode@flashtux.org>2020-08-22 08:55:16 +0200
commit268aa631c6b464c0d97dce5dbe76f145a6cc5f68 (patch)
tree00ef2b36db0fc64e2723442f1750934aec030901 /tests
parent7dd5abd6252d108858f31a717a127f86d5c206c1 (diff)
downloadweechat-268aa631c6b464c0d97dce5dbe76f145a6cc5f68.zip
api: add function string_color_code_size (issue #1547)
Diffstat (limited to 'tests')
-rw-r--r--tests/scripts/python/testapi.py4
-rw-r--r--tests/unit/gui/test-gui-color.cpp89
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py
index 2fbf8370d..aaa03157a 100644
--- a/tests/scripts/python/testapi.py
+++ b/tests/scripts/python/testapi.py
@@ -71,6 +71,10 @@ def test_strings():
check(weechat.string_format_size(1) == '1 byte')
check(weechat.string_format_size(2097152) == '2.10 MB')
check(weechat.string_format_size(420000000) == '420.00 MB')
+ check(weechat.string_color_code_size('') == 0)
+ check(weechat.string_color_code_size('test') == 0)
+ str_color = weechat.color('yellow,red')
+ check(weechat.string_color_code_size(str_color) == 7)
check(weechat.string_remove_color('test', '?') == 'test')
check(weechat.string_is_command_char('/test') == 1)
check(weechat.string_is_command_char('test') == 0)
diff --git a/tests/unit/gui/test-gui-color.cpp b/tests/unit/gui/test-gui-color.cpp
index 19c861dd7..32fe7cd53 100644
--- a/tests/unit/gui/test-gui-color.cpp
+++ b/tests/unit/gui/test-gui-color.cpp
@@ -235,6 +235,95 @@ TEST(GuiColor, GetCustom)
/*
* Tests functions:
+ * gui_color_code_size
+ */
+
+TEST(GuiColor, CodeSize)
+{
+ char string[256];
+
+ /* NULL/empty string */
+ LONGS_EQUAL(0, gui_color_code_size (NULL));
+ LONGS_EQUAL(0, gui_color_code_size (""));
+
+ /* no color code */
+ LONGS_EQUAL(0, gui_color_code_size ("test"));
+
+ /* reset */
+ LONGS_EQUAL(1, gui_color_code_size (gui_color_get_custom ("reset")));
+
+ /* reset (×2) */
+ snprintf (string, sizeof (string),
+ "%s%s",
+ gui_color_get_custom ("reset"),
+ gui_color_get_custom ("reset"));
+ LONGS_EQUAL(1, gui_color_code_size (string));
+
+ /* resetcolor */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("resetcolor")));
+
+ /* emphasis */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("emphasis")));
+
+ /* bold */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("bold")));
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("-bold")));
+
+ /* reverse */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("reverse")));
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("-reverse")));
+
+ /* italic */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("italic")));
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("-italic")));
+
+ /* underline */
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("underline")));
+ LONGS_EQUAL(2, gui_color_code_size (gui_color_get_custom ("-underline")));
+
+ /* bar_fg */
+ LONGS_EQUAL(3, gui_color_code_size (gui_color_get_custom ("bar_fg")));
+
+ /* bar_delim */
+ LONGS_EQUAL(3, gui_color_code_size (gui_color_get_custom ("bar_delim")));
+
+ /* bar_bg */
+ LONGS_EQUAL(3, gui_color_code_size (gui_color_get_custom ("bar_bg")));
+
+ /* fg color */
+ LONGS_EQUAL(4, gui_color_code_size (gui_color_get_custom ("blue")));
+
+ /* bg color */
+ LONGS_EQUAL(4, gui_color_code_size (gui_color_get_custom (",blue")));
+
+ /* fg+bg color */
+ LONGS_EQUAL(7, gui_color_code_size (gui_color_get_custom ("yellow,blue")));
+
+ /* fg+bg color (×2) */
+ snprintf (string, sizeof (string),
+ "%s%s",
+ gui_color_get_custom ("yellow,blue"),
+ gui_color_get_custom ("yellow,blue"));
+ LONGS_EQUAL(7, gui_color_code_size (string));
+
+ /* fg terminal color */
+ LONGS_EQUAL(8, gui_color_code_size (gui_color_get_custom ("214")));
+
+ /* bg terminal color */
+ LONGS_EQUAL(8, gui_color_code_size (gui_color_get_custom (",214")));
+
+ /* fg+bg terminal color */
+ LONGS_EQUAL(15, gui_color_code_size (gui_color_get_custom ("227,240")));
+
+ /* fg terminal color + bg color */
+ LONGS_EQUAL(11, gui_color_code_size (gui_color_get_custom ("227,blue")));
+
+ /* WeeChat color */
+ LONGS_EQUAL(3, gui_color_code_size (GUI_COLOR(GUI_COLOR_CHAT_HOST)));
+}
+
+/*
+ * Tests functions:
* gui_color_decode
*/