Commit fc285535 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Initial work on a test suite for our C++ engine.

parent dcb96227
load(qttest_p4)
include(../shared/shared.pri)
QT = core
SOURCES += tst_ast.cpp
#include <QtTest>
#include <QtDebug>
#include <Control.h>
#include <Parser.h>
#include <AST.h>
CPLUSPLUS_USE_NAMESPACE
class tst_AST: public QObject
{
Q_OBJECT
Control control;
public:
TranslationUnit *parse(const QByteArray &source,
TranslationUnit::ParseMode mode)
{
StringLiteral *fileId = control.findOrInsertFileName("<stdin>");
TranslationUnit *unit = new TranslationUnit(&control, fileId);
unit->setSource(source.constData(), source.length());
unit->parse(mode);
return unit;
}
TranslationUnit *parseStatement(const QByteArray &source)
{ return parse(source, TranslationUnit::ParseStatement); }
private slots:
void if_statement();
void if_else_statement();
};
void tst_AST::if_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b;"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
IfStatementAST *stmt = ast->asIfStatement();
QVERIFY(stmt != 0);
QCOMPARE(stmt->if_token, 1U);
QCOMPARE(stmt->lparen_token, 2U);
QVERIFY(stmt->condition != 0);
QCOMPARE(stmt->rparen_token, 4U);
QVERIFY(stmt->statement != 0);
QCOMPARE(stmt->else_token, 0U);
QVERIFY(stmt->else_statement == 0);
}
void tst_AST::if_else_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b; else c;"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
IfStatementAST *stmt = ast->asIfStatement();
QVERIFY(stmt != 0);
QCOMPARE(stmt->if_token, 1U);
QCOMPARE(stmt->lparen_token, 2U);
QVERIFY(stmt->condition != 0);
QCOMPARE(stmt->rparen_token, 4U);
QVERIFY(stmt->statement != 0);
QCOMPARE(stmt->else_token, 7U);
QVERIFY(stmt->else_statement != 0);
}
QTEST_APPLESS_MAIN(tst_AST)
#include "tst_ast.moc"
SUBDIRS = shared ast
CONFIG += ordered
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE
INCLUDEPATH += $$PWD/../../../../shared/cplusplus
LIBS += -L$$PWD -lCPlusPlusTestSupport
TEMPLATE = lib
TARGET = CPlusPlusTestSupport
CONFIG += static
QT = core
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE
include($$PWD/../../../../shared/cplusplus/cplusplus.pri)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment