Commit 7f83755f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Test the `for' statement.

parent b043d1d0
......@@ -33,6 +33,7 @@ private slots:
void if_else_statement();
void while_statement();
void while_condition_statement();
void for_statement();
void cpp_initializer_or_function_declaration();
};
......@@ -170,6 +171,30 @@ void tst_AST::while_condition_statement()
QCOMPARE(body_stmt->rbrace_token, 9U);
}
void tst_AST::for_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("for (;;) {}"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
ForStatementAST *stmt = ast->asForStatement();
QVERIFY(stmt != 0);
QCOMPARE(stmt->for_token, 1U);
QCOMPARE(stmt->lparen_token, 2U);
QVERIFY(stmt->initializer != 0);
QVERIFY(stmt->initializer->asExpressionStatement() != 0);
QCOMPARE(stmt->initializer->asExpressionStatement()->semicolon_token, 3U);
QVERIFY(stmt->condition == 0);
QCOMPARE(stmt->semicolon_token, 4U);
QVERIFY(stmt->expression == 0);
QCOMPARE(stmt->rparen_token, 5U);
QVERIFY(stmt->statement != 0);
QVERIFY(stmt->statement->asCompoundStatement() != 0);
QCOMPARE(stmt->statement->asCompoundStatement()->lbrace_token, 6U);
QVERIFY(stmt->statement->asCompoundStatement()->statements == 0);
QCOMPARE(stmt->statement->asCompoundStatement()->rbrace_token, 7U);
}
void tst_AST::cpp_initializer_or_function_declaration()
{
QSharedPointer<TranslationUnit> unit(parseStatement("QFileInfo fileInfo(foo);"));
......
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