C++: Fix Macrouse::utf16charsBegin()

This caused displaced highlighting of macro uses after #if constructs.

MacroUse::utf16charBegin() was based on the last "continuation token",
which was wrong.

Change-Id: I89983d82fcf804ba853c04a59a7533c489785d05
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2014-06-02 16:06:26 -04:00
parent c7f0c4a743
commit ff1203de9e
3 changed files with 25 additions and 1 deletions

View File

@@ -180,3 +180,25 @@ void CppToolsPlugin::test_cpppreprocessor_includes_allDiagnostics()
QCOMPARE(document->unresolvedIncludes().size(), 3);
QCOMPARE(document->diagnosticMessages().size(), 3);
}
void CppToolsPlugin::test_cpppreprocessor_macroUses()
{
QByteArray source =
"#define SOMEDEFINE 1\n"
"#if SOMEDEFINE == 1\n"
" int someNumber;\n"
"#endif\n"
;
SourcePreprocessor processor;
Document::Ptr document = processor.run(source);
QVERIFY(document);
const QList<Document::MacroUse> macroUses = document->macroUses();
QCOMPARE(macroUses.size(), 1);
const Document::MacroUse macroUse = macroUses.at(0);
QCOMPARE(macroUse.bytesBegin(), 25U);
QCOMPARE(macroUse.bytesEnd(), 35U);
QCOMPARE(macroUse.utf16charsBegin(), 25U);
QCOMPARE(macroUse.utf16charsEnd(), 35U);
QCOMPARE(macroUse.beginLine(), 2U);
}