diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-12 20:14:36 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-10-12 20:14:36 +0200 |
commit | 8fc8f728d49110ac44d403977f42afbdaf9d371e (patch) | |
tree | bbda7dc06b38f535bfeed53c6ecc9d245eab04b2 /tests | |
parent | 9535f4a70be7fa67bf65b4dc88b9681b2b755c4c (diff) | |
download | weechat-8fc8f728d49110ac44d403977f42afbdaf9d371e.zip |
core: add reverse of string for screen in evaluation of expressions with "revscr:"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/core/test-core-eval.cpp | 12 | ||||
-rw-r--r-- | tests/unit/core/test-core-string.cpp | 70 | ||||
-rw-r--r-- | tests/unit/core/test-core-utf8.cpp | 16 |
3 files changed, 98 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp index 80476733e..0bb69701c 100644 --- a/tests/unit/core/test-core-eval.cpp +++ b/tests/unit/core/test-core-eval.cpp @@ -354,6 +354,18 @@ TEST(CoreEval, EvalExpression) /* test reverse of string */ WEE_CHECK_EVAL("!dlrow ,olleH", "${rev:Hello, world!}"); WEE_CHECK_EVAL("界世はちにんこ", "${rev:こんにちは世界}"); + WEE_CHECK_EVAL("!dlrow30F\x19 ,olleH", + "${rev:Hello, ${color:red}world!}"); + WEE_CHECK_EVAL("Hello, \x19" "F03world!", + "${rev:${rev:Hello, ${color:red}world!}}"); + + /* test reverse of string (for screen) */ + WEE_CHECK_EVAL("!dlrow ,olleH", "${revscr:Hello, world!}"); + WEE_CHECK_EVAL("界世はちにんこ", "${revscr:こんにちは世界}"); + WEE_CHECK_EVAL("!dlrow\x19" "F03 ,olleH", + "${revscr:Hello, ${color:red}world!}"); + WEE_CHECK_EVAL("Hello, \x19" "F03world!", + "${revscr:${revscr:Hello, ${color:red}world!}}"); /* test repeat of string */ WEE_CHECK_EVAL("", "${repeat:-1,x}"); diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index a1dda1af2..b43135d53 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -35,6 +35,7 @@ extern "C" #include "src/core/weechat.h" #include "src/core/wee-string.h" #include "src/core/wee-hashtable.h" +#include "src/gui/gui-color.h" #include "src/plugins/plugin.h" } @@ -276,6 +277,8 @@ TEST(CoreString, Cut) TEST(CoreString, Reverse) { + char string[128]; + POINTERS_EQUAL(NULL, string_reverse (NULL)); STRCMP_EQUAL("", string_reverse ("")); @@ -291,6 +294,73 @@ TEST(CoreString, Reverse) * the function string_reverse accepts only an UTF-8 string as input */ STRCMP_EQUAL("\xeblon", string_reverse ("no\xebl")); + + /* reverse of string with color codes */ + snprintf (string, sizeof (string), + "%s", + gui_color_get_custom ("red")); + STRCMP_EQUAL("30F\x19", string_reverse (string)); + + snprintf (string, sizeof (string), + "%s red", + gui_color_get_custom ("red")); + STRCMP_EQUAL("der 30F\x19", string_reverse (string)); + + snprintf (string, sizeof (string), + "red %s", + gui_color_get_custom ("red")); + STRCMP_EQUAL("30F\x19 der", string_reverse (string)); +} + +/* + * Tests functions: + * string_reverse_screen + */ + +TEST(CoreString, ReverseScreen) +{ + char string[128], result[128]; + + POINTERS_EQUAL(NULL, string_reverse_screen (NULL)); + STRCMP_EQUAL("", string_reverse_screen ("")); + + /* reverse of UTF-8 string */ + STRCMP_EQUAL("n", string_reverse_screen ("n")); + STRCMP_EQUAL("on", string_reverse_screen ("no")); + STRCMP_EQUAL("ëon", string_reverse_screen ("noë")); + STRCMP_EQUAL("lëon", string_reverse_screen ("noël")); + STRCMP_EQUAL("界世はちにんこ", string_reverse_screen ("こんにちは世界")); + + /* + * reverse of ISO-8859-15 string: the result may not be what you expect: + * the function string_reverse_screen accepts only an UTF-8 string as input + */ + STRCMP_EQUAL("\xeblon", string_reverse_screen ("no\xebl")); + + /* reverse of string with color codes */ + snprintf (string, sizeof (string), + "%s", + gui_color_get_custom ("red")); + snprintf (result, sizeof (result), + "%s", + gui_color_get_custom ("red")); + STRCMP_EQUAL(result, string_reverse_screen (string)); + + snprintf (string, sizeof (string), + "%s red", + gui_color_get_custom ("red")); + snprintf (result, sizeof (result), + "der %s", + gui_color_get_custom ("red")); + STRCMP_EQUAL(result, string_reverse_screen (string)); + + snprintf (string, sizeof (string), + "red %s", + gui_color_get_custom ("red")); + snprintf (result, sizeof (result), + "%s der", + gui_color_get_custom ("red")); + STRCMP_EQUAL(result, string_reverse_screen (string)); } /* diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp index e993ea202..ad337d505 100644 --- a/tests/unit/core/test-core-utf8.cpp +++ b/tests/unit/core/test-core-utf8.cpp @@ -353,6 +353,14 @@ TEST(CoreUtf8, Size) LONGS_EQUAL(3, utf8_char_size ("€")); LONGS_EQUAL(3, utf8_char_size (cjk_yellow)); LONGS_EQUAL(4, utf8_char_size (han_char)); + /* ë as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(1, utf8_char_size ("\xeb")); + /* ël as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(2, utf8_char_size ("\xebl")); + /* ëlm as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(3, utf8_char_size ("\xeblm")); + /* ëlmn as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(3, utf8_char_size ("\xeblmn")); /* char size on screen */ LONGS_EQUAL(0, utf8_char_size_screen (NULL)); @@ -361,6 +369,14 @@ TEST(CoreUtf8, Size) LONGS_EQUAL(1, utf8_char_size_screen ("ë")); LONGS_EQUAL(1, utf8_char_size_screen ("€")); LONGS_EQUAL(2, utf8_char_size_screen (cjk_yellow)); + /* ë as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(1, utf8_char_size_screen ("\xeb")); + /* ël as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(1, utf8_char_size_screen ("\xebl")); + /* ëlm as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(1, utf8_char_size_screen ("\xeblm")); + /* ëlmn as iso-8859-15: invalid UTF-8 */ + LONGS_EQUAL(1, utf8_char_size_screen ("\xeblmn")); /* length of string (in chars) */ LONGS_EQUAL(0, utf8_strlen (NULL)); |