diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-04 19:41:23 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-25 14:18:19 +0100 |
commit | 83117f8d2a823b229b96a93d3591704a045eb502 (patch) | |
tree | ea00f29e5fdb3b1f2eb5e17792127d69821ddb3e /tests/unit | |
parent | 07d16903f3c4f8be84e777a2067085f305e8d2f0 (diff) | |
download | weechat-83117f8d2a823b229b96a93d3591704a045eb502.zip |
core: add ternary operator (condition) in evaluation of expressions
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/core/test-eval.cpp | 11 | ||||
-rw-r--r-- | tests/unit/core/test-string.cpp | 65 |
2 files changed, 49 insertions, 27 deletions
diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp index b5bde750e..e2ecd401a 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-eval.cpp @@ -248,6 +248,17 @@ TEST(Eval, EvalExpression) LONGS_EQUAL(8, strlen (value)); free (value); + /* test ternary operator */ + WEE_CHECK_EVAL("1", "${if:5>2}"); + WEE_CHECK_EVAL("0", "${if:1>7}"); + WEE_CHECK_EVAL("yes", "${if:5>2?yes:no}"); + WEE_CHECK_EVAL("no", "${if:1>7?yes:no}"); + WEE_CHECK_EVAL("yes", "${if:5>2 && 6>3?yes:no}"); + WEE_CHECK_EVAL("yes-yes", "${if:5>2?${if:6>3?yes-yes:yes-no}:${if:9>4?no-yes:no-no}}"); + WEE_CHECK_EVAL("yes-no", "${if:5>2?${if:1>7?yes-yes:yes-no}:${if:9>4?no-yes:no-no}}"); + WEE_CHECK_EVAL("no-yes", "${if:1>7?${if:6>3?yes-yes:yes-no}:${if:9>4?no-yes:no-no}}"); + WEE_CHECK_EVAL("no-no", "${if:1>7?${if:1>7?yes-yes:yes-no}:${if:1>7?no-yes:no-no}}"); + /* test option */ snprintf (str_value, sizeof (str_value), "%d", CONFIG_INTEGER(config_look_scroll_amount)); diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp index 4a9cab548..2a937b6a0 100644 --- a/tests/unit/core/test-string.cpp +++ b/tests/unit/core/test-string.cpp @@ -80,11 +80,12 @@ extern "C" #define WEE_REPLACE_CB(__result_replace, __result_errors, \ __str, __prefix, __suffix, \ + __list_prefix_no_replace, \ __callback, __callback_data, __errors) \ errors = -1; \ result = string_replace_with_callback ( \ - __str, __prefix, __suffix, __callback, __callback_data, \ - __errors); \ + __str, __prefix, __suffix, __list_prefix_no_replace, \ + __callback, __callback_data, __errors); \ if (__result_replace == NULL) \ { \ POINTERS_EQUAL(NULL, result); \ @@ -676,6 +677,9 @@ test_replace_cb (void *data, const char *text) if (strcmp (text, "xxx") == 0) return strdup (""); + if (strncmp (text, "no_replace:", 11) == 0) + return strdup (text); + return NULL; } @@ -734,48 +738,55 @@ TEST(String, ReplaceRegex) TEST(String, ReplaceWithCallback) { char *result; + const char *list_prefix_no_replace[] = { "no_replace:", NULL }; int errors; /* tests with invalid arguments */ - WEE_REPLACE_CB(NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, "", NULL, NULL, NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, NULL, "", NULL, NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, NULL, NULL, "", NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, NULL, NULL, NULL, &test_replace_cb, NULL, NULL); - WEE_REPLACE_CB(NULL, 0, NULL, NULL, NULL, NULL, NULL, &errors); - WEE_REPLACE_CB(NULL, -1, "test", NULL, NULL, NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, "test", "${", NULL, NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, "test", NULL, "}", NULL, NULL, NULL); - WEE_REPLACE_CB(NULL, -1, "test", NULL, NULL, &test_replace_cb, NULL, NULL); - WEE_REPLACE_CB(NULL, 0, "test", NULL, NULL, NULL, NULL, &errors); - WEE_REPLACE_CB(NULL, -1, "test", "${", "}", NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, "", NULL, NULL, NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, NULL, "", NULL, NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, NULL, NULL, "", NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, NULL, NULL, NULL, NULL, &test_replace_cb, NULL, NULL); + WEE_REPLACE_CB(NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, &errors); + WEE_REPLACE_CB(NULL, -1, "test", NULL, NULL, NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, "test", "${", NULL, NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, "test", NULL, "}", NULL, NULL, NULL, NULL); + WEE_REPLACE_CB(NULL, -1, "test", NULL, NULL, NULL, &test_replace_cb, NULL, NULL); + WEE_REPLACE_CB(NULL, 0, "test", NULL, NULL, NULL, NULL, NULL, &errors); + WEE_REPLACE_CB(NULL, -1, "test", "${", "}", NULL, NULL, NULL, NULL); /* valid arguments */ - WEE_REPLACE_CB("test", -1, "test", "${", "}", + WEE_REPLACE_CB("test", -1, "test", "${", "}", NULL, &test_replace_cb, NULL, NULL); - WEE_REPLACE_CB("test", 0, "test", "${", "}", + WEE_REPLACE_CB("test", 0, "test", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test def", 0, "test ${abc}", "${", "}", + WEE_REPLACE_CB("test def", 0, "test ${abc}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test ", 0, "test ${xxx}", "${", "}", + WEE_REPLACE_CB("test ", 0, "test ${xxx}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test ${aaa}", 1, "test ${aaa}", "${", "}", + WEE_REPLACE_CB("test ${aaa}", 1, "test ${aaa}", "${", "}", NULL, &test_replace_cb, NULL, &errors); WEE_REPLACE_CB("test def ${aaa}", 1, "test ${abc} ${xxx} ${aaa}", - "${", "}", &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test ", 1, "test ${abc", "${", "}", + "${", "}", NULL, &test_replace_cb, NULL, &errors); + WEE_REPLACE_CB("test ", 1, "test ${abc", "${", "}", NULL, + &test_replace_cb, NULL, &errors); + WEE_REPLACE_CB("test abc}", 0, "test abc}", "${", "}", NULL, + &test_replace_cb, NULL, &errors); + WEE_REPLACE_CB("test ${}", 1, "test ${}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test abc}", 0, "test abc}", "${", "}", + WEE_REPLACE_CB("test ${ }", 1, "test ${ }", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test ${}", 1, "test ${}", "${", "}", + WEE_REPLACE_CB("def", 0, "${abc}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("test ${ }", 1, "test ${ }", "${", "}", + WEE_REPLACE_CB("", 0, "${xxx}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("def", 0, "${abc}", "${", "}", + WEE_REPLACE_CB("${aaa}", 1, "${aaa}", "${", "}", NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("", 0, "${xxx}", "${", "}", + WEE_REPLACE_CB("no_replace:def", 0, "${no_replace:${abc}}", "${", "}", + NULL, &test_replace_cb, NULL, &errors); - WEE_REPLACE_CB("${aaa}", 1, "${aaa}", "${", "}", + WEE_REPLACE_CB("no_replace:${abc}", 0, "${no_replace:${abc}}", "${", "}", + list_prefix_no_replace, &test_replace_cb, NULL, &errors); } |