Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
f5976d2b
Commit
f5976d2b
authored
Dec 15, 2008
by
Roberto Raggi
Browse files
Testing `while' statement.
parent
893dd21a
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/auto/cplusplus/ast/tst_ast.cpp
View file @
f5976d2b
...
...
@@ -31,6 +31,8 @@ public:
private
slots
:
void
if_statement
();
void
if_else_statement
();
void
while_statement
();
void
while_condition_statement
();
void
cpp_initializer_or_function_declaration
();
};
...
...
@@ -100,6 +102,66 @@ void tst_AST::if_else_statement()
QCOMPARE
(
b_id_expr
->
identifier_token
,
8U
);
}
void
tst_AST
::
while_statement
()
{
QSharedPointer
<
TranslationUnit
>
unit
(
parseStatement
(
"while (a) { }"
));
AST
*
ast
=
unit
->
ast
();
QVERIFY
(
ast
!=
0
);
WhileStatementAST
*
stmt
=
ast
->
asWhileStatement
();
QVERIFY
(
stmt
!=
0
);
QCOMPARE
(
stmt
->
while_token
,
1U
);
QCOMPARE
(
stmt
->
lparen_token
,
2U
);
QVERIFY
(
stmt
->
condition
!=
0
);
QCOMPARE
(
stmt
->
rparen_token
,
4U
);
QVERIFY
(
stmt
->
statement
!=
0
);
// check condition
QVERIFY
(
stmt
->
condition
->
asSimpleName
()
!=
0
);
QCOMPARE
(
stmt
->
condition
->
asSimpleName
()
->
identifier_token
,
3U
);
// check the `body' statement
CompoundStatementAST
*
body_stmt
=
stmt
->
statement
->
asCompoundStatement
();
QVERIFY
(
body_stmt
!=
0
);
QCOMPARE
(
body_stmt
->
lbrace_token
,
5U
);
QVERIFY
(
body_stmt
->
statements
==
0
);
QCOMPARE
(
body_stmt
->
rbrace_token
,
6U
);
}
void
tst_AST
::
while_condition_statement
()
{
QSharedPointer
<
TranslationUnit
>
unit
(
parseStatement
(
"while (int a = foo) { }"
));
AST
*
ast
=
unit
->
ast
();
QVERIFY
(
ast
!=
0
);
WhileStatementAST
*
stmt
=
ast
->
asWhileStatement
();
QVERIFY
(
stmt
!=
0
);
QCOMPARE
(
stmt
->
while_token
,
1U
);
QCOMPARE
(
stmt
->
lparen_token
,
2U
);
QVERIFY
(
stmt
->
condition
!=
0
);
QCOMPARE
(
stmt
->
rparen_token
,
7U
);
QVERIFY
(
stmt
->
statement
!=
0
);
// check condition
ConditionAST
*
condition
=
stmt
->
condition
->
asCondition
();
QVERIFY
(
condition
!=
0
);
QVERIFY
(
condition
->
type_specifier
!=
0
);
QVERIFY
(
condition
->
type_specifier
->
asSimpleSpecifier
()
!=
0
);
QCOMPARE
(
condition
->
type_specifier
->
asSimpleSpecifier
()
->
specifier_token
,
3U
);
QVERIFY
(
condition
->
type_specifier
->
next
==
0
);
QVERIFY
(
condition
->
declarator
!=
0
);
QVERIFY
(
condition
->
declarator
->
initializer
!=
0
);
// check the `body' statement
CompoundStatementAST
*
body_stmt
=
stmt
->
statement
->
asCompoundStatement
();
QVERIFY
(
body_stmt
!=
0
);
QCOMPARE
(
body_stmt
->
lbrace_token
,
8U
);
QVERIFY
(
body_stmt
->
statements
==
0
);
QCOMPARE
(
body_stmt
->
rbrace_token
,
9U
);
}
void
tst_AST
::
cpp_initializer_or_function_declaration
()
{
QSharedPointer
<
TranslationUnit
>
unit
(
parseStatement
(
"QFileInfo fileInfo(foo);"
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment