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 | 3ccc173 | 2012-07-30 16:52:51 +0000 | [diff] [blame] | 680 | const char *Source = "// \\param aaa"; |
| 681 | |
| 682 | FullComment *FC = parseString(Source); |
| 683 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 684 | |
| 685 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 686 | { |
| 687 | ParamCommandComment *PCC; |
| 688 | ParagraphComment *PC; |
| 689 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 690 | ParamCommandComment::In, |
| 691 | /* IsDirectionExplicit = */ false, |
| 692 | "aaa", PC)); |
| 693 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 694 | ASSERT_TRUE(HasChildCount(PC, 0)); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | TEST_F(CommentParserTest, ParamCommand2) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 699 | const char *Sources[] = { |
| 700 | "// \\param aaa Bbb\n", |
| 701 | "// \\param\n" |
| 702 | "// aaa Bbb\n", |
| 703 | "// \\param \n" |
| 704 | "// aaa Bbb\n", |
| 705 | "// \\param aaa\n" |
| 706 | "// Bbb\n" |
| 707 | }; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 708 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 709 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 710 | FullComment *FC = parseString(Sources[i]); |
| 711 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 712 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 713 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 714 | { |
| 715 | ParamCommandComment *PCC; |
| 716 | ParagraphComment *PC; |
| 717 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 718 | ParamCommandComment::In, |
| 719 | /* IsDirectionExplicit = */ false, |
| 720 | "aaa", PC)); |
| 721 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 722 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 723 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 724 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Dmitri Gribenko | 3ccc173 | 2012-07-30 16:52:51 +0000 | [diff] [blame] | 727 | TEST_F(CommentParserTest, ParamCommand3) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 728 | const char *Sources[] = { |
| 729 | "// \\param [in] aaa Bbb\n", |
| 730 | "// \\param\n" |
| 731 | "// [in] aaa Bbb\n", |
| 732 | "// \\param [in]\n" |
| 733 | "// aaa Bbb\n", |
| 734 | "// \\param [in] aaa\n" |
| 735 | "// Bbb\n", |
| 736 | }; |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 737 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 738 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 739 | FullComment *FC = parseString(Sources[i]); |
| 740 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 741 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 742 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 743 | { |
| 744 | ParamCommandComment *PCC; |
| 745 | ParagraphComment *PC; |
| 746 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 747 | ParamCommandComment::In, |
| 748 | /* IsDirectionExplicit = */ true, |
| 749 | "aaa", PC)); |
| 750 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 751 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 752 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 753 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Dmitri Gribenko | 3ccc173 | 2012-07-30 16:52:51 +0000 | [diff] [blame] | 756 | TEST_F(CommentParserTest, ParamCommand4) { |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 757 | const char *Sources[] = { |
| 758 | "// \\param [out] aaa Bbb\n", |
| 759 | "// \\param\n" |
| 760 | "// [out] aaa Bbb\n", |
| 761 | "// \\param [out]\n" |
| 762 | "// aaa Bbb\n", |
| 763 | "// \\param [out] aaa\n" |
| 764 | "// Bbb\n", |
| 765 | }; |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 766 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 767 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 768 | FullComment *FC = parseString(Sources[i]); |
| 769 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 770 | |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 771 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 772 | { |
| 773 | ParamCommandComment *PCC; |
| 774 | ParagraphComment *PC; |
| 775 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 776 | ParamCommandComment::Out, |
| 777 | /* IsDirectionExplicit = */ true, |
| 778 | "aaa", PC)); |
| 779 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 780 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 781 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Dmitri Gribenko | 3ccc173 | 2012-07-30 16:52:51 +0000 | [diff] [blame] | 785 | TEST_F(CommentParserTest, ParamCommand5) { |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 786 | const char *Sources[] = { |
| 787 | "// \\param [in,out] aaa Bbb\n", |
Dmitri Gribenko | 0c43a92 | 2012-07-24 18:23:31 +0000 | [diff] [blame] | 788 | "// \\param [in, out] aaa Bbb\n", |
| 789 | "// \\param [in,\n" |
| 790 | "// out] aaa Bbb\n", |
| 791 | "// \\param [in,out]\n" |
| 792 | "// aaa Bbb\n", |
| 793 | "// \\param [in,out] aaa\n" |
| 794 | "// Bbb\n" |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 795 | }; |
| 796 | |
| 797 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 798 | FullComment *FC = parseString(Sources[i]); |
| 799 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 800 | |
| 801 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 802 | { |
| 803 | ParamCommandComment *PCC; |
| 804 | ParagraphComment *PC; |
| 805 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 806 | ParamCommandComment::InOut, |
| 807 | /* IsDirectionExplicit = */ true, |
| 808 | "aaa", PC)); |
| 809 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 810 | ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
Dmitri Gribenko | 3ccc173 | 2012-07-30 16:52:51 +0000 | [diff] [blame] | 815 | TEST_F(CommentParserTest, ParamCommand6) { |
Dmitri Gribenko | fd93916 | 2012-07-24 16:10:47 +0000 | [diff] [blame] | 816 | const char *Source = |
| 817 | "// \\param aaa \\% Bbb \\$ ccc\n"; |
| 818 | |
| 819 | FullComment *FC = parseString(Source); |
| 820 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 821 | |
| 822 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
| 823 | { |
| 824 | ParamCommandComment *PCC; |
| 825 | ParagraphComment *PC; |
| 826 | ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param", |
| 827 | ParamCommandComment::In, |
| 828 | /* IsDirectionExplicit = */ false, |
| 829 | "aaa", PC)); |
| 830 | ASSERT_TRUE(HasChildCount(PCC, 1)); |
| 831 | |
| 832 | ASSERT_TRUE(HasChildCount(PC, 5)); |
| 833 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 834 | ASSERT_TRUE(HasTextAt(PC, 1, "%")); |
| 835 | ASSERT_TRUE(HasTextAt(PC, 2, " Bbb ")); |
| 836 | ASSERT_TRUE(HasTextAt(PC, 3, "$")); |
| 837 | ASSERT_TRUE(HasTextAt(PC, 4, " ccc")); |
| 838 | } |
| 839 | } |
Dmitri Gribenko | e68c229 | 2012-07-23 23:37:11 +0000 | [diff] [blame] | 840 | |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 841 | TEST_F(CommentParserTest, InlineCommand1) { |
| 842 | const char *Source = "// \\c"; |
| 843 | |
| 844 | FullComment *FC = parseString(Source); |
| 845 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 846 | |
| 847 | { |
| 848 | ParagraphComment *PC; |
| 849 | InlineCommandComment *ICC; |
| 850 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 851 | |
| 852 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 853 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 854 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs())); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | TEST_F(CommentParserTest, InlineCommand2) { |
| 859 | const char *Source = "// \\c "; |
| 860 | |
| 861 | FullComment *FC = parseString(Source); |
| 862 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 863 | |
| 864 | { |
| 865 | ParagraphComment *PC; |
| 866 | InlineCommandComment *ICC; |
| 867 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 868 | |
| 869 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 870 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 871 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs())); |
| 872 | ASSERT_TRUE(HasTextAt(PC, 2, " ")); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | TEST_F(CommentParserTest, InlineCommand3) { |
| 877 | const char *Source = "// \\c aaa\n"; |
| 878 | |
| 879 | FullComment *FC = parseString(Source); |
| 880 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 881 | |
| 882 | { |
| 883 | ParagraphComment *PC; |
| 884 | InlineCommandComment *ICC; |
| 885 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 886 | |
| 887 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 888 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 889 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa")); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | TEST_F(CommentParserTest, InlineCommand4) { |
| 894 | const char *Source = "// \\c aaa bbb"; |
| 895 | |
| 896 | FullComment *FC = parseString(Source); |
| 897 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 898 | |
| 899 | { |
| 900 | ParagraphComment *PC; |
| 901 | InlineCommandComment *ICC; |
| 902 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 903 | |
| 904 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 905 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 906 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa")); |
| 907 | ASSERT_TRUE(HasTextAt(PC, 2, " bbb")); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | TEST_F(CommentParserTest, InlineCommand5) { |
| 912 | const char *Source = "// \\unknown aaa\n"; |
| 913 | |
| 914 | FullComment *FC = parseString(Source); |
| 915 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 916 | |
| 917 | { |
| 918 | ParagraphComment *PC; |
| 919 | InlineCommandComment *ICC; |
| 920 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 921 | |
| 922 | ASSERT_TRUE(HasChildCount(PC, 3)); |
| 923 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
| 924 | ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs())); |
| 925 | ASSERT_TRUE(HasTextAt(PC, 2, " aaa")); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | TEST_F(CommentParserTest, HTML1) { |
| 930 | const char *Sources[] = { |
| 931 | "// <a", |
| 932 | "// <a>", |
| 933 | "// <a >" |
| 934 | }; |
| 935 | |
| 936 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 937 | FullComment *FC = parseString(Sources[i]); |
| 938 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 939 | |
| 940 | { |
| 941 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 942 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 943 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 944 | |
| 945 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 946 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 947 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | TEST_F(CommentParserTest, HTML2) { |
| 953 | const char *Sources[] = { |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 954 | "// <br/>", |
| 955 | "// <br />" |
| 956 | }; |
| 957 | |
| 958 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 959 | FullComment *FC = parseString(Sources[i]); |
| 960 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 961 | |
| 962 | { |
| 963 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 964 | HTMLStartTagComment *HST; |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 965 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 966 | |
| 967 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 968 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 969 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing())); |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | TEST_F(CommentParserTest, HTML3) { |
| 975 | const char *Sources[] = { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 976 | "// <a href", |
| 977 | "// <a href ", |
| 978 | "// <a href>", |
| 979 | "// <a href >", |
| 980 | }; |
| 981 | |
| 982 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 983 | FullComment *FC = parseString(Sources[i]); |
| 984 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 985 | |
| 986 | { |
| 987 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 988 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 989 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 990 | |
| 991 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 992 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 993 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 998 | TEST_F(CommentParserTest, HTML4) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 999 | const char *Sources[] = { |
| 1000 | "// <a href=\"bbb\"", |
| 1001 | "// <a href=\"bbb\">", |
| 1002 | }; |
| 1003 | |
| 1004 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1005 | FullComment *FC = parseString(Sources[i]); |
| 1006 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1007 | |
| 1008 | { |
| 1009 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1010 | HTMLStartTagComment *HST; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1011 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 1012 | |
| 1013 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 1014 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1015 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 1020 | TEST_F(CommentParserTest, HTML5) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1021 | const char *Sources[] = { |
| 1022 | "// </a", |
| 1023 | "// </a>", |
| 1024 | "// </a >" |
| 1025 | }; |
| 1026 | |
| 1027 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1028 | FullComment *FC = parseString(Sources[i]); |
| 1029 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1030 | |
| 1031 | { |
| 1032 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1033 | HTMLEndTagComment *HET; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1034 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 1035 | |
| 1036 | ASSERT_TRUE(HasChildCount(PC, 2)); |
| 1037 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1038 | ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
Dmitri Gribenko | a5ef44f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 1043 | TEST_F(CommentParserTest, HTML6) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1044 | const char *Source = |
| 1045 | "// <pre>\n" |
| 1046 | "// Aaa\n" |
| 1047 | "// Bbb\n" |
| 1048 | "// </pre>\n"; |
| 1049 | |
| 1050 | FullComment *FC = parseString(Source); |
| 1051 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1052 | |
| 1053 | { |
| 1054 | ParagraphComment *PC; |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1055 | HTMLStartTagComment *HST; |
| 1056 | HTMLEndTagComment *HET; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1057 | ASSERT_TRUE(GetChildAt(FC, 0, PC)); |
| 1058 | |
| 1059 | ASSERT_TRUE(HasChildCount(PC, 6)); |
| 1060 | ASSERT_TRUE(HasTextAt(PC, 0, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1061 | ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1062 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa")); |
| 1063 | ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb")); |
| 1064 | ASSERT_TRUE(HasTextAt(PC, 4, " ")); |
Dmitri Gribenko | 3f38bf2 | 2012-07-13 00:44:24 +0000 | [diff] [blame] | 1065 | ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | TEST_F(CommentParserTest, VerbatimBlock1) { |
| 1070 | const char *Source = "// \\verbatim\\endverbatim\n"; |
| 1071 | |
| 1072 | FullComment *FC = parseString(Source); |
| 1073 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1074 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1075 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1076 | { |
| 1077 | VerbatimBlockComment *VCC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1078 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim", |
| 1079 | NoLines())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | TEST_F(CommentParserTest, VerbatimBlock2) { |
| 1084 | const char *Source = "// \\verbatim Aaa \\endverbatim\n"; |
| 1085 | |
| 1086 | FullComment *FC = parseString(Source); |
| 1087 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1088 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1089 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1090 | { |
| 1091 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1092 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1093 | Lines(), " Aaa ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | TEST_F(CommentParserTest, VerbatimBlock3) { |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1098 | const char *Source = "// \\verbatim Aaa\n"; |
| 1099 | |
| 1100 | FullComment *FC = parseString(Source); |
| 1101 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1102 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1103 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1104 | { |
| 1105 | VerbatimBlockComment *VBC; |
| 1106 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "", |
| 1107 | Lines(), " Aaa")); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | TEST_F(CommentParserTest, VerbatimBlock4) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1112 | const char *Source = |
| 1113 | "//\\verbatim\n" |
| 1114 | "//\\endverbatim\n"; |
| 1115 | |
| 1116 | FullComment *FC = parseString(Source); |
| 1117 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1118 | |
| 1119 | { |
| 1120 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1121 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim", |
| 1122 | NoLines())); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1126 | TEST_F(CommentParserTest, VerbatimBlock5) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1127 | const char *Sources[] = { |
| 1128 | "//\\verbatim\n" |
| 1129 | "// Aaa\n" |
| 1130 | "//\\endverbatim\n", |
| 1131 | |
| 1132 | "/*\\verbatim\n" |
| 1133 | " * Aaa\n" |
| 1134 | " *\\endverbatim*/" |
| 1135 | }; |
| 1136 | |
| 1137 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1138 | FullComment *FC = parseString(Sources[i]); |
| 1139 | ASSERT_TRUE(HasChildCount(FC, 1)); |
| 1140 | |
| 1141 | { |
| 1142 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1143 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim", |
| 1144 | Lines(), " Aaa")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1149 | TEST_F(CommentParserTest, VerbatimBlock6) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1150 | const char *Sources[] = { |
| 1151 | "// \\verbatim\n" |
| 1152 | "// Aaa\n" |
| 1153 | "// \\endverbatim\n", |
| 1154 | |
| 1155 | "/* \\verbatim\n" |
| 1156 | " * Aaa\n" |
| 1157 | " * \\endverbatim*/" |
| 1158 | }; |
| 1159 | |
| 1160 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1161 | FullComment *FC = parseString(Sources[i]); |
| 1162 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1163 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1164 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1165 | { |
| 1166 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1167 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1168 | Lines(), " Aaa")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1173 | TEST_F(CommentParserTest, VerbatimBlock7) { |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1174 | const char *Sources[] = { |
| 1175 | "// \\verbatim\n" |
| 1176 | "// Aaa\n" |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1177 | "// Bbb\n" |
| 1178 | "// \\endverbatim\n", |
| 1179 | |
| 1180 | "/* \\verbatim\n" |
| 1181 | " * Aaa\n" |
| 1182 | " * Bbb\n" |
| 1183 | " * \\endverbatim*/" |
| 1184 | }; |
| 1185 | |
| 1186 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1187 | FullComment *FC = parseString(Sources[i]); |
| 1188 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1189 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1190 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1191 | { |
| 1192 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1193 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim", |
| 1194 | Lines(), " Aaa", " Bbb")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1199 | TEST_F(CommentParserTest, VerbatimBlock8) { |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1200 | const char *Sources[] = { |
| 1201 | "// \\verbatim\n" |
| 1202 | "// Aaa\n" |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1203 | "//\n" |
| 1204 | "// Bbb\n" |
| 1205 | "// \\endverbatim\n", |
| 1206 | |
| 1207 | "/* \\verbatim\n" |
| 1208 | " * Aaa\n" |
| 1209 | " *\n" |
| 1210 | " * Bbb\n" |
| 1211 | " * \\endverbatim*/" |
| 1212 | }; |
| 1213 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1214 | FullComment *FC = parseString(Sources[i]); |
| 1215 | ASSERT_TRUE(HasChildCount(FC, 2)); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1216 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1217 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1218 | { |
| 1219 | VerbatimBlockComment *VBC; |
Dmitri Gribenko | 9f08f49 | 2012-07-20 20:18:53 +0000 | [diff] [blame] | 1220 | ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim")); |
Dmitri Gribenko | 64da4e5 | 2012-07-18 23:01:58 +0000 | [diff] [blame] | 1221 | ASSERT_EQ(3U, VBC->getNumLines()); |
| 1222 | ASSERT_EQ(" Aaa", VBC->getText(0)); |
| 1223 | ASSERT_EQ("", VBC->getText(1)); |
| 1224 | ASSERT_EQ(" Bbb", VBC->getText(2)); |
| 1225 | } |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | TEST_F(CommentParserTest, VerbatimLine1) { |
| 1230 | const char *Sources[] = { |
| 1231 | "// \\fn", |
| 1232 | "// \\fn\n" |
| 1233 | }; |
| 1234 | |
| 1235 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1236 | FullComment *FC = parseString(Sources[i]); |
| 1237 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1238 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1239 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1240 | { |
| 1241 | VerbatimLineComment *VLC; |
| 1242 | ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", "")); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | TEST_F(CommentParserTest, VerbatimLine2) { |
| 1248 | const char *Sources[] = { |
| 1249 | "/// \\fn void *foo(const char *zzz = \"\\$\");\n//", |
| 1250 | "/** \\fn void *foo(const char *zzz = \"\\$\");*/" |
| 1251 | }; |
| 1252 | |
| 1253 | for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { |
| 1254 | FullComment *FC = parseString(Sources[i]); |
| 1255 | ASSERT_TRUE(HasChildCount(FC, 2)); |
| 1256 | |
Dmitri Gribenko | debd16f | 2012-07-23 23:09:32 +0000 | [diff] [blame] | 1257 | ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1258 | { |
| 1259 | VerbatimLineComment *VLC; |
| 1260 | ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", |
| 1261 | " void *foo(const char *zzz = \"\\$\");")); |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | } // unnamed namespace |
| 1267 | |
| 1268 | } // end namespace comments |
| 1269 | } // end namespace clang |
| 1270 | |