summaryrefslogtreecommitdiff
path: root/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
AgeCommit message (Collapse)Author
2024-05-20[clang-format][NFC] Remove redundnat llvm::, clang::, etc.Owen Pan
2023-10-27[clang-format][NFC] Remove extraneous newlines in remaining unit testsOwen Pan
2023-09-26[clang-format] Fix a bug in NamespaceEndCommentsFixer (#67422)Owen Pan
Fixed #67407.
2023-08-16[clang-format] Handle NamespaceMacro string arg for FixNamespaceCommentsOwen Pan
Fixes #63795. Differential Revision: https://reviews.llvm.org/D157568
2023-08-10[clang-format] Correctly count annoated lines of a namespace bodyOwen Pan
Fixes #63882. Differential Revision: https://reviews.llvm.org/D157244
2023-07-24[clang-format] Insert namespace comments with leading spacesOwen Pan
Insert missing namespace comments with SpacesBeforeTrailingComments leading spaces. Fixes #64051. Differential Revision: https://reviews.llvm.org/D156065
2022-03-17[clang-format] Reformat. NFC.Marek Kurdej
2022-03-10[clang-format] Fix namespace format when the name is followed by a macroZequan Wu
Example: ``` $ cat a.cpp namespace my_namespace::yeah API_AVAILABLE(macos(10.15)) { void test() {} } $ clang-format a.cpp namespace my_namespace::yeah API_AVAILABLE(macos(10.15)) { void test() {} }// namespace my_namespace::yeahAPI_AVAILABLE(macos(10.15)) ``` After: ``` $ clang-format a.cpp namespace my_namespace::yeah API_AVAILABLE(macos(10.15)) { void test() {} }// namespace my_namespace::yeah ``` Reviewed By: MyDeveloperDay, owenpan, curdeius Differential Revision: https://reviews.llvm.org/D121269
2022-03-07[clang-format] Fix namespace end comments in ObjC++ files tooNico Weber
See also d96ae867351ec. Differential Revision: https://reviews.llvm.org/D121112
2022-03-04[clang-format] fix namepsace format when the name is macro expansionZequan Wu
Originally filed at crbug.com/1184570. When the name of a namespace is a macro that takes arguments, - It fixed the indentation. - It fixed the namepsace end comments. Differential Revision: https://reviews.llvm.org/D120931
2022-01-14[clang-format] Fix namespace end comments fixer with anonymous namespaces.Marek Kurdej
Previously, a strange trailing comment was produced: ``` namespace out { namespace { }} // namespace out:: ``` (mind the "out::"). Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D117289
2021-12-14[clang-format] FixNamespaceComments does not understand namespace aliasesmydeveloperday
https://github.com/llvm/llvm-project/issues/35876 Ensure a namespace alias doesn't get incorrectly identifier as a namespace Reviewed By: HazardyKnusperkeks, curdeius, owenpan Differential Revision: https://reviews.llvm.org/D115647 Fixes: #35876
2021-03-01[clang-format][PR47290] Add ShortNamespaceLines format optionKrystian Kuzniarek
clang-format documentation states that having enabled FixNamespaceComments one may expect below code: c++ namespace a { foo(); } to be turned into: c++ namespace a { foo(); } // namespace a In reality, no "// namespace a" was added. The problem was too high value of kShortNamespaceMaxLines, which is used while deciding whether a namespace is long enough to be formatted. As with 9163fe2, clang-format idempotence is preserved. Differential Revision: https://reviews.llvm.org/D87587
2020-10-20[clang-format] Drop clangFrontend dependency for FormatTestsAlex Richardson
This allows building the clang-format unit tests in only 657 ninja steps rather than 1257 which allows for much faster incremental builds after a git pull. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D89709
2020-05-30[clang-format] [PR46130] When editing a file with unbalance {} the namespace ↵mydeveloperday
comment fixer can incorrectly comment the wrong closing brace Summary: https://bugs.llvm.org/show_bug.cgi?id=46130 from Twitter https://twitter.com/ikautak/status/1265998988232159232 I have seen this myself many times.. if you have format on save and you work in an editor where you are constantly saving (:w muscle memory) If you are in the middle of editing and somehow you've missed a { or } in your code, somewhere, often way below where you are at the bottom of your file the namespace comment fixer will have put the namespace on the previous closing brace. This leads to you having to fix up the bottom of the file. This revision prevents that happening by performing an initial pass of the tokens and simply counting the number of `{` and `}` and ensuring they balance. If they don't balance we don't do any namespace fixing as it will likely be unstable and incorrect. Reviewed By: curdeius Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D80830
2020-05-02[clang-format] NFC - clang-format the FormatTestsmydeveloperday
Summary: Ensure the clang-format unit tests are themselves clang-formatted Having areas of the llvm code which are clang-format clean, give us more areas to run new clang-format binaries on ensuring we haven't broken anything. It seems to me we SHOULD have this clang-formatted at a minimum, otherwise how can we expect others to use clang-format if we "don't eat our own dogfood", also if the tests are dependent on the formatting of the code then that would also be bad! Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D79204
2019-07-23clang-format: Fix namespace end comments for namespaces with attributes and ↵Nico Weber
macros. Fixes PR39247. While here, also make C++20 `namespace A::inline B::inline C` nested inline namespaced definitions work. Before: #define DEPRECATE_WOOF [[deprecated("meow")]] namespace DEPRECATE_WOOF woof { void f() {} } // namespace DEPRECATE_WOOFwoof namespace [[deprecated("meow")]] woof { void f() {} } // namespace [[deprecated("meow")]]woof namespace woof::inline bark { void f() {} } // namespace woof::inlinebark Now: #define DEPRECATE_WOOF [[deprecated("meow")]] namespace DEPRECATE_WOOF woof { void f() {} } // namespace woof namespace [[deprecated("meow")]] woof { void f() {} } // namespace woof namespace woof::inline bark { void f() {} } // namespace woof::inline bark (In addition to the fixed namespace end comments, also note the correct indent of the namespace contents.) Differential Revision: https://reviews.llvm.org/D65125 llvm-svn: 366831
2019-06-06clang-format: better handle namespace macrosFrancois Ferrand
Summary: Other macros are used to declare namespaces, and should thus be handled similarly. This is the case for crpcut's TESTSUITE macro, or for unittest-cpp's SUITE macro: TESTSUITE(Foo) { TEST(MyFirstTest) { assert(0); } } // TESTSUITE(Foo) This patch deals with this cases by introducing a new option to specify lists of namespace macros. Internally, it re-uses the system already in place for foreach and statement macros, to ensure there is no impact on performance. Reviewers: krasimir, djasper, klimek Reviewed By: klimek Subscribers: acoomans, cfe-commits, klimek Tags: #clang Differential Revision: https://reviews.llvm.org/D37813 llvm-svn: 362740
2019-05-29[NFC] clang-format: Use LLVM style in NamespaceEndCommentsFixerTestFrancois Ferrand
As pointed out in https://reviews.llvm.org/D37813#inline-555026, the code which is formatted does not match LLVM formatting style. Technically this is not a problem since these tests bypass most of the formatter, but it can be misleading. llvm-svn: 361984
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-05-15[clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
2017-07-28clang-format: fix block OpeningLineIndex around preprocessorFrancois Ferrand
Summary: The current code would return an incorrect value when a preprocessor directive is present immediately after the opening brace: this causes the nanespace end comment fixer to break in some places, for exemple it would not add the comment in this case: namespace a { #define FOO } Fixing the computation is simple enough, but it was breaking a feature, as it would cause comments to be added also when the namespace declaration was dependant on conditional compilation. To fix this, a hash of the current preprocessor stack/branches is computed at the beginning of parseBlock(), so that we explicitely do not store the OpeningLineIndex when the beginning and end of the block are not in the same preprocessor conditions. Tthe hash is computed based on the line, but this could propbably be improved by using the actual condition, so that clang-format would be able to match multiple identical #ifdef blocks. Reviewers: krasimir, djasper Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35483 llvm-svn: 309369
2017-06-14clang-format: Add CompactNamespaces optionFrancois Ferrand
Summary: Add CompactNamespaces option, to pack namespace declarations on the same line (somewhat similar to C++17 nested namespace definition). With this option, consecutive namespace declarations are kept on the same line: namespace foo { namespace bar { ... }} // namespace foo::bar Reviewers: krasimir, djasper, klimek Reviewed By: djasper Subscribers: kimgr, cfe-commits, klimek Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32480 llvm-svn: 305384
2017-04-21[clang-format] Clang-tidy cleanup of NamespaceEndCommentFixerTest.cpp, NFCKrasimir Georgiev
llvm-svn: 300983
2017-04-04[clang-format] fix crash in NamespaceEndCommentsFixer (PR32438)Matthias Gehre
Summary: The new test case was crashing before. Now it passes as expected. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31441 llvm-svn: 299465
2017-03-07[clang-format] Support namespaces ending in semicolonKrasimir Georgiev
Summary: This patch adds support for namespaces ending in semicolon to the namespace comment fixer. source: ``` namespace A { int i; int j; }; ``` clang-format before: ``` namespace A { int i; int j; } // namespace A; ``` clang-format after: ``` namespace A { int i; int j; }; // namespace A ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30688 llvm-svn: 297140
2017-03-06[clang-format] Add tests for ambiguous namespaces to the comment fixerKrasimir Georgiev
llvm-svn: 297034
2017-03-06[clang-format] Make NamespaceEndCommentFixer add at most one commentKrasimir Georgiev
Summary: Until now, NamespaceEndCommentFixer was adding missing comments for every run, which results in multiple end comments for: ``` namespace { int i; int j; } #if A int a = 1; #else int a = 2; #endif ``` result before: ``` namespace { int i; int j; }// namespace // namespace #if A int a = 1; #else int a = 2; #endif ``` result after: ``` namespace { int i; int j; }// namespace #if A int a = 1; #else int a = 2; #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30659 llvm-svn: 297028
2017-03-02[clang-format] Use number of unwrapped lines for short namespaceKrasimir Georgiev
Summary: This patch makes the namespace comment fixer use the number of unwrapped lines that a namespace spans to detect it that namespace is short, thus not needing end comments to be added. This is needed to ensure clang-format is idempotent. Previously, a short namespace was detected by the original source code lines. This has the effect of requiring two runs for this example: ``` namespace { class A; } ``` after first run: ``` namespace { class A; } ``` after second run: ``` namespace { class A; } // namespace ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30528 llvm-svn: 296736
2017-03-01[clang-format] Don't add namespace end comments for unbalanced right braces ↵Krasimir Georgiev
after namespace end llvm-svn: 296638
2017-02-27[clang-format] Add a NamespaceEndCommentsFixerKrasimir Georgiev
Summary: This patch adds a NamespaceEndCommentsFixer TokenAnalyzer for clang-format, which fixes end namespace comments. It currently supports inserting and updating existing wrong comments. Example source: ``` namespace A { int i; } namespace B { int j; } // namespace A ``` after formatting: ``` namespace A { int i; } // namespace A namespace B { int j; } // namespace B ``` Reviewers: klimek, djasper Reviewed By: djasper Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D30269 llvm-svn: 296341