summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@trolltech.com>2009-02-10 14:43:19 +0100
committerRoberto Raggi <qtc-committer@nokia.com>2009-02-10 14:44:03 +0100
commit2d80acbe763e1cd1f872e4d49ba653d09bca8c6e (patch)
treefa98b1339f78093ce5bd5d80751252af765650bb /tests
parent885d908ea336de72e7fce2141c1060e425f2af0a (diff)
downloadqt-creator-2d80acbe763e1cd1f872e4d49ba653d09bca8c6e.tar.gz
Improved the implementation of new-expressions.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/cplusplus/ast/tst_ast.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp
index 689da076ea..e4ef03211d 100644
--- a/tests/auto/cplusplus/ast/tst_ast.cpp
+++ b/tests/auto/cplusplus/ast/tst_ast.cpp
@@ -42,6 +42,8 @@ private slots:
// expressions
void simple_name();
void template_id();
+ void new_expression_1();
+ void new_expression_2();
// statements
void if_statement();
@@ -91,6 +93,59 @@ void tst_AST::template_id()
QCOMPARE(ast->asTemplateId()->greater_token, 4U);
}
+void tst_AST::new_expression_1()
+{
+ QSharedPointer<TranslationUnit> unit(parseExpression("\n"
+"new char"
+ ));
+
+ AST *ast = unit->ast();
+ QVERIFY(ast != 0);
+
+ NewExpressionAST *expr = ast->asNewExpression();
+ QVERIFY(expr != 0);
+
+ QCOMPARE(expr->scope_token, 0U);
+ QCOMPARE(expr->new_token, 1U);
+ QVERIFY(expr->new_placement == 0);
+ QCOMPARE(expr->lparen_token, 0U);
+ QVERIFY(expr->type_id == 0);
+ QCOMPARE(expr->rparen_token, 0U);
+ QVERIFY(expr->new_type_id != 0);
+ QVERIFY(expr->new_initializer == 0);
+
+ QVERIFY(expr->new_type_id->type_specifier != 0);
+ QVERIFY(expr->new_type_id->ptr_operators == 0);
+ QVERIFY(expr->new_type_id->new_array_declarators == 0);
+}
+
+void tst_AST::new_expression_2()
+{
+ QSharedPointer<TranslationUnit> unit(parseStatement("\n"
+"::new(__p) _Tp(__val);"
+ ));
+
+ AST *ast = unit->ast();
+ QVERIFY(ast != 0);
+
+ ExpressionStatementAST *stmt = ast->asExpressionStatement();
+ QVERIFY(stmt != 0);
+ QVERIFY(stmt->expression != 0);
+ QVERIFY(stmt->semicolon_token != 0);
+
+ NewExpressionAST *expr = stmt->expression->asNewExpression();
+ QVERIFY(expr != 0);
+
+ QCOMPARE(expr->scope_token, 1U);
+ QCOMPARE(expr->new_token, 2U);
+ QVERIFY(expr->new_placement != 0);
+ QCOMPARE(expr->lparen_token, 0U);
+ QVERIFY(expr->type_id == 0);
+ QCOMPARE(expr->rparen_token, 0U);
+ QVERIFY(expr->new_type_id != 0);
+ QVERIFY(expr->new_initializer != 0);
+}
+
void tst_AST::if_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b;"));