diff options
author | Martin Probst <martin@probst.io> | 2017-05-29 08:41:11 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-05-29 08:41:11 +0000 |
commit | 816a9668bb6c56b5fae96cbe6ca8c33aa90be1e5 (patch) | |
tree | 6f575887b876a0e3ef3e2f59d66a9e015854ab7b /clang/unittests/Format/CleanupTest.cpp | |
parent | 3b189d1643fe788ec4792984758a2c0bcaac1b36 (diff) | |
download | bcm5719-llvm-816a9668bb6c56b5fae96cbe6ca8c33aa90be1e5.tar.gz bcm5719-llvm-816a9668bb6c56b5fae96cbe6ca8c33aa90be1e5.zip |
clang-format: [JS] do not clean up duplicated commas.
Summary:
In JavaScript, duplicated commas have semantic meaning.
x = [a,,b];
The statement above creates an array with three entries, the middle being undefined. Because clang-format should not change semantics, disable this cleanup in JS.
Reviewers: djasper
Subscribers: klimek
Differential Revision: https://reviews.llvm.org/D33641
llvm-svn: 304141
Diffstat (limited to 'clang/unittests/Format/CleanupTest.cpp')
-rw-r--r-- | clang/unittests/Format/CleanupTest.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index e554a819127..708fdf89689 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -36,11 +36,12 @@ protected: // Returns code after cleanup around \p Offsets. std::string cleanupAroundOffsets(llvm::ArrayRef<unsigned> Offsets, - llvm::StringRef Code) { + llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle()) { std::vector<tooling::Range> Ranges; for (auto Offset : Offsets) Ranges.push_back(tooling::Range(Offset, 0)); - return cleanup(Code, Ranges); + return cleanup(Code, Ranges, Style); } }; @@ -171,6 +172,14 @@ TEST_F(CleanupTest, ListRedundantComma) { EXPECT_EQ(Expected, cleanupAroundOffsets({17, 22}, Code)); } +TEST_F(CleanupTest, NoCleanupsForJavaScript) { + std::string Code = "function f() { var x = [a, b, , c]; }"; + std::string Expected = "function f() { var x = [a, b, , c]; }"; + const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript); + + EXPECT_EQ(Expected, cleanupAroundOffsets({30}, Code, Style)); +} + TEST_F(CleanupTest, TrailingCommaInParens) { std::string Code = "int main() { f(,1,,2,3,f(1,2,),4,,);}"; std::string Expected = "int main() { f(1,2,3,f(1,2),4);}"; |