Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1 | //===- unittests/AST/CommentParser.cpp ------ Comment parser tests --------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "clang/Basic/SourceManager.h" |
| 11 | #include "clang/Basic/FileManager.h" |
| 12 | #include "clang/Basic/Diagnostic.h" |
| 13 | #include "clang/AST/Comment.h" |
| 14 | #include "clang/AST/CommentLexer.h" |
| 15 | #include "clang/AST/CommentParser.h" |
| 16 | #include "clang/AST/CommentSema.h" |
| 17 | #include "llvm/ADT/STLExtras.h" |
| 18 | #include "llvm/Support/Allocator.h" |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "gtest/gtest.h" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | using namespace clang; |
| 25 | |
| 26 | namespace clang { |
| 27 | namespace comments { |
| 28 | |
| 29 | namespace { |
| 30 | |
| 31 | const bool DEBUG = true; |
| 32 | |
| 33 | class CommentParserTest : public ::testing::Test { |
| 34 | protected: |
| 35 | CommentParserTest() |
| 36 | : FileMgr(FileMgrOpts), |
| 37 | DiagID(new DiagnosticIDs()), |
| 38 | Diags(DiagID, new IgnoringDiagConsumer()), |
| 39 | SourceMgr(Diags, FileMgr) { |
| 40 | } |
| 41 | |
| 42 | FileSystemOptions FileMgrOpts; |
| 43 | FileManager FileMgr; |
| 44 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID; |
| 45 | DiagnosticsEngine Diags; |
| 46 | SourceManager SourceMgr; |
| 47 | llvm::BumpPtrAllocator Allocator; |
| 48 | |
| 49 | FullComment *parseString(const char *Source); |
| 50 | }; |
| 51 | |
| 52 | FullComment *CommentParserTest::parseString(const char *Source) { |
| 53 | MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source); |
| 54 | FileID File = SourceMgr.createFileIDForMemBuffer(Buf); |
| 55 | SourceLocation Begin = SourceMgr.getLocForStartOfFile(File); |
| 56 | |
Dmitri Gribenko | 477a9f5 | 2012-07-27 20:37:06 +0000 | [diff] [blame^] | 57 | comments::Lexer L(Allocator, Begin, CommentOptions(), |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 58 | Source, Source + strlen(Source)); |
| 59 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 60 | comments::Sema S(Allocator, SourceMgr, Diags); |
| 61 | comments::Parser P(L, S, Allocator, SourceMgr, Diags); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 62 | comments::FullComment *FC = P.parseFullComment(); |
| 63 | |
| 64 | if (DEBUG) { |
| 65 | llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n"; |
| 66 | FC->dump(SourceMgr); |
| 67 | } |
| 68 | |
| 69 | Token Tok; |
| 70 | L.lex(Tok); |
| 71 | if (Tok.is(tok::eof)) |
| 72 | return FC; |
| 73 | else |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | ::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) { |
| 78 | if (!C) |
| 79 | return ::testing::AssertionFailure() << "Comment is NULL"; |
| 80 | |
| 81 | if (Count != C->child_count()) |
| 82 | return ::testing::AssertionFailure() |
| 83 | << "Count = " << Count |
| 84 | << ", child_count = " << C->child_count(); |
| 85 | |
| 86 | return ::testing::AssertionSuccess(); |
| 87 | } |
| 88 | |
| 89 | template <typename T> |
| 90 | ::testing::AssertionResult GetChildAt(const Comment *C, |
| 91 | size_t Idx, |
| 92 | T *&Child) { |
| 93 | if (!C) |
| 94 | return ::testing::AssertionFailure() << "Comment is NULL"; |
| 95 | |
| 96 | if (Idx >= C->child_count()) |
| 97 | return ::testing::AssertionFailure() |
| 98 | << "Idx out of range. Idx = " << Idx |
| 99 | << ", child_count = " << C->child_count(); |
| 100 | |
| 101 | Comment::child_iterator I = C->child_begin() + Idx; |
| 102 | Comment *CommentChild = *I; |
| 103 | if (!CommentChild) |
| 104 | return ::testing::AssertionFailure() << "Child is NULL"; |
| 105 | |
| 106 | Child = dyn_cast<T>(CommentChild); |
| 107 | if (!Child) |
| 108 | return ::testing::AssertionFailure() |
| 109 | << "Child is not of requested type, but a " |
| 110 | << CommentChild->getCommentKindName(); |
| 111 | |
| 112 | return ::testing::AssertionSuccess(); |
| 113 | } |
| 114 | |
| 115 | ::testing::AssertionResult HasTextAt(const Comment *C, |
| 116 | size_t Idx, |
| 117 | StringRef Text) { |
| 118 | TextComment *TC; |
| 119 | ::testing::AssertionResult AR = GetChildAt(C, Idx, TC); |
| 120 | if (!AR) |
| 121 | return AR; |
| 122 | |
| 123 | StringRef ActualText = TC->getText(); |
| 124 | if (ActualText != Text) |
| 125 | return ::testing::AssertionFailure() |
| 126 | << "TextComment has text \"" << ActualText.str() << "\", " |
| 127 | "expected \"" << Text.str() << "\""; |
| 128 | |
| 129 | if (TC->hasTrailingNewline()) |
| 130 | return ::testing::AssertionFailure() |
| 131 | << "TextComment has a trailing newline"; |
| 132 | |
| 133 | return ::testing::AssertionSuccess(); |
| 134 | } |
| 135 | |
| 136 | ::testing::AssertionResult HasTextWithNewlineAt(const Comment *C, |
| 137 | size_t Idx, |
| 138 | StringRef Text) { |
| 139 | TextComment *TC; |
| 140 | ::testing::AssertionResult AR = GetChildAt(C, Idx, TC); |
| 141 | if (!AR) |
| 142 | return AR; |
| 143 | |
| 144 | StringRef ActualText = TC->getText(); |
| 145 | if (ActualText != Text) |
| 146 | return ::testing::AssertionFailure() |
| 147 | << "TextComment has text \"" << ActualText.str() << "\", " |
| 148 | "expected \"" << Text.str() << "\""; |
| 149 | |
| 150 | if (!TC->hasTrailingNewline()) |
| 151 | return ::testing::AssertionFailure() |
| 152 | << "TextComment has no trailing newline"; |
| 153 | |
| 154 | return ::testing::AssertionSuccess(); |
| 155 | } |
| 156 | |
| 157 | ::testing::AssertionResult HasBlockCommandAt(const Comment *C, |
| 158 | size_t Idx, |
| 159 | BlockCommandComment *&BCC, |
| 160 | StringRef Name, |
| 161 | ParagraphComment *&Paragraph) { |
| 162 | ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC); |
| 163 | if (!AR) |
| 164 | return AR; |
| 165 | |
| 166 | StringRef ActualName = BCC->getCommandName(); |
| 167 | if (ActualName != Name) |
| 168 | return ::testing::AssertionFailure() |
| 169 | << "BlockCommandComment has name \"" << ActualName.str() << "\", " |
| 170 | "expected \"" << Name.str() << "\""; |
| 171 | |
| 172 | Paragraph = BCC->getParagraph(); |
| 173 | |
| 174 | return ::testing::AssertionSuccess(); |
| 175 | } |
| 176 | |
| 177 | ::testing::AssertionResult HasParamCommandAt( |
| 178 | const Comment *C, |
| 179 | size_t Idx, |
| 180 | ParamCommandComment *&PCC, |
| 181 | StringRef CommandName, |
| 182 | ParamCommandComment::PassDirection Direction, |
| 183 | bool IsDirectionExplicit, |
| 184 | StringRef ParamName, |
| 185 | ParagraphComment *&Paragraph) { |
| 186 | ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC); |
| 187 | if (!AR) |
| 188 | return AR; |
| 189 | |
| 190 | StringRef ActualCommandName = PCC->getCommandName(); |
| 191 | if (ActualCommandName != CommandName) |
| 192 | return ::testing::AssertionFailure() |
| 193 | << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", " |
| 194 | "expected \"" << CommandName.str() << "\""; |
| 195 | |
| 196 | if (PCC->getDirection() != Direction) |
| 197 | return ::testing::AssertionFailure() |
| 198 | << "ParamCommandComment has direction " << PCC->getDirection() << ", " |
| 199 | "expected " << Direction; |
| 200 | |
| 201 | if (PCC->isDirectionExplicit() != IsDirectionExplicit) |
| 202 | return ::testing::AssertionFailure() |
| 203 | << "ParamCommandComment has " |
| 204 | << (PCC->isDirectionExplicit() ? "explicit" : "implicit") |
| 205 | << " direction, " |
| 206 | "expected " << (IsDirectionExplicit ? "explicit" : "implicit"); |
| 207 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 208 | if (!PCC->hasParamName()) |
| 209 | return ::testing::AssertionFailure() |
| 210 | << "ParamCommandComment has no parameter name"; |
| 211 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 212 | StringRef ActualParamName = PCC->getParamName(); |
| 213 | if (ActualParamName != ParamName) |
| 214 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 215 | << "ParamCommandComment has parameter name \"" << ActualParamName.str() |
| 216 | << "\", " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 217 | "expected \"" << ParamName.str() << "\""; |
| 218 | |
| 219 | Paragraph = PCC->getParagraph(); |
| 220 | |
| 221 | return ::testing::AssertionSuccess(); |
| 222 | } |
| 223 | |
| 224 | ::testing::AssertionResult HasInlineCommandAt(const Comment *C, |
| 225 | size_t Idx, |
| 226 | InlineCommandComment *&ICC, |
| 227 | StringRef Name) { |
| 228 | ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC); |
| 229 | if (!AR) |
| 230 | return AR; |
| 231 | |
| 232 | StringRef ActualName = ICC->getCommandName(); |
| 233 | if (ActualName != Name) |
| 234 | return ::testing::AssertionFailure() |
| 235 | << "InlineCommandComment has name \"" << ActualName.str() << "\", " |
| 236 | "expected \"" << Name.str() << "\""; |
| 237 | |
| 238 | return ::testing::AssertionSuccess(); |
| 239 | } |
| 240 | |
| 241 | struct NoArgs {}; |
| 242 | |
| 243 | ::testing::AssertionResult HasInlineCommandAt(const Comment *C, |
| 244 | size_t Idx, |
| 245 | InlineCommandComment *&ICC, |
| 246 | StringRef Name, |
| 247 | NoArgs) { |
| 248 | ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name); |
| 249 | if (!AR) |
| 250 | return AR; |
| 251 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 252 | if (ICC->getNumArgs() != 0) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 253 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 254 | << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 255 | "expected 0"; |
| 256 | |
| 257 | return ::testing::AssertionSuccess(); |
| 258 | } |
| 259 | |
| 260 | ::testing::AssertionResult HasInlineCommandAt(const Comment *C, |
| 261 | size_t Idx, |
| 262 | InlineCommandComment *&ICC, |
| 263 | StringRef Name, |
| 264 | StringRef Arg) { |
| 265 | ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name); |
| 266 | if (!AR) |
| 267 | return AR; |
| 268 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 269 | if (ICC->getNumArgs() != 1) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 270 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 271 | << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 272 | "expected 1"; |
| 273 | |
| 274 | StringRef ActualArg = ICC->getArgText(0); |
| 275 | if (ActualArg != Arg) |
| 276 | return ::testing::AssertionFailure() |
| 277 | << "InlineCommandComment has argument \"" << ActualArg.str() << "\", " |
| 278 | "expected \"" << Arg.str() << "\""; |
| 279 | |
| 280 | return ::testing::AssertionSuccess(); |
| 281 | } |
| 282 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 283 | ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, |
| 284 | size_t Idx, |
| 285 | HTMLStartTagComment *&HST, |
| 286 | StringRef TagName) { |
| 287 | ::testing::AssertionResult AR = GetChildAt(C, Idx, HST); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 288 | if (!AR) |
| 289 | return AR; |
| 290 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 291 | StringRef ActualTagName = HST->getTagName(); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 292 | if (ActualTagName != TagName) |
| 293 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 294 | << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 295 | "expected \"" << TagName.str() << "\""; |
| 296 | |
| 297 | return ::testing::AssertionSuccess(); |
| 298 | } |
| 299 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 300 | struct SelfClosing {}; |
| 301 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 302 | ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, |
| 303 | size_t Idx, |
| 304 | HTMLStartTagComment *&HST, |
| 305 | StringRef TagName, |
| 306 | SelfClosing) { |
| 307 | ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 308 | if (!AR) |
| 309 | return AR; |
| 310 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 311 | if (!HST->isSelfClosing()) |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 312 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 313 | << "HTMLStartTagComment is not self-closing"; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 314 | |
| 315 | return ::testing::AssertionSuccess(); |
| 316 | } |
| 317 | |
| 318 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 319 | struct NoAttrs {}; |
| 320 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 321 | ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, |
| 322 | size_t Idx, |
| 323 | HTMLStartTagComment *&HST, |
| 324 | StringRef TagName, |
| 325 | NoAttrs) { |
| 326 | ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 327 | if (!AR) |
| 328 | return AR; |
| 329 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 330 | if (HST->isSelfClosing()) |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 331 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 332 | << "HTMLStartTagComment is self-closing"; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 333 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 334 | if (HST->getNumAttrs() != 0) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 335 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 336 | << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 337 | "expected 0"; |
| 338 | |
| 339 | return ::testing::AssertionSuccess(); |
| 340 | } |
| 341 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 342 | ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C, |
| 343 | size_t Idx, |
| 344 | HTMLStartTagComment *&HST, |
| 345 | StringRef TagName, |
| 346 | StringRef AttrName, |
| 347 | StringRef AttrValue) { |
| 348 | ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 349 | if (!AR) |
| 350 | return AR; |
| 351 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 352 | if (HST->isSelfClosing()) |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 353 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 354 | << "HTMLStartTagComment is self-closing"; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 355 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 356 | if (HST->getNumAttrs() != 1) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 357 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 358 | << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 359 | "expected 1"; |
| 360 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 361 | StringRef ActualName = HST->getAttr(0).Name; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 362 | if (ActualName != AttrName) |
| 363 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 364 | << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 365 | "expected \"" << AttrName.str() << "\""; |
| 366 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 367 | StringRef ActualValue = HST->getAttr(0).Value; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 368 | if (ActualValue != AttrValue) |
| 369 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 370 | << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 371 | "expected \"" << AttrValue.str() << "\""; |
| 372 | |
| 373 | return ::testing::AssertionSuccess(); |
| 374 | } |
| 375 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 376 | ::testing::AssertionResult HasHTMLEndTagAt(const Comment *C, |
| 377 | size_t Idx, |
| 378 | HTMLEndTagComment *&HET, |
| 379 | StringRef TagName) { |
| 380 | ::testing::AssertionResult AR = GetChildAt(C, Idx, HET); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 381 | if (!AR) |
| 382 | return AR; |
| 383 | |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 384 | StringRef ActualTagName = HET->getTagName(); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 385 | if (ActualTagName != TagName) |
| 386 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 387 | << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 388 | "expected \"" << TagName.str() << "\""; |
| 389 | |
| 390 | return ::testing::AssertionSuccess(); |
| 391 | } |
| 392 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 393 | ::testing::AssertionResult HasParagraphCommentAt(const Comment *C, |
| 394 | size_t Idx, |
| 395 | StringRef Text) { |
| 396 | ParagraphComment *PC; |
| 397 | |
| 398 | { |
| 399 | ::testing::AssertionResult AR = GetChildAt(C, Idx, PC); |
| 400 | if (!AR) |
| 401 | return AR; |
| 402 | } |
| 403 | |
| 404 | { |
| 405 | ::testing::AssertionResult AR = HasChildCount(PC, 1); |
| 406 | if (!AR) |
| 407 | return AR; |
| 408 | } |
| 409 | |
| 410 | { |
| 411 | ::testing::AssertionResult AR = HasTextAt(PC, 0, Text); |
| 412 | if (!AR) |
| 413 | return AR; |
| 414 | } |
| 415 | |
| 416 | return ::testing::AssertionSuccess(); |
| 417 | } |
| 418 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 419 | ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C, |
| 420 | size_t Idx, |
| 421 | VerbatimBlockComment *&VBC, |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 422 | StringRef Name, |
| 423 | StringRef CloseName) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 424 | ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC); |
| 425 | if (!AR) |
| 426 | return AR; |
| 427 | |
| 428 | StringRef ActualName = VBC->getCommandName(); |
| 429 | if (ActualName != Name) |
| 430 | return ::testing::AssertionFailure() |
| 431 | << "VerbatimBlockComment has name \"" << ActualName.str() << "\", " |
| 432 | "expected \"" << Name.str() << "\""; |
| 433 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 434 | StringRef ActualCloseName = VBC->getCloseName(); |
| 435 | if (ActualCloseName != CloseName) |
| 436 | return ::testing::AssertionFailure() |
| 437 | << "VerbatimBlockComment has closing command name \"" |
| 438 | << ActualCloseName.str() << "\", " |
| 439 | "expected \"" << CloseName.str() << "\""; |
| 440 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 441 | return ::testing::AssertionSuccess(); |
| 442 | } |
| 443 | |
| 444 | struct NoLines {}; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 445 | struct Lines {}; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 446 | |
| 447 | ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C, |
| 448 | size_t Idx, |
| 449 | VerbatimBlockComment *&VBC, |
| 450 | StringRef Name, |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 451 | StringRef CloseName, |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 452 | NoLines) { |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 453 | ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name, |
| 454 | CloseName); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 455 | if (!AR) |
| 456 | return AR; |
| 457 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 458 | if (VBC->getNumLines() != 0) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 459 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 460 | << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 461 | "expected 0"; |
| 462 | |
| 463 | return ::testing::AssertionSuccess(); |
| 464 | } |
| 465 | |
| 466 | ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C, |
| 467 | size_t Idx, |
| 468 | VerbatimBlockComment *&VBC, |
| 469 | StringRef Name, |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 470 | StringRef CloseName, |
| 471 | Lines, |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 472 | StringRef Line0) { |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 473 | ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name, |
| 474 | CloseName); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 475 | if (!AR) |
| 476 | return AR; |
| 477 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 478 | if (VBC->getNumLines() != 1) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 479 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 480 | << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 481 | "expected 1"; |
| 482 | |
| 483 | StringRef ActualLine0 = VBC->getText(0); |
| 484 | if (ActualLine0 != Line0) |
| 485 | return ::testing::AssertionFailure() |
| 486 | << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", " |
| 487 | "expected \"" << Line0.str() << "\""; |
| 488 | |
| 489 | return ::testing::AssertionSuccess(); |
| 490 | } |
| 491 | |
| 492 | ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C, |
| 493 | size_t Idx, |
| 494 | VerbatimBlockComment *&VBC, |
| 495 | StringRef Name, |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 496 | StringRef CloseName, |
| 497 | Lines, |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 498 | StringRef Line0, |
| 499 | StringRef Line1) { |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 500 | ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name, |
| 501 | CloseName); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 502 | if (!AR) |
| 503 | return AR; |
| 504 | |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 505 | if (VBC->getNumLines() != 2) |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 506 | return ::testing::AssertionFailure() |
Dmitri Gribenko | 0eaf69d | 2012-07-13 19:02:42 +0000 | [diff] [blame] | 507 | << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), " |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 508 | "expected 2"; |
| 509 | |
| 510 | StringRef ActualLine0 = VBC->getText(0); |
| 511 | if (ActualLine0 != Line0) |
| 512 | return ::testing::AssertionFailure() |
| 513 | << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", " |
| 514 | "expected \"" << Line0.str() << "\""; |
| 515 | |
| 516 | StringRef ActualLine1 = VBC->getText(1); |
| 517 | if (ActualLine1 != Line1) |
| 518 | return ::testing::AssertionFailure() |
| 519 | << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", " |
| 520 | "expected \"" << Line1.str() << "\""; |
| 521 | |
| 522 | return ::testing::AssertionSuccess(); |
| 523 | } |
| 524 | |
| 525 | ::testing::AssertionResult HasVerbatimLineAt(const Comment *C, |
| 526 | size_t Idx, |
| 527 | VerbatimLineComment *&VLC, |
| 528 | StringRef Name, |
| 529 | StringRef Text) { |
| 530 | ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC); |
| 531 | if (!AR) |
| 532 | return AR; |
| 533 | |
| 534 | StringRef ActualName = VLC->getCommandName(); |
| 535 | if (ActualName != Name) |
| 536 | return ::testing::AssertionFailure() |
| 537 | << "VerbatimLineComment has name \"" << ActualName.str() << "\", " |
| 538 | "expected \"" << Name.str() << "\""; |
| 539 | |
| 540 | StringRef ActualText = VLC->getText(); |
| 541 | if (ActualText != Text) |
| 542 | return ::testing::AssertionFailure() |
| 543 | << "VerbatimLineComment has text \"" << ActualText.str() << "\", " |
| 544 | "expected \"" << Text.str() << "\""; |
| 545 | |
| 546 | return ::testing::AssertionSuccess(); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | TEST_F(CommentParserTest, Basic1) { |
| 551 | const char *Source = "//"; |
| 552 | |
| 553 | FullComment *FC = parseString(Source); |
| 554 | ASSERT_TRUE(HasChildCount(FC, 0)); |
| 555 | } |
| 556 | |
| 557 | TEST_F(CommentParserTest, Basic2) { |
| 558 | const char *Source = "// Meow"; |
| 559 | |
| 560 | FullComment *FC = parseString(Source); |
| 561 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 562 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 563 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | TEST_F(CommentParserTest, Basic3) { |
| 567 | const char *Source = |
| 568 | "// Aaa\n" |
| 569 | "// Bbb"; |
| 570 | |
| 571 | FullComment *FC = parseString(Source); |
| 572 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 573 | |
| 574 | { |
| 575 | ParagraphComment *PC; |
| 576 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 577 | |
| 578 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 579 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa")); |
| 580 | ASSERT_TRUE(HasTextAt(PC, 1, " Bbb")); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | TEST_F(CommentParserTest, Paragraph1) { |
| 585 | const char *Sources[] = { |
| 586 | "// Aaa\n" |
| 587 | "//\n" |
| 588 | "// Bbb", |
| 589 | |
| 590 | "// Aaa\n" |
| 591 | "//\n" |
| 592 | "//\n" |
| 593 | "// Bbb", |
| 594 | }; |
| 595 | |
| 596 | |
| 597 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 598 | FullComment *FC = parseString(Sources[i]); |
| 599 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 600 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 601 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa")); |
| 602 | ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | TEST_F(CommentParserTest, Paragraph2) { |
| 607 | const char *Source = |
| 608 | "// \\brief Aaa\n" |
| 609 | "//\n" |
| 610 | "// Bbb"; |
| 611 | |
| 612 | FullComment *FC = parseString(Source); |
| 613 | ASSERT_TRUE(HasChildCount(FC, 3)); |
| 614 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 615 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 616 | { |
| 617 | BlockCommandComment *BCC; |
| 618 | ParagraphComment *PC; |
| 619 | ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC)); |
| 620 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 621 | ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 622 | } |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 623 | ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | TEST_F(CommentParserTest, Paragraph3) { |
| 627 | const char *Source = "// \\brief \\author"; |
| 628 | |
| 629 | FullComment *FC = parseString(Source); |
| 630 | ASSERT_TRUE(HasChildCount(FC, 3)); |
| 631 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 632 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 633 | { |
| 634 | BlockCommandComment *BCC; |
| 635 | ParagraphComment *PC; |
| 636 | ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC)); |
| 637 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 638 | ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 639 | } |
| 640 | { |
| 641 | BlockCommandComment *BCC; |
| 642 | ParagraphComment *PC; |
| 643 | ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC)); |
| 644 | |
| 645 | ASSERT_TRUE(GetChildAt(BCC, 0, PC)); |
| 646 | ASSERT_TRUE(HasChildCount(PC, 0)); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | TEST_F(CommentParserTest, Paragraph4) { |
| 651 | const char *Source = |
| 652 | "// \\brief Aaa\n" |
| 653 | "// Bbb \\author\n" |
| 654 | "// Ccc"; |
| 655 | |
| 656 | FullComment *FC = parseString(Source); |
| 657 | ASSERT_TRUE(HasChildCount(FC, 3)); |
| 658 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 659 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 660 | { |
| 661 | BlockCommandComment *BCC; |
| 662 | ParagraphComment *PC; |
| 663 | ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC)); |
| 664 | |
| 665 | ASSERT_TRUE(GetChildAt(BCC, 0, PC)); |
| 666 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 667 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa")); |
| 668 | ASSERT_TRUE(HasTextAt(PC, 1, " Bbb ")); |
| 669 | } |
| 670 | { |
| 671 | BlockCommandComment *BCC; |
| 672 | ParagraphComment *PC; |
| 673 | ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC)); |
| 674 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 675 | ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | TEST_F(CommentParserTest, ParamCommand1) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 680 | const char *Sources[] = { |
| 681 | "// \\param aaa Bbb\n", |
| 682 | "// \\param\n" |
| 683 | "// aaa Bbb\n", |
| 684 | "// \\param \n" |
| 685 | "// aaa Bbb\n", |
| 686 | "// \\param aaa\n" |
| 687 | "// Bbb\n" |
| 688 | }; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 689 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 690 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 691 | FullComment *FC = parseString(Sources[i]); |
| 692 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 693 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 694 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 695 | { |
| 696 | ParamCommandComment *PCC; |
| 697 | ParagraphComment *PC; |
| 698 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 699 | ParamCommandComment::In, |
| 700 | /* IsDirectionExplicit = */ false, |
| 701 | "aaa", PC)); |
| 702 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 703 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 704 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 705 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | TEST_F(CommentParserTest, ParamCommand2) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 709 | const char *Sources[] = { |
| 710 | "// \\param [in] aaa Bbb\n", |
| 711 | "// \\param\n" |
| 712 | "// [in] aaa Bbb\n", |
| 713 | "// \\param [in]\n" |
| 714 | "// aaa Bbb\n", |
| 715 | "// \\param [in] aaa\n" |
| 716 | "// Bbb\n", |
| 717 | }; |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 718 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 719 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 720 | FullComment *FC = parseString(Sources[i]); |
| 721 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 722 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 723 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 724 | { |
| 725 | ParamCommandComment *PCC; |
| 726 | ParagraphComment *PC; |
| 727 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 728 | ParamCommandComment::In, |
| 729 | /* IsDirectionExplicit = */ true, |
| 730 | "aaa", PC)); |
| 731 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 732 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 733 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 734 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | TEST_F(CommentParserTest, ParamCommand3) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 738 | const char *Sources[] = { |
| 739 | "// \\param [out] aaa Bbb\n", |
| 740 | "// \\param\n" |
| 741 | "// [out] aaa Bbb\n", |
| 742 | "// \\param [out]\n" |
| 743 | "// aaa Bbb\n", |
| 744 | "// \\param [out] aaa\n" |
| 745 | "// Bbb\n", |
| 746 | }; |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 747 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 748 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 749 | FullComment *FC = parseString(Sources[i]); |
| 750 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 751 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 752 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 753 | { |
| 754 | ParamCommandComment *PCC; |
| 755 | ParagraphComment *PC; |
| 756 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 757 | ParamCommandComment::Out, |
| 758 | /* IsDirectionExplicit = */ true, |
| 759 | "aaa", PC)); |
| 760 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 761 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 762 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 766 | TEST_F(CommentParserTest, ParamCommand4) { |
| 767 | const char *Sources[] = { |
| 768 | "// \\param [in,out] aaa Bbb\n", |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 769 | "// \\param [in, out] aaa Bbb\n", |
| 770 | "// \\param [in,\n" |
| 771 | "// out] aaa Bbb\n", |
| 772 | "// \\param [in,out]\n" |
| 773 | "// aaa Bbb\n", |
| 774 | "// \\param [in,out] aaa\n" |
| 775 | "// Bbb\n" |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 776 | }; |
| 777 | |
| 778 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 779 | FullComment *FC = parseString(Sources[i]); |
| 780 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 781 | |
| 782 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 783 | { |
| 784 | ParamCommandComment *PCC; |
| 785 | ParagraphComment *PC; |
| 786 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 787 | ParamCommandComment::InOut, |
| 788 | /* IsDirectionExplicit = */ true, |
| 789 | "aaa", PC)); |
| 790 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 791 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
Dmitri Gribenko | fd93916 | 2012-07-24 16:10:47 +0000 | [diff] [blame] | 796 | TEST_F(CommentParserTest, ParamCommand5) { |
| 797 | const char *Source = |
| 798 | "// \\param aaa \\% Bbb \\$ ccc\n"; |
| 799 | |
| 800 | FullComment *FC = parseString(Source); |
| 801 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 802 | |
| 803 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 804 | { |
| 805 | ParamCommandComment *PCC; |
| 806 | ParagraphComment *PC; |
| 807 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 808 | ParamCommandComment::In, |
| 809 | /* IsDirectionExplicit = */ false, |
| 810 | "aaa", PC)); |
| 811 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 812 | |
| 813 | ASSERT_TRUE(HasChildCount(PC, 5)); |
| 814 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 815 | ASSERT_TRUE(HasTextAt(PC, 1, "%")); |
| 816 | ASSERT_TRUE(HasTextAt(PC, 2, " Bbb ")); |
| 817 | ASSERT_TRUE(HasTextAt(PC, 3, "$")); |
| 818 | ASSERT_TRUE(HasTextAt(PC, 4, " ccc")); |
| 819 | } |
| 820 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 821 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 822 | TEST_F(CommentParserTest, InlineCommand1) { |
| 823 | const char *Source = "// \\c"; |
| 824 | |
| 825 | FullComment *FC = parseString(Source); |
| 826 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 827 | |
| 828 | { |
| 829 | ParagraphComment *PC; |
| 830 | InlineCommandComment *ICC; |
| 831 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 832 | |
| 833 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 834 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 835 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs())); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | TEST_F(CommentParserTest, InlineCommand2) { |
| 840 | const char *Source = "// \\c "; |
| 841 | |
| 842 | FullComment *FC = parseString(Source); |
| 843 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 844 | |
| 845 | { |
| 846 | ParagraphComment *PC; |
| 847 | InlineCommandComment *ICC; |
| 848 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 849 | |
| 850 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 851 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 852 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs())); |
| 853 | ASSERT_TRUE(HasTextAt(PC, 2, " ")); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | TEST_F(CommentParserTest, InlineCommand3) { |
| 858 | const char *Source = "// \\c aaa\n"; |
| 859 | |
| 860 | FullComment *FC = parseString(Source); |
| 861 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 862 | |
| 863 | { |
| 864 | ParagraphComment *PC; |
| 865 | InlineCommandComment *ICC; |
| 866 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 867 | |
| 868 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 869 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 870 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa")); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | TEST_F(CommentParserTest, InlineCommand4) { |
| 875 | const char *Source = "// \\c aaa bbb"; |
| 876 | |
| 877 | FullComment *FC = parseString(Source); |
| 878 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 879 | |
| 880 | { |
| 881 | ParagraphComment *PC; |
| 882 | InlineCommandComment *ICC; |
| 883 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 884 | |
| 885 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 886 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 887 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa")); |
| 888 | ASSERT_TRUE(HasTextAt(PC, 2, " bbb")); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | TEST_F(CommentParserTest, InlineCommand5) { |
| 893 | const char *Source = "// \\unknown aaa\n"; |
| 894 | |
| 895 | FullComment *FC = parseString(Source); |
| 896 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 897 | |
| 898 | { |
| 899 | ParagraphComment *PC; |
| 900 | InlineCommandComment *ICC; |
| 901 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 902 | |
| 903 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 904 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 905 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs())); |
| 906 | ASSERT_TRUE(HasTextAt(PC, 2, " aaa")); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | TEST_F(CommentParserTest, HTML1) { |
| 911 | const char *Sources[] = { |
| 912 | "// <a", |
| 913 | "// <a>", |
| 914 | "// <a >" |
| 915 | }; |
| 916 | |
| 917 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 918 | FullComment *FC = parseString(Sources[i]); |
| 919 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 920 | |
| 921 | { |
| 922 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 923 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 924 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 925 | |
| 926 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 927 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 928 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | TEST_F(CommentParserTest, HTML2) { |
| 934 | const char *Sources[] = { |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 935 | "// <br/>", |
| 936 | "// <br />" |
| 937 | }; |
| 938 | |
| 939 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 940 | FullComment *FC = parseString(Sources[i]); |
| 941 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 942 | |
| 943 | { |
| 944 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 945 | HTMLStartTagComment *HST; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 946 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 947 | |
| 948 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 949 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 950 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing())); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | TEST_F(CommentParserTest, HTML3) { |
| 956 | const char *Sources[] = { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 957 | "// <a href", |
| 958 | "// <a href ", |
| 959 | "// <a href>", |
| 960 | "// <a href >", |
| 961 | }; |
| 962 | |
| 963 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 964 | FullComment *FC = parseString(Sources[i]); |
| 965 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 966 | |
| 967 | { |
| 968 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 969 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 970 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 971 | |
| 972 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 973 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 974 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 979 | TEST_F(CommentParserTest, HTML4) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 980 | const char *Sources[] = { |
| 981 | "// <a href=\"bbb\"", |
| 982 | "// <a href=\"bbb\">", |
| 983 | }; |
| 984 | |
| 985 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 986 | FullComment *FC = parseString(Sources[i]); |
| 987 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 988 | |
| 989 | { |
| 990 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 991 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 992 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 993 | |
| 994 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 995 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 996 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | } |
| 1000 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 1001 | TEST_F(CommentParserTest, HTML5) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1002 | const char *Sources[] = { |
| 1003 | "// </a", |
| 1004 | "// </a>", |
| 1005 | "// </a >" |
| 1006 | }; |
| 1007 | |
| 1008 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1009 | FullComment *FC = parseString(Sources[i]); |
| 1010 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1011 | |
| 1012 | { |
| 1013 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1014 | HTMLEndTagComment *HET; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1015 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 1016 | |
| 1017 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 1018 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1019 | ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 1024 | TEST_F(CommentParserTest, HTML6) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1025 | const char *Source = |
| 1026 | "// <pre>\n" |
| 1027 | "// Aaa\n" |
| 1028 | "// Bbb\n" |
| 1029 | "// </pre>\n"; |
| 1030 | |
| 1031 | FullComment *FC = parseString(Source); |
| 1032 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1033 | |
| 1034 | { |
| 1035 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1036 | HTMLStartTagComment *HST; |
| 1037 | HTMLEndTagComment *HET; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1038 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 1039 | |
| 1040 | ASSERT_TRUE(HasChildCount(PC, 6)); |
| 1041 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1042 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1043 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa")); |
| 1044 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb")); |
| 1045 | ASSERT_TRUE(HasTextAt(PC, 4, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1046 | ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | TEST_F(CommentParserTest, VerbatimBlock1) { |
| 1051 | const char *Source = "// \\verbatim\\endverbatim\n"; |
| 1052 | |
| 1053 | FullComment *FC = parseString(Source); |
| 1054 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1055 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1056 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1057 | { |
| 1058 | VerbatimBlockComment *VCC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1059 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim", |
| 1060 | NoLines())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | TEST_F(CommentParserTest, VerbatimBlock2) { |
| 1065 | const char *Source = "// \\verbatim Aaa \\endverbatim\n"; |
| 1066 | |
| 1067 | FullComment *FC = parseString(Source); |
| 1068 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1069 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1070 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1071 | { |
| 1072 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1073 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1074 | Lines(), " Aaa ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | TEST_F(CommentParserTest, VerbatimBlock3) { |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1079 | const char *Source = "// \\verbatim Aaa\n"; |
| 1080 | |
| 1081 | FullComment *FC = parseString(Source); |
| 1082 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1083 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1084 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1085 | { |
| 1086 | VerbatimBlockComment *VBC; |
| 1087 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "", |
| 1088 | Lines(), " Aaa")); |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | TEST_F(CommentParserTest, VerbatimBlock4) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1093 | const char *Source = |
| 1094 | "//\\verbatim\n" |
| 1095 | "//\\endverbatim\n"; |
| 1096 | |
| 1097 | FullComment *FC = parseString(Source); |
| 1098 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1099 | |
| 1100 | { |
| 1101 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1102 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim", |
| 1103 | NoLines())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1107 | TEST_F(CommentParserTest, VerbatimBlock5) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1108 | const char *Sources[] = { |
| 1109 | "//\\verbatim\n" |
| 1110 | "// Aaa\n" |
| 1111 | "//\\endverbatim\n", |
| 1112 | |
| 1113 | "/*\\verbatim\n" |
| 1114 | " * Aaa\n" |
| 1115 | " *\\endverbatim*/" |
| 1116 | }; |
| 1117 | |
| 1118 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1119 | FullComment *FC = parseString(Sources[i]); |
| 1120 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1121 | |
| 1122 | { |
| 1123 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1124 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim", |
| 1125 | Lines(), " Aaa")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1130 | TEST_F(CommentParserTest, VerbatimBlock6) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1131 | const char *Sources[] = { |
| 1132 | "// \\verbatim\n" |
| 1133 | "// Aaa\n" |
| 1134 | "// \\endverbatim\n", |
| 1135 | |
| 1136 | "/* \\verbatim\n" |
| 1137 | " * Aaa\n" |
| 1138 | " * \\endverbatim*/" |
| 1139 | }; |
| 1140 | |
| 1141 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1142 | FullComment *FC = parseString(Sources[i]); |
| 1143 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1144 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1145 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1146 | { |
| 1147 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1148 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1149 | Lines(), " Aaa")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1154 | TEST_F(CommentParserTest, VerbatimBlock7) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1155 | const char *Sources[] = { |
| 1156 | "// \\verbatim\n" |
| 1157 | "// Aaa\n" |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1158 | "// Bbb\n" |
| 1159 | "// \\endverbatim\n", |
| 1160 | |
| 1161 | "/* \\verbatim\n" |
| 1162 | " * Aaa\n" |
| 1163 | " * Bbb\n" |
| 1164 | " * \\endverbatim*/" |
| 1165 | }; |
| 1166 | |
| 1167 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1168 | FullComment *FC = parseString(Sources[i]); |
| 1169 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1170 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1171 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1172 | { |
| 1173 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1174 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1175 | Lines(), " Aaa", " Bbb")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1180 | TEST_F(CommentParserTest, VerbatimBlock8) { |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1181 | const char *Sources[] = { |
| 1182 | "// \\verbatim\n" |
| 1183 | "// Aaa\n" |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1184 | "//\n" |
| 1185 | "// Bbb\n" |
| 1186 | "// \\endverbatim\n", |
| 1187 | |
| 1188 | "/* \\verbatim\n" |
| 1189 | " * Aaa\n" |
| 1190 | " *\n" |
| 1191 | " * Bbb\n" |
| 1192 | " * \\endverbatim*/" |
| 1193 | }; |
| 1194 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1195 | FullComment *FC = parseString(Sources[i]); |
| 1196 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1197 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1198 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1199 | { |
| 1200 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1201 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1202 | ASSERT_EQ(3U, VBC->getNumLines()); |
| 1203 | ASSERT_EQ(" Aaa", VBC->getText(0)); |
| 1204 | ASSERT_EQ("", VBC->getText(1)); |
| 1205 | ASSERT_EQ(" Bbb", VBC->getText(2)); |
| 1206 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | TEST_F(CommentParserTest, VerbatimLine1) { |
| 1211 | const char *Sources[] = { |
| 1212 | "// \\fn", |
| 1213 | "// \\fn\n" |
| 1214 | }; |
| 1215 | |
| 1216 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1217 | FullComment *FC = parseString(Sources[i]); |
| 1218 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1219 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1220 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1221 | { |
| 1222 | VerbatimLineComment *VLC; |
| 1223 | ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", "")); |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | TEST_F(CommentParserTest, VerbatimLine2) { |
| 1229 | const char *Sources[] = { |
| 1230 | "/// \\fn void *foo(const char *zzz = \"\\$\");\n//", |
| 1231 | "/** \\fn void *foo(const char *zzz = \"\\$\");*/" |
| 1232 | }; |
| 1233 | |
| 1234 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1235 | FullComment *FC = parseString(Sources[i]); |
| 1236 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1237 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1238 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1239 | { |
| 1240 | VerbatimLineComment *VLC; |
| 1241 | ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", |
| 1242 | " void *foo(const char *zzz = \"\\$\");")); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | } // unnamed namespace |
| 1248 | |
| 1249 | } // end namespace comments |
| 1250 | } // end namespace clang |
| 1251 | |