Skip to content

Commit

Permalink
add test for multiline highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Apr 15, 2024
1 parent 80275f7 commit e8f04fc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/modeltests/tst_formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#include "../testutils.h"

#if KFSyntaxHighlighting_FOUND
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
#endif

Q_DECLARE_METATYPE(QVector<QTextLayout::FormatRange>)

class TestFormatting : public QObject
Expand Down Expand Up @@ -83,6 +88,47 @@ private slots:
}
}
}

void testMultilineHighlighting()
{
#if KFSyntaxHighlighting_FOUND
const auto testfunc =
QStringList({QStringLiteral("int test() {"), QStringLiteral("/* A"), QStringLiteral(" * very"),
QStringLiteral(" * long"), QStringLiteral(" * comment */"), QStringLiteral("return 0;"),
QStringLiteral("}")});

auto repository = std::make_unique<KSyntaxHighlighting::Repository>();

HighlightedText text(repository.get());
text.setText(testfunc);
text.setDefinition(repository->definitionForFileName(QStringLiteral("test.cpp")));

// get formatting for line 2 (first commented line)
const auto formats = text.layoutForLine(1)->formats();
Q_ASSERT(!formats.empty());
const auto commentFormat = formats[0].format;

// ensure all other lines have the same format
for (int line = 2; line < 5; line++) {
const auto formats = text.layoutForLine(line)->formats();

for (const auto& format : formats) {
QCOMPARE(format.format, commentFormat);
}
}

{
// ensure that the last line (return 0;) is not formatted in the comment style
const auto formats = text.layoutForLine(5)->formats();

for (const auto& format : formats) {
QVERIFY(format.format != commentFormat);
}
}
#else
QSKIP("Test requires KSyntaxHighlighting");
#endif // KFSyntaxHighlighting_FOUND
}
};

HOTSPOT_GUITEST_MAIN(TestFormatting)
Expand Down

0 comments on commit e8f04fc

Please sign in to comment.