| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "clang/AST/RawCommentList.h" |
| 15 | #include "clang/Basic/CommentOptions.h" |
| 16 | #include "clang/Basic/Diagnostic.h" |
| 17 | #include "clang/Basic/DiagnosticIDs.h" |
| 18 | #include "clang/Basic/FileManager.h" |
| 19 | #include "clang/Basic/FileSystemOptions.h" |
| 20 | #include "clang/Basic/SourceLocation.h" |
| 21 | #include "clang/Basic/SourceManager.h" |
| 22 | #include "llvm/Support/MemoryBuffer.h" |
| 23 | #include "llvm/Support/VirtualFileSystem.h" |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | namespace clang { |
| 27 | |
| 28 | class : public ::testing::Test { |
| 29 | protected: |
| 30 | std::string (llvm::StringRef ) { |
| 31 | SourceManagerForFile FileSourceMgr("comment-test.cpp", CommentText); |
| 32 | SourceManager& SourceMgr = FileSourceMgr.get(); |
| 33 | |
| 34 | auto = CommentText.find("/"); |
| 35 | assert(CommentStartOffset != llvm::StringRef::npos); |
| 36 | FileID File = SourceMgr.getMainFileID(); |
| 37 | |
| 38 | SourceRange ( |
| 39 | SourceMgr.getLocForStartOfFile(File).getLocWithOffset( |
| 40 | CommentStartOffset), |
| 41 | SourceMgr.getLocForEndOfFile(File)); |
| 42 | CommentOptions EmptyOpts; |
| 43 | |
| 44 | |
| 45 | RawComment (SourceMgr, CommentRange, EmptyOpts, ); |
| 46 | DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions); |
| 47 | return Comment.getFormattedText(SourceMgr, Diags); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | (CommentTextTest, FormattedText) { |
| 52 | |
| 53 | auto ExpectedOutput = |
| 54 | R"(This function does this and that. |
| 55 | For example, |
| 56 | Runnning it in that case will give you |
| 57 | this result. |
| 58 | That's about it.)"; |
| 59 | |
| 60 | auto Formatted = formatComment( |
| 61 | R"cpp( |
| 62 | // This function does this and that. |
| 63 | // For example, |
| 64 | // Runnning it in that case will give you |
| 65 | // this result. |
| 66 | // That's about it.)cpp"); |
| 67 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 68 | |
| 69 | |
| 70 | Formatted = formatComment( |
| 71 | R"cpp( |
| 72 | /// This function does this and that. |
| 73 | /// For example, |
| 74 | /// Runnning it in that case will give you |
| 75 | /// this result. |
| 76 | /// That's about it.)cpp"); |
| 77 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 78 | |
| 79 | |
| 80 | Formatted = formatComment( |
| 81 | R"cpp( |
| 82 | /* This function does this and that. |
| 83 | * For example, |
| 84 | * Runnning it in that case will give you |
| 85 | * this result. |
| 86 | * That's about it.*/)cpp"); |
| 87 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 88 | |
| 89 | |
| 90 | Formatted = formatComment( |
| 91 | R"cpp( |
| 92 | /** This function does this and that. |
| 93 | * For example, |
| 94 | * Runnning it in that case will give you |
| 95 | * this result. |
| 96 | * That's about it.*/)cpp"); |
| 97 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 98 | |
| 99 | |
| 100 | Formatted = formatComment( |
| 101 | R"cpp( |
| 102 | // This function does this and that. |
| 103 | // For example, |
| 104 | // Runnning it in that case will give you |
| 105 | // this result. |
| 106 | // That's about it.)cpp"); |
| 107 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 108 | |
| 109 | } |
| 110 | |
| 111 | (CommentTextTest, KeepsDoxygenControlSeqs) { |
| 112 | |
| 113 | auto ExpectedOutput = |
| 114 | R"(\brief This is the brief part of the comment. |
| 115 | \param a something about a. |
| 116 | @param b something about b.)"; |
| 117 | |
| 118 | auto Formatted = formatComment( |
| 119 | R"cpp( |
| 120 | /// \brief This is the brief part of the comment. |
| 121 | /// \param a something about a. |
| 122 | /// @param b something about b.)cpp"); |
| 123 | EXPECT_EQ(ExpectedOutput, Formatted); |
| 124 | |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | |