diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-04-04 14:44:18 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-04-04 14:44:18 +0200 |
commit | 3bf585ba04e7ff4a95f739e58503da7af3714bc7 (patch) | |
tree | 4491e9835a428d94bcb643e519f7e4ce0f47fc7c /tests/unit/core | |
parent | 1aefb0a54606071e6aeca89f0cfbfc55a2f356dc (diff) | |
download | weechat-3bf585ba04e7ff4a95f739e58503da7af3714bc7.zip |
core: evaluate left/right part of comparison after split on the comparison operator in ${if:xxx} (closes #1627)
To force evaluation of the expression before doing the comparison (less safe),
the "${eval_cond:xxx}" can be used.
With the old behavior we had:
>> ${if:a==b}
== [0]
>> ${if:${raw:a==b}}
== [0]
>> ${if:${eval_cond:${raw:a==b}}}
== [0]
And with the new behavior, we have:
>> ${if:a==b}
== [0]
>> ${if:${raw:a==b}}
== [1]
>> ${if:${eval_cond:${raw:a==b}}}
== [0]
Diffstat (limited to 'tests/unit/core')
-rw-r--r-- | tests/unit/core/test-core-eval.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp index de86cdd65..eca88db81 100644 --- a/tests/unit/core/test-core-eval.cpp +++ b/tests/unit/core/test-core-eval.cpp @@ -86,6 +86,9 @@ TEST(CoreEval, EvalCondition) NULL, NULL); CHECK(extra_vars); hashtable_set (extra_vars, "test", "value"); + hashtable_set (extra_vars, "var_abc", "abc"); + hashtable_set (extra_vars, "var_cond_true", "a==a"); + hashtable_set (extra_vars, "var_cond_false", "a==b"); options = hashtable_new (32, WEECHAT_HASHTABLE_STRING, @@ -175,6 +178,8 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("0", "${if:${buffer.number}==2?yes:no} == yes"); WEE_CHECK_EVAL("0", "yes == ${if:${buffer.number}==2?yes:no}"); WEE_CHECK_EVAL("0", "${if:\\$==A?yes:}"); + WEE_CHECK_EVAL("0", "${var_does_not_exist}"); + WEE_CHECK_EVAL("0", "${var_abc} == def"); /* conditions evaluated as true */ WEE_CHECK_EVAL("1", "1"); @@ -262,6 +267,14 @@ TEST(CoreEval, EvalCondition) WEE_CHECK_EVAL("1", "${if:${buffer.number}==1?yes:no} == yes"); WEE_CHECK_EVAL("1", "yes == ${if:${buffer.number}==1?yes:no}"); WEE_CHECK_EVAL("1", "${if:\\$==\\$?yes:}"); + WEE_CHECK_EVAL("1", "${var_abc}"); + WEE_CHECK_EVAL("1", "${var_abc} == abc"); + WEE_CHECK_EVAL("1", "${var_cond_true}"); + WEE_CHECK_EVAL("0", "${var_cond_true} == zzz"); + WEE_CHECK_EVAL("1", "${var_cond_true} != zzz"); + WEE_CHECK_EVAL("1", "${var_cond_false}"); + WEE_CHECK_EVAL("0", "${var_cond_false} == zzz"); + WEE_CHECK_EVAL("1", "${var_cond_false} != zzz"); /* evaluation of extra_vars */ hashtable_set (options, "extra", "eval"); @@ -455,6 +468,9 @@ TEST(CoreEval, EvalExpression) NULL, NULL); CHECK(extra_vars); hashtable_set (extra_vars, "test", "value"); + hashtable_set (extra_vars, "var_abc", "abc"); + hashtable_set (extra_vars, "var_cond_true", "a==a"); + hashtable_set (extra_vars, "var_cond_false", "a==b"); options = hashtable_new (32, WEECHAT_HASHTABLE_STRING, @@ -486,6 +502,12 @@ TEST(CoreEval, EvalExpression) WEE_CHECK_EVAL("0", "${eval_cond:}"); WEE_CHECK_EVAL("0", "${eval_cond:${buffer.number} == 2}"); WEE_CHECK_EVAL("1", "${eval_cond:${buffer.number} == 1}"); + WEE_CHECK_EVAL("1", "${eval_cond:${var_abc}}"); + WEE_CHECK_EVAL("1", "${eval_cond:${var_abc} == abc}"); + WEE_CHECK_EVAL("0", "${eval_cond:${var_abc} == def}"); + WEE_CHECK_EVAL("1", "${eval_cond:${var_cond_true}}"); + WEE_CHECK_EVAL("1", "${eval_cond:${var_cond_true}}"); + WEE_CHECK_EVAL("0", "${eval_cond:${var_cond_false}}"); /* test value from extra_vars */ WEE_CHECK_EVAL("value", "${test}"); @@ -702,13 +724,24 @@ TEST(CoreEval, EvalExpression) 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}}"); + WEE_CHECK_EVAL("0", "${if:}"); WEE_CHECK_EVAL("0", "${if:0}"); WEE_CHECK_EVAL("1", "${if:1}"); + WEE_CHECK_EVAL("1", "${if:abc}"); WEE_CHECK_EVAL("0", "${if:abc!=abc}"); WEE_CHECK_EVAL("1", "${if:abc==abc}"); WEE_CHECK_EVAL("1", "${if:${if:abc==abc}}"); WEE_CHECK_EVAL("0", "${if:${rev:${if:42==42?hello:bye}}==eyb}"); WEE_CHECK_EVAL("1", "${if:${rev:${if:42==42?hello:bye}}==olleh}"); + WEE_CHECK_EVAL("1", "${if:${var_abc}}"); + WEE_CHECK_EVAL("1", "${if:${var_abc} == abc}"); + WEE_CHECK_EVAL("0", "${if:${var_abc} == def}"); + WEE_CHECK_EVAL("1", "${if:${var_cond_true}}"); + WEE_CHECK_EVAL("0", "${if:${var_cond_true} == zzz}"); + WEE_CHECK_EVAL("1", "${if:${var_cond_true} != zzz}"); + WEE_CHECK_EVAL("1", "${if:${var_cond_false}}"); + WEE_CHECK_EVAL("0", "${if:${var_cond_false} == zzz}"); + WEE_CHECK_EVAL("1", "${if:${var_cond_false} != zzz}"); /* test calc */ WEE_CHECK_EVAL("0", "${calc:}"); |