diff options
author | David Spickett <david.spickett@linaro.org> | 2023-08-24 08:12:55 +0000 |
---|---|---|
committer | David Spickett <david.spickett@linaro.org> | 2023-08-24 08:15:17 +0000 |
commit | 547bce36132ae0d92226599b6b8702051571461f (patch) | |
tree | fb8c15584891601ec4c193bde562092df2bcb1c3 /clang/unittests/Format/FormatTestJava.cpp | |
parent | 09ccc5563ebe70be2b5a5421df43cd5720ba1f5b (diff) | |
download | llvm-547bce36132ae0d92226599b6b8702051571461f.zip llvm-547bce36132ae0d92226599b6b8702051571461f.tar.gz llvm-547bce36132ae0d92226599b6b8702051571461f.tar.bz2 |
Revert "[clang-format] Break long string literals in C#, etc."
This reverts commit 16ccba51072bbc5ff4c66f91f939163dc91e5d96.
This is failing across Linaro's bots e.g.:
https://lab.llvm.org/buildbot/#/builders/188/builds/34393
Diffstat (limited to 'clang/unittests/Format/FormatTestJava.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index f3bf70a..51afe79 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -6,19 +6,34 @@ // //===----------------------------------------------------------------------===// -#include "FormatTestBase.h" +#include "FormatTestUtils.h" +#include "clang/Format/Format.h" +#include "llvm/Support/Debug.h" +#include "gtest/gtest.h" #define DEBUG_TYPE "format-test" namespace clang { namespace format { -namespace test { -namespace { -class FormatTestJava : public test::FormatTestBase { +class FormatTestJava : public ::testing::Test { protected: - FormatStyle getDefaultStyle() const override { - return getGoogleStyle(FormatStyle::LK_Java); + static std::string format(llvm::StringRef Code, unsigned Offset, + unsigned Length, const FormatStyle &Style) { + LLVM_DEBUG(llvm::errs() << "---\n"); + LLVM_DEBUG(llvm::errs() << Code << "\n\n"); + std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); + tooling::Replacements Replaces = reformat(Style, Code, Ranges); + auto Result = applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast<bool>(Result)); + LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); + return *Result; + } + + static std::string + format(llvm::StringRef Code, + const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) { + return format(Code, 0, Code.size(), Style); } static FormatStyle getStyleWithColumns(unsigned ColumnLimit) { @@ -26,6 +41,13 @@ protected: Style.ColumnLimit = ColumnLimit; return Style; } + + static void verifyFormat( + llvm::StringRef Code, + const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) { + EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; + EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); + } }; TEST_F(FormatTestJava, NoAlternativeOperatorNames) { @@ -543,9 +565,9 @@ TEST_F(FormatTestJava, FormatsLambdas) { } TEST_F(FormatTestJava, BreaksStringLiterals) { - verifyFormat("x = \"some text \"\n" - " + \"other\";", - "x = \"some text other\";", getStyleWithColumns(18)); + // FIXME: String literal breaking is currently disabled for Java and JS, as it + // requires strings to be merged using "+" which we don't support. + verifyFormat("\"some text other\";", getStyleWithColumns(14)); } TEST_F(FormatTestJava, AlignsBlockComments) { @@ -603,7 +625,5 @@ TEST_F(FormatTestJava, ShortFunctions) { Style); } -} // namespace -} // namespace test } // namespace format -} // namespace clang +} // end namespace clang |