diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-12-10 11:28:13 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-12-10 11:28:13 +0000 |
commit | c1637f167c7a2b6a3b4f30634b074a04bd60cd9a (patch) | |
tree | df0f7c9170c667d5059dd191a2a050bd7893b9ec /clang/unittests/Format/FormatTestJS.cpp | |
parent | b5c4b876907c3af47e1141a9221b5cb1f9372e06 (diff) | |
download | bcm5719-llvm-c1637f167c7a2b6a3b4f30634b074a04bd60cd9a.tar.gz bcm5719-llvm-c1637f167c7a2b6a3b4f30634b074a04bd60cd9a.zip |
Allow predefined styles to define different options for different languages.
Summary:
Allow predefined styles to define different options for different
languages so that one can run:
clang-format -style=google file1.cpp file2.js
or use a single .clang-format file with "BasedOnStyle: Google" for both c++ and
JS files.
Added Google style for JavaScript with "BreakBeforeTernaryOperators" set to
false.
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2364
llvm-svn: 196909
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 1f8f139574a..0d242a7bc92 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -33,24 +33,18 @@ protected: } static std::string format(llvm::StringRef Code, - const FormatStyle &Style = getJSStyle()) { + const FormatStyle &Style = getGoogleJSStyle()) { return format(Code, 0, Code.size(), Style); } - static FormatStyle getJSStyle() { - FormatStyle Style = getLLVMStyle(); - Style.Language = FormatStyle::LK_JavaScript; - return Style; - } - - static FormatStyle getJSStyleWithColumns(unsigned ColumnLimit) { - FormatStyle Style = getJSStyle(); + static FormatStyle getGoogleJSStyleWithColumns(unsigned ColumnLimit) { + FormatStyle Style = getGoogleJSStyle(); Style.ColumnLimit = ColumnLimit; return Style; } static void verifyFormat(llvm::StringRef Code, - const FormatStyle &Style = getJSStyle()) { + const FormatStyle &Style = getGoogleJSStyle()) { EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); } }; @@ -60,26 +54,30 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { verifyFormat("a != = b;"); verifyFormat("a === b;"); - verifyFormat("aaaaaaa ===\n b;", getJSStyleWithColumns(10)); + verifyFormat("aaaaaaa ===\n b;", getGoogleJSStyleWithColumns(10)); verifyFormat("a !== b;"); - verifyFormat("aaaaaaa !==\n b;", getJSStyleWithColumns(10)); + verifyFormat("aaaaaaa !==\n b;", getGoogleJSStyleWithColumns(10)); verifyFormat("if (a + b + c +\n" " d !==\n" " e + f + g)\n" " q();", - getJSStyleWithColumns(20)); + getGoogleJSStyleWithColumns(20)); verifyFormat("a >> >= b;"); verifyFormat("a >>> b;"); - verifyFormat("aaaaaaa >>>\n b;", getJSStyleWithColumns(10)); + verifyFormat("aaaaaaa >>>\n b;", getGoogleJSStyleWithColumns(10)); verifyFormat("a >>>= b;"); - verifyFormat("aaaaaaa >>>=\n b;", getJSStyleWithColumns(10)); + verifyFormat("aaaaaaa >>>=\n b;", getGoogleJSStyleWithColumns(10)); verifyFormat("if (a + b + c +\n" " d >>>\n" " e + f + g)\n" " q();", - getJSStyleWithColumns(20)); + getGoogleJSStyleWithColumns(20)); + verifyFormat("var x = aaaaaaaaaa ?\n" + " bbbbbb :\n" + " ccc;", + getGoogleJSStyleWithColumns(20)); } } // end namespace tooling |