diff options
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 41ffbedea74..1481ef0f285 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -98,6 +98,7 @@ TEST_F(FormatTestJS, ES6DestructuringAssignment) { } TEST_F(FormatTestJS, ContainerLiterals) { + verifyFormat("var x = {y: function(a) { return a; }};"); verifyFormat("return {\n" " link: function() {\n" " f(); //\n" @@ -142,6 +143,10 @@ TEST_F(FormatTestJS, ContainerLiterals) { verifyFormat("X = {\n a: 123\n};"); verifyFormat("X.Y = {\n a: 123\n};"); verifyFormat("x = foo && {a: 123};"); + + // Arrow functions in object literals. + verifyFormat("var x = {y: (a) => { return a; }};"); + verifyFormat("var x = {y: (a) => a};"); } TEST_F(FormatTestJS, MethodsInObjectLiterals) { @@ -419,13 +424,28 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) { " .thenCatch(function(error) { body(); });"); } +TEST_F(FormatTestJS, ArrowFunctions) { + verifyFormat("var x = (a) => {\n" + " return a;\n" + "};"); + verifyFormat("var x = (a) => {\n" + " function y() { return 42; }\n" + " return a;\n" + "};"); + verifyFormat("var x = (a: type): {some: type} => {\n" + " return a;\n" + "};"); + verifyFormat("var x = (a) => a;"); + verifyFormat("var x = (a) => a;"); +} + TEST_F(FormatTestJS, ReturnStatements) { verifyFormat("function() {\n" " return [hello, world];\n" "}"); } -TEST_F(FormatTestJS, ClosureStyleComments) { +TEST_F(FormatTestJS, ClosureStyleCasts) { verifyFormat("var x = /** @type {foo} */ (bar);"); } @@ -536,11 +556,14 @@ TEST_F(FormatTestJS, RegexLiteralExamples) { TEST_F(FormatTestJS, TypeAnnotations) { verifyFormat("var x: string;"); verifyFormat("function x(): string {\n return 'x';\n}"); + verifyFormat("function x(): {x: string} {\n return {x: 'x'};\n}"); verifyFormat("function x(y: string): string {\n return 'x';\n}"); verifyFormat("for (var y: string in x) {\n x();\n}"); verifyFormat("((a: string, b: number): string => a + b);"); verifyFormat("var x: (y: number) => string;"); verifyFormat("var x: P<string, (a: number) => string>;"); + verifyFormat("var x = {y: function(): z { return 1; }};"); + verifyFormat("var x = {y: function(): {a: number} { return 1; }};"); } TEST_F(FormatTestJS, ClassDeclarations) { |

