1 //===- unittest/Format/FormatTestJS.cpp - Formatting unit tests for JS ----===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "FormatTestUtils.h" 11 #include "clang/Format/Format.h" 12 #include "llvm/Support/Debug.h" 13 #include "gtest/gtest.h" 14 15 #define DEBUG_TYPE "format-test" 16 17 namespace clang { 18 namespace format { 19 20 class FormatTestJS : public ::testing::Test { 21 protected: 22 static std::string format(llvm::StringRef Code, unsigned Offset, 23 unsigned Length, const FormatStyle &Style) { 24 DEBUG(llvm::errs() << "---\n"); 25 DEBUG(llvm::errs() << Code << "\n\n"); 26 std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); 27 tooling::Replacements Replaces = reformat(Style, Code, Ranges); 28 std::string Result = applyAllReplacements(Code, Replaces); 29 EXPECT_NE("", Result); 30 DEBUG(llvm::errs() << "\n" << Result << "\n\n"); 31 return Result; 32 } 33 34 static std::string format( 35 llvm::StringRef Code, 36 const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { 37 return format(Code, 0, Code.size(), Style); 38 } 39 40 static FormatStyle getGoogleJSStyleWithColumns(unsigned ColumnLimit) { 41 FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); 42 Style.ColumnLimit = ColumnLimit; 43 return Style; 44 } 45 46 static void verifyFormat( 47 llvm::StringRef Code, 48 const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { 49 EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); 50 } 51 }; 52 53 TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { 54 verifyFormat("a == = b;"); 55 verifyFormat("a != = b;"); 56 57 verifyFormat("a === b;"); 58 verifyFormat("aaaaaaa ===\n b;", getGoogleJSStyleWithColumns(10)); 59 verifyFormat("a !== b;"); 60 verifyFormat("aaaaaaa !==\n b;", getGoogleJSStyleWithColumns(10)); 61 verifyFormat("if (a + b + c +\n" 62 " d !==\n" 63 " e + f + g)\n" 64 " q();", 65 getGoogleJSStyleWithColumns(20)); 66 67 verifyFormat("a >> >= b;"); 68 69 verifyFormat("a >>> b;"); 70 verifyFormat("aaaaaaa >>>\n b;", getGoogleJSStyleWithColumns(10)); 71 verifyFormat("a >>>= b;"); 72 verifyFormat("aaaaaaa >>>=\n b;", getGoogleJSStyleWithColumns(10)); 73 verifyFormat("if (a + b + c +\n" 74 " d >>>\n" 75 " e + f + g)\n" 76 " q();", 77 getGoogleJSStyleWithColumns(20)); 78 verifyFormat("var x = aaaaaaaaaa ?\n" 79 " bbbbbb :\n" 80 " ccc;", 81 getGoogleJSStyleWithColumns(20)); 82 83 verifyFormat("var b = a.map((x) => x + 1);"); 84 verifyFormat("return ('aaa') in bbbb;"); 85 } 86 87 TEST_F(FormatTestJS, UnderstandsAmpAmp) { 88 verifyFormat("e && e.SomeFunction();"); 89 } 90 91 TEST_F(FormatTestJS, LiteralOperatorsCanBeKeywords) { 92 verifyFormat("not.and.or.not_eq = 1;"); 93 } 94 95 TEST_F(FormatTestJS, ES6DestructuringAssignment) { 96 verifyFormat("var [a, b, c] = [1, 2, 3];"); 97 verifyFormat("var {a, b} = {a: 1, b: 2};"); 98 } 99 100 TEST_F(FormatTestJS, ContainerLiterals) { 101 verifyFormat("return {\n" 102 " link: function() {\n" 103 " f(); //\n" 104 " }\n" 105 "};"); 106 verifyFormat("return {\n" 107 " a: a,\n" 108 " link: function() {\n" 109 " f(); //\n" 110 " }\n" 111 "};"); 112 verifyFormat("return {\n" 113 " a: a,\n" 114 " link: function() {\n" 115 " f(); //\n" 116 " },\n" 117 " link: function() {\n" 118 " f(); //\n" 119 " }\n" 120 "};"); 121 verifyFormat("var stuff = {\n" 122 " // comment for update\n" 123 " update: false,\n" 124 " // comment for modules\n" 125 " modules: false,\n" 126 " // comment for tasks\n" 127 " tasks: false\n" 128 "};"); 129 verifyFormat("return {\n" 130 " 'finish':\n" 131 " //\n" 132 " a\n" 133 "};"); 134 verifyFormat("var obj = {\n" 135 " fooooooooo: function(x) {\n" 136 " return x.zIsTooLongForOneLineWithTheDeclarationLine();\n" 137 " }\n" 138 "};"); 139 // Simple object literal, as opposed to enum style below. 140 verifyFormat("var obj = {a: 123};"); 141 // Enum style top level assignment. 142 verifyFormat("X = {\n a: 123\n};"); 143 verifyFormat("X.Y = {\n a: 123\n};"); 144 verifyFormat("x = foo && {a: 123};"); 145 } 146 147 TEST_F(FormatTestJS, MethodsInObjectLiterals) { 148 verifyFormat("var o = {\n" 149 " value: 'test',\n" 150 " get value() { // getter\n" 151 " return this.value;\n" 152 " }\n" 153 "};"); 154 verifyFormat("var o = {\n" 155 " value: 'test',\n" 156 " set value(val) { // setter\n" 157 " this.value = val;\n" 158 " }\n" 159 "};"); 160 verifyFormat("var o = {\n" 161 " value: 'test',\n" 162 " someMethod(val) { // method\n" 163 " doSomething(this.value + val);\n" 164 " }\n" 165 "};"); 166 } 167 168 TEST_F(FormatTestJS, SpacesInContainerLiterals) { 169 verifyFormat("var arr = [1, 2, 3];"); 170 verifyFormat("f({a: 1, b: 2, c: 3});"); 171 172 verifyFormat("var object_literal_with_long_name = {\n" 173 " a: 'aaaaaaaaaaaaaaaaaa',\n" 174 " b: 'bbbbbbbbbbbbbbbbbb'\n" 175 "};"); 176 177 verifyFormat("f({a: 1, b: 2, c: 3});", 178 getChromiumStyle(FormatStyle::LK_JavaScript)); 179 verifyFormat("f({'a': [{}]});"); 180 } 181 182 TEST_F(FormatTestJS, SingleQuoteStrings) { 183 verifyFormat("this.function('', true);"); 184 } 185 186 TEST_F(FormatTestJS, GoogScopes) { 187 verifyFormat("goog.scope(function() {\n" 188 "var x = a.b;\n" 189 "var y = c.d;\n" 190 "}); // goog.scope"); 191 verifyFormat("goog.scope(function() {\n" 192 "// test\n" 193 "var x = 0;\n" 194 "// test\n" 195 "});"); 196 } 197 198 TEST_F(FormatTestJS, GoogModules) { 199 verifyFormat("goog.module('this.is.really.absurdly.long');", 200 getGoogleJSStyleWithColumns(40)); 201 verifyFormat("goog.require('this.is.really.absurdly.long');", 202 getGoogleJSStyleWithColumns(40)); 203 verifyFormat("goog.provide('this.is.really.absurdly.long');", 204 getGoogleJSStyleWithColumns(40)); 205 verifyFormat("var long = goog.require('this.is.really.absurdly.long');", 206 getGoogleJSStyleWithColumns(40)); 207 208 // These should be wrapped normally. 209 verifyFormat( 210 "var MyLongClassName =\n" 211 " goog.module.get('my.long.module.name.followedBy.MyLongClassName');"); 212 } 213 214 TEST_F(FormatTestJS, FormatsFreestandingFunctions) { 215 verifyFormat("function outer1(a, b) {\n" 216 " function inner1(a, b) { return a; }\n" 217 " inner1(a, b);\n" 218 "}\n" 219 "function outer2(a, b) {\n" 220 " function inner2(a, b) { return a; }\n" 221 " inner2(a, b);\n" 222 "}"); 223 } 224 225 TEST_F(FormatTestJS, FunctionLiterals) { 226 verifyFormat("doFoo(function() {});"); 227 verifyFormat("doFoo(function() { return 1; });"); 228 verifyFormat("var func = function() {\n" 229 " return 1;\n" 230 "};"); 231 verifyFormat("return {\n" 232 " body: {\n" 233 " setAttribute: function(key, val) { this[key] = val; },\n" 234 " getAttribute: function(key) { return this[key]; },\n" 235 " style: {direction: ''}\n" 236 " }\n" 237 "};"); 238 EXPECT_EQ("abc = xyz ?\n" 239 " function() {\n" 240 " return 1;\n" 241 " } :\n" 242 " function() {\n" 243 " return -1;\n" 244 " };", 245 format("abc=xyz?function(){return 1;}:function(){return -1;};")); 246 247 verifyFormat("var closure = goog.bind(\n" 248 " function() { // comment\n" 249 " foo();\n" 250 " bar();\n" 251 " },\n" 252 " this, arg1IsReallyLongAndNeeedsLineBreaks,\n" 253 " arg3IsReallyLongAndNeeedsLineBreaks);"); 254 verifyFormat("var closure = goog.bind(function() { // comment\n" 255 " foo();\n" 256 " bar();\n" 257 "}, this);"); 258 verifyFormat("return {\n" 259 " a: 'E',\n" 260 " b: function() {\n" 261 " return function() {\n" 262 " f(); //\n" 263 " };\n" 264 " }\n" 265 "};"); 266 verifyFormat("{\n" 267 " var someVariable = function(x) {\n" 268 " return x.zIsTooLongForOneLineWithTheDeclarationLine();\n" 269 " };\n" 270 "}"); 271 272 verifyFormat("f({a: function() { return 1; }});", 273 getGoogleJSStyleWithColumns(33)); 274 verifyFormat("f({\n" 275 " a: function() { return 1; }\n" 276 "});", 277 getGoogleJSStyleWithColumns(32)); 278 279 verifyFormat("return {\n" 280 " a: function SomeFunction() {\n" 281 " // ...\n" 282 " return 1;\n" 283 " }\n" 284 "};"); 285 verifyFormat("this.someObject.doSomething(aaaaaaaaaaaaaaaaaaaaaaaaaa)\n" 286 " .then(goog.bind(function(aaaaaaaaaaa) {\n" 287 " someFunction();\n" 288 " someFunction();\n" 289 " }, this), aaaaaaaaaaaaaaaaa);"); 290 291 // FIXME: This is not ideal yet. 292 verifyFormat("someFunction(goog.bind(\n" 293 " function() {\n" 294 " doSomething();\n" 295 " doSomething();\n" 296 " },\n" 297 " this),\n" 298 " goog.bind(function() {\n" 299 " doSomething();\n" 300 " doSomething();\n" 301 " }, this));"); 302 } 303 304 TEST_F(FormatTestJS, InliningFunctionLiterals) { 305 FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); 306 Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; 307 verifyFormat("var func = function() {\n" 308 " return 1;\n" 309 "};", 310 Style); 311 verifyFormat("var func = doSomething(function() { return 1; });", Style); 312 verifyFormat("var outer = function() {\n" 313 " var inner = function() { return 1; }\n" 314 "};", 315 Style); 316 verifyFormat("function outer1(a, b) {\n" 317 " function inner1(a, b) { return a; }\n" 318 "}", 319 Style); 320 321 Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; 322 verifyFormat("var func = function() { return 1; };", Style); 323 verifyFormat("var func = doSomething(function() { return 1; });", Style); 324 verifyFormat( 325 "var outer = function() { var inner = function() { return 1; } };", 326 Style); 327 verifyFormat("function outer1(a, b) {\n" 328 " function inner1(a, b) { return a; }\n" 329 "}", 330 Style); 331 332 Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; 333 verifyFormat("var func = function() {\n" 334 " return 1;\n" 335 "};", 336 Style); 337 verifyFormat("var func = doSomething(function() {\n" 338 " return 1;\n" 339 "});", 340 Style); 341 verifyFormat("var outer = function() {\n" 342 " var inner = function() {\n" 343 " return 1;\n" 344 " }\n" 345 "};", 346 Style); 347 verifyFormat("function outer1(a, b) {\n" 348 " function inner1(a, b) {\n" 349 " return a;\n" 350 " }\n" 351 "}", 352 Style); 353 } 354 355 TEST_F(FormatTestJS, MultipleFunctionLiterals) { 356 verifyFormat("promise.then(\n" 357 " function success() {\n" 358 " doFoo();\n" 359 " doBar();\n" 360 " },\n" 361 " function error() {\n" 362 " doFoo();\n" 363 " doBaz();\n" 364 " },\n" 365 " []);\n"); 366 verifyFormat("promise.then(\n" 367 " function success() {\n" 368 " doFoo();\n" 369 " doBar();\n" 370 " },\n" 371 " [],\n" 372 " function error() {\n" 373 " doFoo();\n" 374 " doBaz();\n" 375 " });\n"); 376 // FIXME: Here, we should probably break right after the "(" for consistency. 377 verifyFormat("promise.then([],\n" 378 " function success() {\n" 379 " doFoo();\n" 380 " doBar();\n" 381 " },\n" 382 " function error() {\n" 383 " doFoo();\n" 384 " doBaz();\n" 385 " });\n"); 386 387 verifyFormat("getSomeLongPromise()\n" 388 " .then(function(value) { body(); })\n" 389 " .thenCatch(function(error) {\n" 390 " body();\n" 391 " body();\n" 392 " });"); 393 verifyFormat("getSomeLongPromise()\n" 394 " .then(function(value) {\n" 395 " body();\n" 396 " body();\n" 397 " })\n" 398 " .thenCatch(function(error) {\n" 399 " body();\n" 400 " body();\n" 401 " });"); 402 403 // FIXME: This is bad, but it used to be formatted correctly by accident. 404 verifyFormat("getSomeLongPromise().then(function(value) {\n" 405 " body();\n" 406 "}).thenCatch(function(error) { body(); });"); 407 } 408 409 TEST_F(FormatTestJS, ReturnStatements) { 410 verifyFormat("function() {\n" 411 " return [hello, world];\n" 412 "}"); 413 } 414 415 TEST_F(FormatTestJS, ClosureStyleComments) { 416 verifyFormat("var x = /** @type {foo} */ (bar);"); 417 } 418 419 TEST_F(FormatTestJS, TryCatch) { 420 verifyFormat("try {\n" 421 " f();\n" 422 "} catch (e) {\n" 423 " g();\n" 424 "} finally {\n" 425 " h();\n" 426 "}"); 427 428 // But, of course, "catch" is a perfectly fine function name in JavaScript. 429 verifyFormat("someObject.catch();"); 430 verifyFormat("someObject.new();"); 431 verifyFormat("someObject.delete();"); 432 } 433 434 TEST_F(FormatTestJS, StringLiteralConcatenation) { 435 verifyFormat("var literal = 'hello ' +\n" 436 " 'world';"); 437 } 438 439 TEST_F(FormatTestJS, RegexLiteralClassification) { 440 // Regex literals. 441 verifyFormat("var regex = /abc/;"); 442 verifyFormat("f(/abc/);"); 443 verifyFormat("f(abc, /abc/);"); 444 verifyFormat("some_map[/abc/];"); 445 verifyFormat("var x = a ? /abc/ : /abc/;"); 446 verifyFormat("for (var i = 0; /abc/.test(s[i]); i++) {\n}"); 447 verifyFormat("var x = !/abc/.test(y);"); 448 verifyFormat("var x = a && /abc/.test(y);"); 449 verifyFormat("var x = a || /abc/.test(y);"); 450 verifyFormat("var x = a + /abc/.search(y);"); 451 verifyFormat("var regexs = {/abc/, /abc/};"); 452 verifyFormat("return /abc/;"); 453 454 // Not regex literals. 455 verifyFormat("var a = a / 2 + b / 3;"); 456 } 457 458 TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) { 459 verifyFormat("var regex = /a*/;"); 460 verifyFormat("var regex = /a+/;"); 461 verifyFormat("var regex = /a?/;"); 462 verifyFormat("var regex = /.a./;"); 463 verifyFormat("var regex = /a\\*/;"); 464 verifyFormat("var regex = /^a$/;"); 465 verifyFormat("var regex = /\\/a/;"); 466 verifyFormat("var regex = /(?:x)/;"); 467 verifyFormat("var regex = /x(?=y)/;"); 468 verifyFormat("var regex = /x(?!y)/;"); 469 verifyFormat("var regex = /x|y/;"); 470 verifyFormat("var regex = /a{2}/;"); 471 verifyFormat("var regex = /a{1,3}/;"); 472 verifyFormat("var regex = /[abc]/;"); 473 verifyFormat("var regex = /[^abc]/;"); 474 verifyFormat("var regex = /[\\b]/;"); 475 verifyFormat("var regex = /\\b/;"); 476 verifyFormat("var regex = /\\B/;"); 477 verifyFormat("var regex = /\\d/;"); 478 verifyFormat("var regex = /\\D/;"); 479 verifyFormat("var regex = /\\f/;"); 480 verifyFormat("var regex = /\\n/;"); 481 verifyFormat("var regex = /\\r/;"); 482 verifyFormat("var regex = /\\s/;"); 483 verifyFormat("var regex = /\\S/;"); 484 verifyFormat("var regex = /\\t/;"); 485 verifyFormat("var regex = /\\v/;"); 486 verifyFormat("var regex = /\\w/;"); 487 verifyFormat("var regex = /\\W/;"); 488 verifyFormat("var regex = /a(a)\\1/;"); 489 verifyFormat("var regex = /\\0/;"); 490 verifyFormat("var regex = /\\\\/g;"); 491 verifyFormat("var regex = /\\a\\\\/g;"); 492 verifyFormat("var regex = /\a\\//g;"); 493 verifyFormat("var regex = /a\\//;\n" 494 "var x = 0;"); 495 EXPECT_EQ("var regex = /\\/*/;\n" 496 "var x = 0;", 497 format("var regex = /\\/*/;\n" 498 "var x=0;")); 499 } 500 501 TEST_F(FormatTestJS, RegexLiteralModifiers) { 502 verifyFormat("var regex = /abc/g;"); 503 verifyFormat("var regex = /abc/i;"); 504 verifyFormat("var regex = /abc/m;"); 505 verifyFormat("var regex = /abc/y;"); 506 } 507 508 TEST_F(FormatTestJS, RegexLiteralLength) { 509 verifyFormat("var regex = /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;", 510 getGoogleJSStyleWithColumns(60)); 511 verifyFormat("var regex =\n" 512 " /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;", 513 getGoogleJSStyleWithColumns(60)); 514 verifyFormat("var regex = /\\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;", 515 getGoogleJSStyleWithColumns(50)); 516 } 517 518 TEST_F(FormatTestJS, RegexLiteralExamples) { 519 verifyFormat("var regex = search.match(/(?:\?|&)times=([^?&]+)/i);"); 520 } 521 522 TEST_F(FormatTestJS, TypeAnnotations) { 523 verifyFormat("var x: string;"); 524 verifyFormat("function x(): string {\n return 'x';\n}"); 525 verifyFormat("function x(y: string): string {\n return 'x';\n}"); 526 verifyFormat("for (var y: string in x) {\n x();\n}"); 527 verifyFormat("((a: string, b: number): string => a + b);"); 528 verifyFormat("var x: (y: number) => string;"); 529 verifyFormat("var x: P<string, (a: number) => string>;"); 530 } 531 532 TEST_F(FormatTestJS, ClassDeclarations) { 533 verifyFormat("class C {\n x: string = 12;\n}"); 534 verifyFormat("class C {\n x(): string => 12;\n}"); 535 verifyFormat("class C {\n ['x' + 2]: string = 12;\n}"); 536 verifyFormat("class C {\n private x: string = 12;\n}"); 537 verifyFormat("class C {\n private static x: string = 12;\n}"); 538 verifyFormat("class C {\n static x(): string { return 'asd'; }\n}"); 539 verifyFormat("class C extends P implements I {}"); 540 } 541 542 TEST_F(FormatTestJS, MetadataAnnotations) { 543 verifyFormat("@A\nclass C {\n}"); 544 verifyFormat("@A({arg: 'value'})\nclass C {\n}"); 545 verifyFormat("@A\n@B\nclass C {\n}"); 546 verifyFormat("class C {\n @A x: string;\n}"); 547 verifyFormat("class C {\n" 548 " @A\n" 549 " private x(): string {\n" 550 " return 'y';\n" 551 " }\n" 552 "}"); 553 verifyFormat("class X {}\n" 554 "class Y {}"); 555 } 556 557 TEST_F(FormatTestJS, Modules) { 558 verifyFormat("import SomeThing from 'some/module.js';"); 559 verifyFormat("import {X, Y} from 'some/module.js';"); 560 verifyFormat("import {\n" 561 " VeryLongImportsAreAnnoying,\n" 562 " VeryLongImportsAreAnnoying,\n" 563 " VeryLongImportsAreAnnoying,\n" 564 " VeryLongImportsAreAnnoying\n" 565 "} from 'some/module.js';"); 566 verifyFormat("import {\n" 567 " X,\n" 568 " Y,\n" 569 "} from 'some/module.js';"); 570 verifyFormat("import {\n" 571 " X,\n" 572 " Y,\n" 573 "} from 'some/long/module.js';", 574 getGoogleJSStyleWithColumns(20)); 575 verifyFormat("import {X as myLocalX, Y as myLocalY} from 'some/module.js';"); 576 verifyFormat("import * as lib from 'some/module.js';"); 577 verifyFormat("var x = {import: 1};\nx.import = 2;"); 578 579 verifyFormat("export function fn() {\n" 580 " return 'fn';\n" 581 "}"); 582 verifyFormat("export const x = 12;"); 583 verifyFormat("export default class X {}"); 584 verifyFormat("export {X, Y} from 'some/module.js';"); 585 verifyFormat("export {\n" 586 " X,\n" 587 " Y,\n" 588 "} from 'some/module.js';"); 589 verifyFormat("export class C {\n" 590 " x: number;\n" 591 " y: string;\n" 592 "}"); 593 verifyFormat("export class X { y: number; }"); 594 verifyFormat("export default class X { y: number }"); 595 verifyFormat("export default function() {\n return 1;\n}"); 596 verifyFormat("export var x = 12;"); 597 verifyFormat("export var x: number = 12;"); 598 verifyFormat("export const y = {\n" 599 " a: 1,\n" 600 " b: 2\n" 601 "};"); 602 } 603 604 TEST_F(FormatTestJS, TemplateStrings) { 605 // Keeps any whitespace/indentation within the template string. 606 EXPECT_EQ("var x = `hello\n" 607 " ${ name }\n" 608 " !`;", 609 format("var x = `hello\n" 610 " ${ name }\n" 611 " !`;")); 612 613 // FIXME: +1 / -1 offsets are to work around clang-format miscalculating 614 // widths for unknown tokens that are not whitespace (e.g. '`'). Remove when 615 // the code is corrected. 616 617 verifyFormat("var x =\n" 618 " `hello ${world}` >= some();", 619 getGoogleJSStyleWithColumns(34)); // Barely doesn't fit. 620 verifyFormat("var x = `hello ${world}` >= some();", 621 getGoogleJSStyleWithColumns(35 + 1)); // Barely fits. 622 EXPECT_EQ("var x = `hello\n" 623 " ${world}` >=\n" 624 " some();", 625 format("var x =\n" 626 " `hello\n" 627 " ${world}` >= some();", 628 getGoogleJSStyleWithColumns(21))); // Barely doesn't fit. 629 EXPECT_EQ("var x = `hello\n" 630 " ${world}` >= some();", 631 format("var x =\n" 632 " `hello\n" 633 " ${world}` >= some();", 634 getGoogleJSStyleWithColumns(22))); // Barely fits. 635 636 verifyFormat("var x =\n `h`;", getGoogleJSStyleWithColumns(13 - 1)); 637 EXPECT_EQ( 638 "var x =\n `multi\n line`;", 639 format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(14 - 1))); 640 641 // Two template strings. 642 verifyFormat("var x = `hello` == `hello`;"); 643 } 644 645 TEST_F(FormatTestJS, CastSyntax) { 646 verifyFormat("var x = <type>foo;"); 647 } 648 649 TEST_F(FormatTestJS, TypeArguments) { 650 verifyFormat("class X<Y> {}"); 651 verifyFormat("new X<Y>();"); 652 verifyFormat("foo<Y>(a);"); 653 verifyFormat("var x: X<Y>[];"); 654 verifyFormat("class C extends D<E> implements F<G>, H<I> {}"); 655 } 656 657 } // end namespace tooling 658 } // end namespace clang 659