[cfe-commits] r160647 - /cfe/trunk/unittests/AST/CommentParser.cpp
Dmitri Gribenko
gribozavr at gmail.com
Mon Jul 23 16:09:32 PDT 2012
Author: gribozavr
Date: Mon Jul 23 18:09:32 2012
New Revision: 160647
URL: http://llvm.org/viewvc/llvm-project?rev=160647&view=rev
Log:
Comment parser unit tests: reduce code duplication
Modified:
cfe/trunk/unittests/AST/CommentParser.cpp
Modified: cfe/trunk/unittests/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/CommentParser.cpp?rev=160647&r1=160646&r2=160647&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/CommentParser.cpp (original)
+++ cfe/trunk/unittests/AST/CommentParser.cpp Mon Jul 23 18:09:32 2012
@@ -385,6 +385,32 @@
return ::testing::AssertionSuccess();
}
+::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
+ size_t Idx,
+ StringRef Text) {
+ ParagraphComment *PC;
+
+ {
+ ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
+ if (!AR)
+ return AR;
+ }
+
+ {
+ ::testing::AssertionResult AR = HasChildCount(PC, 1);
+ if (!AR)
+ return AR;
+ }
+
+ {
+ ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
+ if (!AR)
+ return AR;
+ }
+
+ return ::testing::AssertionSuccess();
+}
+
::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
size_t Idx,
VerbatimBlockComment *&VBC,
@@ -529,13 +555,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Meow"));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
}
TEST_F(CommentParserTest, Basic3) {
@@ -573,20 +593,8 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Aaa"));
- }
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 1, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Bbb"));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
}
}
@@ -599,30 +607,15 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 3));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
BlockCommandComment *BCC;
ParagraphComment *PC;
ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
- ASSERT_TRUE(GetChildAt(BCC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Aaa"));
- }
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 2, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Bbb"));
+ ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
}
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
}
TEST_F(CommentParserTest, Paragraph3) {
@@ -631,21 +624,13 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 3));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
BlockCommandComment *BCC;
ParagraphComment *PC;
ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
- ASSERT_TRUE(GetChildAt(BCC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
+ ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
}
{
BlockCommandComment *BCC;
@@ -666,13 +651,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 3));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
BlockCommandComment *BCC;
ParagraphComment *PC;
@@ -688,9 +667,7 @@
ParagraphComment *PC;
ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
- ASSERT_TRUE(GetChildAt(BCC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " Ccc"));
+ ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
}
}
@@ -705,13 +682,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 6));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
ParamCommandComment *PCC;
ParagraphComment *PC;
@@ -1002,13 +973,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VCC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
@@ -1022,13 +987,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VBC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
@@ -1042,13 +1001,7 @@
FullComment *FC = parseString(Source);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VBC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
@@ -1109,13 +1062,7 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VBC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
@@ -1141,13 +1088,7 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VBC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
@@ -1174,13 +1115,7 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimBlockComment *VBC;
ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
@@ -1202,13 +1137,7 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimLineComment *VLC;
ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
@@ -1226,13 +1155,7 @@
FullComment *FC = parseString(Sources[i]);
ASSERT_TRUE(HasChildCount(FC, 2));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
-
- ASSERT_TRUE(HasChildCount(PC, 1));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- }
+ ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
{
VerbatimLineComment *VLC;
ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
More information about the cfe-commits
mailing list