forked from qt-creator/qt-creator
Added test for lambda function definitions.
Change-Id: I2233aa98a07e9c23463d4bec0b09dcccb89deb58 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
@@ -52,6 +52,9 @@
|
|||||||
#include <Names.h>
|
#include <Names.h>
|
||||||
|
|
||||||
//TESTED_COMPONENT=src/libs/cplusplus
|
//TESTED_COMPONENT=src/libs/cplusplus
|
||||||
|
|
||||||
|
#define NO_PARSER_OR_SEMANTIC_ERROR_MESSAGES
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
class tst_Semantic: public QObject
|
class tst_Semantic: public QObject
|
||||||
@@ -68,13 +71,15 @@ public:
|
|||||||
TranslationUnit *parse(const QByteArray &source,
|
TranslationUnit *parse(const QByteArray &source,
|
||||||
TranslationUnit::ParseMode mode,
|
TranslationUnit::ParseMode mode,
|
||||||
bool enableObjc,
|
bool enableObjc,
|
||||||
bool qtMocRun)
|
bool qtMocRun,
|
||||||
|
bool enableCxx11)
|
||||||
{
|
{
|
||||||
const StringLiteral *fileId = control->stringLiteral("<stdin>");
|
const StringLiteral *fileId = control->stringLiteral("<stdin>");
|
||||||
TranslationUnit *unit = new TranslationUnit(control.data(), fileId);
|
TranslationUnit *unit = new TranslationUnit(control.data(), fileId);
|
||||||
unit->setSource(source.constData(), source.length());
|
unit->setSource(source.constData(), source.length());
|
||||||
unit->setObjCEnabled(enableObjc);
|
unit->setObjCEnabled(enableObjc);
|
||||||
unit->setQtMocRunEnabled(qtMocRun);
|
unit->setQtMocRunEnabled(qtMocRun);
|
||||||
|
unit->setCxxOxEnabled(enableCxx11);
|
||||||
unit->parse(mode);
|
unit->parse(mode);
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
@@ -84,7 +89,9 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Document(TranslationUnit *unit)
|
Document(TranslationUnit *unit)
|
||||||
: unit(unit), globals(unit->control()->newNamespace(0, 0)), errorCount(0)
|
: unit(unit)
|
||||||
|
, globals(unit->control()->newNamespace(0, 0))
|
||||||
|
, errorCount(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~Document()
|
~Document()
|
||||||
@@ -114,23 +121,31 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void report(int /*level*/,
|
virtual void report(int /*level*/,
|
||||||
const StringLiteral * /*fileName*/,
|
const StringLiteral *fileName,
|
||||||
unsigned /*line*/, unsigned /*column*/,
|
unsigned line, unsigned column,
|
||||||
const char * /*format*/, va_list /*ap*/)
|
const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
++errorCount;
|
++errorCount;
|
||||||
|
|
||||||
// qDebug() << fileName->chars()<<':'<<line<<':'<<column<<' '<<QString().vsprintf(format, ap);
|
#ifndef NO_PARSER_OR_SEMANTIC_ERROR_MESSAGES
|
||||||
|
qDebug() << fileName->chars()<<':'<<line<<':'<<column<<' '<<QString().vsprintf(format, ap);
|
||||||
|
#else
|
||||||
|
Q_UNUSED(fileName);
|
||||||
|
Q_UNUSED(line);
|
||||||
|
Q_UNUSED(column);
|
||||||
|
Q_UNUSED(format);
|
||||||
|
Q_UNUSED(ap);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Diagnostic diag;
|
Diagnostic diag;
|
||||||
|
|
||||||
|
|
||||||
QSharedPointer<Document> document(const QByteArray &source, bool enableObjc = false, bool qtMocRun = false)
|
QSharedPointer<Document> document(const QByteArray &source, bool enableObjc = false, bool qtMocRun = false, bool enableCxx11 = false)
|
||||||
{
|
{
|
||||||
diag.errorCount = 0; // reset the error count.
|
diag.errorCount = 0; // reset the error count.
|
||||||
TranslationUnit *unit = parse(source, TranslationUnit::ParseTranlationUnit, enableObjc, qtMocRun);
|
TranslationUnit *unit = parse(source, TranslationUnit::ParseTranlationUnit, enableObjc, qtMocRun, enableCxx11);
|
||||||
QSharedPointer<Document> doc(new Document(unit));
|
QSharedPointer<Document> doc(new Document(unit));
|
||||||
doc->check();
|
doc->check();
|
||||||
doc->errorCount = diag.errorCount;
|
doc->errorCount = diag.errorCount;
|
||||||
@@ -164,6 +179,8 @@ private slots:
|
|||||||
|
|
||||||
void q_enum_1();
|
void q_enum_1();
|
||||||
|
|
||||||
|
void lambda_1();
|
||||||
|
|
||||||
void diagnostic_error();
|
void diagnostic_error();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -697,6 +714,17 @@ void tst_Semantic::q_enum_1()
|
|||||||
QCOMPARE(e->name->identifier()->chars(), "e");
|
QCOMPARE(e->name->identifier()->chars(), "e");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_Semantic::lambda_1()
|
||||||
|
{
|
||||||
|
QSharedPointer<Document> doc = document("\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" auto func = [](int a, int b) {return a + b;};\n"
|
||||||
|
"}\n", false, false, true);
|
||||||
|
|
||||||
|
QCOMPARE(doc->errorCount, 0U);
|
||||||
|
QCOMPARE(doc->globals->memberCount(), 1U);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_Semantic::diagnostic_error()
|
void tst_Semantic::diagnostic_error()
|
||||||
{
|
{
|
||||||
QSharedPointer<Document> doc = document("\n"
|
QSharedPointer<Document> doc = document("\n"
|
||||||
|
Reference in New Issue
Block a user