C++: Document::functionAt provides line information

Needed for the debugger.

Change-Id: I6465f6dc53017df212e403ea8a9a1c7977ac1671
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Nikolai Kosjar
2014-11-11 12:52:46 +01:00
parent fd3f544bb2
commit 69504c25ca
3 changed files with 49 additions and 14 deletions

View File

@@ -163,6 +163,8 @@ void tst_Lookup::document_functionAt_data()
QTest::addColumn<int>("line");
QTest::addColumn<int>("column");
QTest::addColumn<QString>("expectedFunction");
QTest::addColumn<int>("expectedOpeningDeclaratorParenthesisLine");
QTest::addColumn<int>("expectedClosingBraceLine");
QByteArray source = "\n"
"void Foo::Bar() {\n" // line 1
@@ -172,12 +174,12 @@ void tst_Lookup::document_functionAt_data()
" }\n" // line 5
"}\n";
QString expectedFunction = QString::fromLatin1("Foo::Bar");
QTest::newRow("nonInline1") << source << 1 << 2 << QString();
QTest::newRow("nonInline2") << source << 1 << 11 << expectedFunction;
QTest::newRow("nonInline3") << source << 2 << 2 << expectedFunction;
QTest::newRow("nonInline4") << source << 3 << 10 << expectedFunction;
QTest::newRow("nonInline5") << source << 4 << 3 << expectedFunction;
QTest::newRow("nonInline6") << source << 6 << 1 << expectedFunction;
QTest::newRow("nonInline1") << source << 1 << 2 << QString() << -1 << -1;
QTest::newRow("nonInline2") << source << 1 << 11 << expectedFunction << 1 << 6;
QTest::newRow("nonInline3") << source << 2 << 2 << expectedFunction << 1 << 6;
QTest::newRow("nonInline4") << source << 3 << 10 << expectedFunction << 1 << 6;
QTest::newRow("nonInline5") << source << 4 << 3 << expectedFunction << 1 << 6;
QTest::newRow("nonInline6") << source << 6 << 1 << expectedFunction << 1 << 6;
source = "\n"
"namespace N {\n" // line 1
@@ -188,9 +190,16 @@ void tst_Lookup::document_functionAt_data()
"};\n"
"}\n"; // line 7
expectedFunction = QString::fromLatin1("N::C::f");
QTest::newRow("inline1") << source << 1 << 2 << QString();
QTest::newRow("inline2") << source << 2 << 10 << QString();
QTest::newRow("inline2") << source << 3 << 10 << expectedFunction;
QTest::newRow("inline1") << source << 1 << 2 << QString() << -1 << -1;
QTest::newRow("inline2") << source << 2 << 10 << QString() << -1 << -1;
QTest::newRow("inline2") << source << 3 << 10 << expectedFunction << 3 << 5;
source = "\n"
"void f(Helper helper = [](){})\n" // line 1
"{\n"
"}\n"; // line 3
expectedFunction = QString::fromLatin1("f");
QTest::newRow("inlineWithLambdaArg1") << source << 2 << 1 << expectedFunction << 1 << 3;
}
void tst_Lookup::document_functionAt()
@@ -199,14 +208,23 @@ void tst_Lookup::document_functionAt()
QFETCH(int, line);
QFETCH(int, column);
QFETCH(QString, expectedFunction);
QFETCH(int, expectedOpeningDeclaratorParenthesisLine);
QFETCH(int, expectedClosingBraceLine);
Document::Ptr doc = Document::create("document_functionAt");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->functionAt(line, column), expectedFunction);
int actualOpeningDeclaratorParenthesisLine = -1;
int actualClosingBraceLine = -1;
const QString actualFunction = doc->functionAt(line, column,
&actualOpeningDeclaratorParenthesisLine,
&actualClosingBraceLine);
QCOMPARE(actualFunction, expectedFunction);
QCOMPARE(actualOpeningDeclaratorParenthesisLine, expectedOpeningDeclaratorParenthesisLine);
QCOMPARE(actualClosingBraceLine, expectedClosingBraceLine);
}
void tst_Lookup::simple_class_1()