From 87f74e9f9544a7e3b7e4ffd0acc40841b8eb79e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 23 Nov 2023 08:18:22 +0100 Subject: core: add syntax highlighting in evaluation of expressions, add option weechat.color.eval_syntax_colors (issue #2042) Syntax highlighting (raw string without evaluation): `${raw_hl:xxx}` Syntax highlighting: `${hl:xxx}` --- tests/unit/core/test-core-eval.cpp | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'tests/unit/core') diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp index 5c758e8ed..4c0163511 100644 --- a/tests/unit/core/test-core-eval.cpp +++ b/tests/unit/core/test-core-eval.cpp @@ -489,12 +489,87 @@ TEST(CoreEval, EvalExpression) WEE_CHECK_EVAL("", "${}"); WEE_CHECK_EVAL("", "${xyz}"); + /* test raw string with syntax highlighting */ + WEE_CHECK_EVAL("", "${raw_hl:}"); + WEE_CHECK_EVAL("test", "${raw_hl:test}"); + snprintf (str_value, sizeof (str_value), + "%s${info:version}%s", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "${raw_hl:${info:version}}"); + snprintf (str_value, sizeof (str_value), + "test_%s${info:version}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "test_${raw_hl:${info:version}}_end"); + snprintf (str_value, sizeof (str_value), + "test_%s${cut:3,,%s${rev:%s${info:version}%s}%s}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom (config_eval_syntax_colors[1]), + gui_color_get_custom (config_eval_syntax_colors[2]), + gui_color_get_custom (config_eval_syntax_colors[1]), + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "test_${raw_hl:${cut:3,,${rev:${info:version}}}}_end"); + snprintf (str_value, sizeof (str_value), + "test_%s${raw:${test}}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "test_${raw_hl:${raw:${test}}}_end"); + snprintf (str_value, sizeof (str_value), + "test_%s${if:a==1?%s${yes}%s:%s${no}%s}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom (config_eval_syntax_colors[1]), + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom (config_eval_syntax_colors[1]), + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "test_${raw_hl:${if:a==1?${yes}:${no}}}_end"); + snprintf (str_value, sizeof (str_value), + "test_%s${a:%s${b:%s${c:%s${d:%s${e:%s${f:%s${g:%s${h:%s${i:}%s}%s}%s}%s}%s}%s}%s}%s}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[1 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[2 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[3 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[4 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[5 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[6 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[7 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[8 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[7 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[6 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[5 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[4 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[3 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[2 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[1 % config_num_eval_syntax_colors]), + gui_color_get_custom (config_eval_syntax_colors[0 % config_num_eval_syntax_colors]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, + "test_${raw_hl:${a:${b:${c:${d:${e:${f:${g:${h:${i:}}}}}}}}}}_end"); + /* test raw string */ + WEE_CHECK_EVAL("", "${raw:}"); + WEE_CHECK_EVAL("test", "${raw:test}"); WEE_CHECK_EVAL("${info:version}", "${raw:${info:version}}"); WEE_CHECK_EVAL("yes", "${if:${raw:test?}==${raw:test?}?yes:no}"); WEE_CHECK_EVAL("no", "${if:${raw:test?}==${raw:test}?yes:no}"); WEE_CHECK_EVAL("16", "${length:${raw:${buffer.number}}}"); + /* test string with syntax highlighting */ + WEE_CHECK_EVAL("", "${hl:}"); + WEE_CHECK_EVAL("test", "${hl:test}"); + snprintf (str_value, sizeof (str_value), + "%s${info:version}%s", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL("test_weechat_end", "test_${hl:${buffer.name}}_end"); + snprintf (str_value, sizeof (str_value), + "test_%s${buffer.name}%s_end", + gui_color_get_custom (config_eval_syntax_colors[0]), + gui_color_get_custom ("reset")); + WEE_CHECK_EVAL(str_value, "test_${hl:${raw:${buffer.name}}}_end"); + /* test eval of substring */ WEE_CHECK_EVAL("\t", "${eval:${\\t}}"); -- cgit v1.2.3