From 9700a75f382509d66c1483ddf1a8cdf7de83870f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 19 Oct 2021 17:27:35 +0200 Subject: [PATCH] fish_tests: Make a fancy caret for highlighting errors Now looks like ``` Error: Wrong color in test at index 8-11 in text (expected 0x6, actual 0x2): command echo abc foo & ^^^^ ``` instead of repeating the error for every character that is wrong. --- src/fish_tests.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 0de04338b..35ce00f1b 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -5548,10 +5548,18 @@ static void test_highlighting() { if (text.at(i) == L' ') continue; if (expected_colors.at(i) != colors.at(i)) { + // Make a fancy caret under the token + auto e_col = expected_colors.at(i); + auto a_col = colors.at(i); + auto j = i + 1; + while (j < colors.size() && expected_colors.at(j) == e_col && colors.at(j) == a_col) j++; + if (j == colors.size() - 1) j++; const wcstring spaces(i, L' '); - err(L"Wrong color in test at index %lu in text (expected %#x, actual " - L"%#x):\n%ls\n%ls^", - i, expected_colors.at(i), colors.at(i), text.c_str(), spaces.c_str()); + const wcstring carets(j - i, L'^'); + err(L"Wrong color in test at index %lu-%lu in text (expected %#x, actual " + L"%#x):\n%ls\n%ls%ls", + i, j - 1, expected_colors.at(i), colors.at(i), text.c_str(), spaces.c_str(), carets.c_str()); + i = j; } } }