Exemplo n.º 1
0
void tst_Lookup::document_functionAt_1()
{
    const QByteArray source = "\n"
            "void Foo::Bar() {\n" // line 1
            "    \n" // line 2
            "    for (int i=0; i < 10; ++i) {\n"
            "        \n" // line 4
            "    }\n"
            "}\n"; // line 7

    Document::Ptr doc = Document::create("document_functionAt_1");
    doc->setUtf8Source(source);
    doc->parse();
    doc->check();

    QVERIFY(doc->diagnosticMessages().isEmpty());
    QCOMPARE(doc->functionAt(1,  2), QString());
    QCOMPARE(doc->functionAt(1, 11), QString(QLatin1String("Foo::Bar")));
    QCOMPARE(doc->functionAt(2,  2), QString(QLatin1String("Foo::Bar")));
    QCOMPARE(doc->functionAt(3, 10), QString(QLatin1String("Foo::Bar")));
    QCOMPARE(doc->functionAt(4, 3), QString(QLatin1String("Foo::Bar")));
    QCOMPARE(doc->functionAt(6, 1), QString(QLatin1String("Foo::Bar")));
}
Exemplo n.º 2
0
void tst_Lookup::document_functionAt()
{
    QFETCH(QByteArray, source);
    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());

    int actualOpeningDeclaratorParenthesisLine = -1;
    int actualClosingBraceLine = -1;
    const QString actualFunction = doc->functionAt(line, column,
                                                   &actualOpeningDeclaratorParenthesisLine,
                                                   &actualClosingBraceLine);
    QCOMPARE(actualFunction, expectedFunction);
    QCOMPARE(actualOpeningDeclaratorParenthesisLine, expectedOpeningDeclaratorParenthesisLine);
    QCOMPARE(actualClosingBraceLine, expectedClosingBraceLine);
}