diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /unittests/Format/FormatTestJS.cpp | |
parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) |
Diffstat (limited to 'unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | unittests/Format/FormatTestJS.cpp | 98 |
1 files changed, 78 insertions, 20 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index e7808c6596d0b..67b99ba146dad 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -191,31 +191,32 @@ TEST_F(FormatTestJS, JSDocComments) { // Break a single line long jsdoc comment pragma. EXPECT_EQ("/**\n" - " * @returns\n" - " * {string}\n" - " * jsdoc line 12\n" + " * @returns {string} jsdoc line 12\n" " */", format("/** @returns {string} jsdoc line 12 */", getGoogleJSStyleWithColumns(20))); - EXPECT_EQ("/**\n" - " * @returns\n" - " * {string}\n" + " * @returns {string}\n" " * jsdoc line 12\n" " */", + format("/** @returns {string} jsdoc line 12 */", + getGoogleJSStyleWithColumns(25))); + + EXPECT_EQ("/**\n" + " * @returns {string} jsdoc line 12\n" + " */", format("/** @returns {string} jsdoc line 12 */", getGoogleJSStyleWithColumns(20))); // FIXME: this overcounts the */ as a continuation of the 12 when breaking. // Related to the FIXME in BreakableBlockComment::getRangeLength. EXPECT_EQ("/**\n" - " * @returns\n" - " * {string}\n" - " * jsdoc line\n" + " * @returns {string}\n" + " * jsdoc line line\n" " * 12\n" " */", - format("/** @returns {string} jsdoc line 12*/", - getGoogleJSStyleWithColumns(20))); + format("/** @returns {string} jsdoc line line 12*/", + getGoogleJSStyleWithColumns(25))); // Fix a multiline jsdoc comment ending in a comment pragma. EXPECT_EQ("/**\n" @@ -599,6 +600,8 @@ TEST_F(FormatTestJS, GoogModules) { getGoogleJSStyleWithColumns(40)); verifyFormat("var long = goog.require('this.is.really.absurdly.long');", getGoogleJSStyleWithColumns(40)); + verifyFormat("const X = goog.requireType('this.is.really.absurdly.long');", + getGoogleJSStyleWithColumns(40)); verifyFormat("goog.forwardDeclare('this.is.really.absurdly.long');", getGoogleJSStyleWithColumns(40)); @@ -1185,6 +1188,16 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) { getGoogleJSStyleWithColumns(25)); } +TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) { + // Do not confuse is, the dict key with is, the type matcher. Put is, the dict + // key, on a newline. + verifyFormat("Polymer({\n" + " is: '', //\n" + " rest: 1\n" + "});", + getGoogleJSStyleWithColumns(20)); +} + TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) { verifyFormat("a\n" "b;", @@ -2038,29 +2051,42 @@ TEST_F(FormatTestJS, WrapAfterParen) { TEST_F(FormatTestJS, JSDocAnnotations) { verifyFormat("/**\n" - " * @exports\n" - " * {this.is.a.long.path.to.a.Type}\n" + " * @exports {this.is.a.long.path.to.a.Type}\n" " */", "/**\n" " * @exports {this.is.a.long.path.to.a.Type}\n" " */", getGoogleJSStyleWithColumns(20)); verifyFormat("/**\n" - " * @mods\n" - " * {this.is.a.long.path.to.a.Type}\n" + " * @mods {this.is.a.long.path.to.a.Type}\n" + " */", + "/**\n" + " * @mods {this.is.a.long.path.to.a.Type}\n" + " */", + getGoogleJSStyleWithColumns(20)); + verifyFormat("/**\n" + " * @mods {this.is.a.long.path.to.a.Type}\n" " */", "/**\n" " * @mods {this.is.a.long.path.to.a.Type}\n" " */", getGoogleJSStyleWithColumns(20)); verifyFormat("/**\n" - " * @param\n" - " * {this.is.a.long.path.to.a.Type}\n" + " * @param {canWrap\n" + " * onSpace}\n" " */", "/**\n" - " * @param {this.is.a.long.path.to.a.Type}\n" + " * @param {canWrap onSpace}\n" " */", getGoogleJSStyleWithColumns(20)); + // make sure clang-format doesn't break before *any* '{' + verifyFormat("/**\n" + " * @lala {lala {lalala\n" + " */\n", + "/**\n" + " * @lala {lala {lalala\n" + " */\n", + getGoogleJSStyleWithColumns(20)); verifyFormat("/**\n" " * @see http://very/very/long/url/is/long\n" " */", @@ -2083,8 +2109,7 @@ TEST_F(FormatTestJS, JSDocAnnotations) { " /**\n" " * long long long\n" " * long\n" - " * @param\n" - " * {this.is.a.long.path.to.a.Type}\n" + " * @param {this.is.a.long.path.to.a.Type}\n" " * a\n" " * long long long\n" " * long long\n" @@ -2271,5 +2296,38 @@ TEST_F(FormatTestJS, BackslashesInComments) { "formatMe( );\n"); } +TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) { + EXPECT_EQ( + "a = function() {\n" + " b = function() {\n" + " this.aaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa] = aaaa.aaaaaa ?\n" + " aaaa.aaaaaa : /** @type " + "{aaaa.aaaa.aaaaaaaaa.aaaaaaaaaaaaaaaaaaa} */\n" + " (aaaa.aaaa.aaaaaaaaa.aaaaaaaaaaaaa.aaaaaaaaaaaaaaaaa);\n" + " };\n" + "};", + format("a = function() {\n" + " b = function() {\n" + " this.aaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa] = aaaa.aaaaaa ? " + "aaaa.aaaaaa : /** @type " + "{aaaa.aaaa.aaaaaaaaa.aaaaaaaaaaaaaaaaaaa} */\n" + " (aaaa.aaaa.aaaaaaaaa.aaaaaaaaaaaaa.aaaaaaaaaaaaaaaaa);\n" + " };\n" + "};")); +} + +TEST_F(FormatTestJS, ParameterNamingComment) { + verifyFormat("callFoo(/*spaceAfterParameterNamingComment=*/ 1);"); +} + +TEST_F(FormatTestJS, ConditionalTypes) { + // Formatting below is not necessarily intentional, this just ensures that + // clang-format does not break the code. + verifyFormat( // wrap + "type UnionToIntersection<U> =\n" + " (U extends any ? (k: U) => void :\n" + " never) extends((k: infer I) => void) ? I : never;"); +} + } // end namespace tooling } // end namespace clang |