summaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTestJS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Format/FormatTestJS.cpp')
-rw-r--r--unittests/Format/FormatTestJS.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 2a929563f7544..9975b7d311253 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -21,8 +21,8 @@ class FormatTestJS : public ::testing::Test {
protected:
static std::string format(llvm::StringRef Code, unsigned Offset,
unsigned Length, const FormatStyle &Style) {
- DEBUG(llvm::errs() << "---\n");
- DEBUG(llvm::errs() << Code << "\n\n");
+ LLVM_DEBUG(llvm::errs() << "---\n");
+ LLVM_DEBUG(llvm::errs() << Code << "\n\n");
std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
FormattingAttemptStatus Status;
tooling::Replacements Replaces =
@@ -30,7 +30,7 @@ protected:
EXPECT_TRUE(Status.FormatComplete);
auto Result = applyAllReplacements(Code, Replaces);
EXPECT_TRUE(static_cast<bool>(Result));
- DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+ LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
return *Result;
}
@@ -49,6 +49,8 @@ protected:
static void verifyFormat(
llvm::StringRef Code,
const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+ EXPECT_EQ(Code.str(), format(Code, Style))
+ << "Expected code is not stable";
std::string Result = format(test::messUp(Code), Style);
EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
}
@@ -57,6 +59,8 @@ protected:
llvm::StringRef Expected,
llvm::StringRef Code,
const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+ EXPECT_EQ(Expected.str(), format(Expected, Style))
+ << "Expected code is not stable";
std::string Result = format(Code, Style);
EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
}
@@ -294,6 +298,7 @@ TEST_F(FormatTestJS, ReservedWords) {
verifyFormat("x.for = 1;");
verifyFormat("x.of();");
verifyFormat("of(null);");
+ verifyFormat("return of(null);");
verifyFormat("import {of} from 'x';");
verifyFormat("x.in();");
verifyFormat("x.let();");
@@ -1157,6 +1162,17 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
"foo() {}",
getGoogleJSStyleWithColumns(10));
verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
+ verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+ verifyFormat("x = (a['a']\n"
+ " ['b']);",
+ getGoogleJSStyleWithColumns(10));
+ verifyFormat("function f() {\n"
+ " return foo.bar(\n"
+ " (param): param is {\n"
+ " a: SomeType\n"
+ " }&ABC => 1)\n"
+ "}",
+ getGoogleJSStyleWithColumns(25));
}
TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
@@ -1524,6 +1540,15 @@ TEST_F(FormatTestJS, ClassDeclarations) {
"}");
}
+TEST_F(FormatTestJS, StrictPropInitWrap) {
+ const FormatStyle &Style = getGoogleJSStyleWithColumns(22);
+ verifyFormat("class X {\n"
+ " strictPropInitField!:\n"
+ " string;\n"
+ "}",
+ Style);
+}
+
TEST_F(FormatTestJS, InterfaceDeclarations) {
verifyFormat("interface I {\n"
" x: string;\n"
@@ -2129,6 +2154,7 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) {
verifyFormat("let x = foo!.bar();\n");
verifyFormat("let x = foo ? bar! : baz;\n");
verifyFormat("let x = !foo;\n");
+ verifyFormat("if (!+a) {\n}");
verifyFormat("let x = foo[0]!;\n");
verifyFormat("let x = (foo)!;\n");
verifyFormat("let x = x(foo!);\n");