summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-08-03 19:46:41 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-08-03 19:46:41 +0200
commitd89c4f559c817a92da94d98baf9f3829238b0392 (patch)
tree552415606ad46f35bf20cb5d6d376b78b9c480f6 /tests/unit/core
parent0be4020b68e54cbb6fd588175419843b7873f900 (diff)
downloadweechat-d89c4f559c817a92da94d98baf9f3829238b0392.zip
api: add random integer number in evaluation of expressions with "random:min,max"
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-eval.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp
index 4cdd5f477..f542641da 100644
--- a/tests/unit/core/test-core-eval.cpp
+++ b/tests/unit/core/test-core-eval.cpp
@@ -453,7 +453,7 @@ TEST(CoreEval, EvalExpression)
{
struct t_hashtable *pointers, *extra_vars, *options;
struct t_config_option *ptr_option;
- char *value, str_value[256];
+ char *value, str_value[256], str_expr[256];
const char *ptr_debug_output;
pointers = hashtable_new (32,
@@ -751,6 +751,25 @@ TEST(CoreEval, EvalExpression)
WEE_CHECK_EVAL("18", "${calc:(5+1)*3}");
WEE_CHECK_EVAL("123129", "${calc:${repeat:2,123}+2*3}");
+ /* test random */
+ WEE_CHECK_EVAL("0", "${random:}");
+ WEE_CHECK_EVAL("0", "${random:1}");
+ WEE_CHECK_EVAL("0", "${random:1,}");
+ WEE_CHECK_EVAL("0", "${random:5,1}");
+ WEE_CHECK_EVAL("2", "${random:2,2}");
+ snprintf (str_expr, sizeof (str_expr),
+ "${random:-1,%ld}",
+ (long)RAND_MAX);
+ WEE_CHECK_EVAL("0", str_expr);
+ snprintf (str_expr, sizeof (str_expr),
+ "${random:%ld,%ld}",
+ (long)RAND_MAX,
+ (long)RAND_MAX);
+ snprintf (str_value, sizeof (str_value),
+ "%ld",
+ (long)RAND_MAX);
+ WEE_CHECK_EVAL(str_value, str_expr);
+
/* test translation */
WEE_CHECK_EVAL("", "${translate:}");
WEE_CHECK_EVAL("abcdef", "${translate:abcdef}");