CppEditor: fix highlighter tests

amends 9091c99429

Change-Id: Iaa64d51aa0dad1d63c88a51bfa55afa2367e65ed
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2023-06-15 13:28:33 +02:00
parent db8842a0d4
commit 5ba10671da
3 changed files with 11 additions and 2 deletions

View File

@@ -621,8 +621,9 @@ void CppHighlighterTest::test()
const QChar c = m_doc.characterAt(pos);
if (c == QChar::ParagraphSeparator)
continue;
const QTextCharFormat expectedFormat = c.isSpace()
? whitespacified(formatForStyle) : formatForStyle;
const QTextCharFormat expectedFormat = asSyntaxHighlight(
c.isSpace() ? whitespacified(formatForStyle) : formatForStyle);
const QTextCharFormat actualFormat = getActualFormat(pos);
if (actualFormat != expectedFormat) {
int posLine;

View File

@@ -869,6 +869,13 @@ QTextCharFormat SyntaxHighlighter::whitespacified(const QTextCharFormat &fmt)
return format;
}
QTextCharFormat SyntaxHighlighter::asSyntaxHighlight(const QTextCharFormat &fmt)
{
QTextCharFormat format = fmt;
format.setProperty(SyntaxHighlight, true);
return format;
}
void SyntaxHighlighter::highlightBlock(const QString &text)
{
formatSpaces(text);

View File

@@ -62,6 +62,7 @@ protected:
void setTextFormatCategories(int count, std::function<TextStyle(int)> formatMapping);
QTextCharFormat formatForCategory(int categoryIndex) const;
QTextCharFormat whitespacified(const QTextCharFormat &fmt);
QTextCharFormat asSyntaxHighlight(const QTextCharFormat &fmt);
// implement in subclasses
// default implementation highlights whitespace