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.
This commit is contained in:
Fabian Homborg 2021-10-19 17:27:35 +02:00
parent 711796ad13
commit 9700a75f38

View File

@ -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;
}
}
}