| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
| 6 | 6 |
| 7 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 7 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; | 8 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; |
| 9 import 'package:analyzer_experimental/src/services/writer.dart'; | 9 import 'package:analyzer_experimental/src/services/writer.dart'; |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 test('CU - EOL comments', () { | 71 test('CU - EOL comments', () { |
| 72 expectCUFormatsTo( | 72 expectCUFormatsTo( |
| 73 '//comment one\n\n' | 73 '//comment one\n\n' |
| 74 '//comment two\n\n', | 74 '//comment two\n\n', |
| 75 '//comment one\n\n' | 75 '//comment one\n\n' |
| 76 '//comment two\n\n' | 76 '//comment two\n\n' |
| 77 ); | 77 ); |
| 78 expectCUFormatsTo( | 78 expectCUFormatsTo( |
| 79 'var x; //x\n', |
| 80 'var x; //x\n' |
| 81 ); |
| 82 expectCUFormatsTo( |
| 79 'library foo;\n' | 83 'library foo;\n' |
| 80 '\n' | 84 '\n' |
| 81 '//comment one\n' | 85 '//comment one\n' |
| 82 '\n' | 86 '\n' |
| 83 'class C {\n' | 87 'class C {\n' |
| 84 '}\n', | 88 '}\n', |
| 85 'library foo;\n' | 89 'library foo;\n' |
| 86 '\n' | 90 '\n' |
| 87 '//comment one\n' | 91 '//comment one\n' |
| 88 '\n' | 92 '\n' |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 }); | 326 }); |
| 323 | 327 |
| 324 test('CU - Block comments', () { | 328 test('CU - Block comments', () { |
| 325 expectCUFormatsTo( | 329 expectCUFormatsTo( |
| 326 '/** Old school class comment */\n' | 330 '/** Old school class comment */\n' |
| 327 'class C {\n' | 331 'class C {\n' |
| 328 ' /** Foo! */ int foo() => 42;\n' | 332 ' /** Foo! */ int foo() => 42;\n' |
| 329 '}\n', | 333 '}\n', |
| 330 '/** Old school class comment */\n' | 334 '/** Old school class comment */\n' |
| 331 'class C {\n' | 335 'class C {\n' |
| 332 ' /** Foo! */ int foo() => 42;\n' | 336 ' /** Foo! */\n' |
| 337 ' int foo() => 42;\n' |
| 333 '}\n' | 338 '}\n' |
| 334 ); | 339 ); |
| 335 expectCUFormatsTo( | 340 expectCUFormatsTo( |
| 336 'library foo;\n' | 341 'library foo;\n' |
| 337 'class C /* is cool */ {\n' | 342 'class C /* is cool */ {\n' |
| 338 ' /* int */ foo() => 42;\n' | 343 ' /* int */ foo() => 42;\n' |
| 339 '}\n', | 344 '}\n', |
| 340 'library foo;\n' | 345 'library foo;\n' |
| 341 'class C /* is cool */ {\n' | 346 'class C /* is cool */ {\n' |
| 342 ' /* int */ foo() => 42;\n' | 347 ' /* int */ foo() => 42;\n' |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 '/// Copyright info\n' | 404 '/// Copyright info\n' |
| 400 '\n' | 405 '\n' |
| 401 'library foo;\n' | 406 'library foo;\n' |
| 402 '/// Class comment\n' | 407 '/// Class comment\n' |
| 403 '//TODO: implement\n' | 408 '//TODO: implement\n' |
| 404 'class C {\n' | 409 'class C {\n' |
| 405 '}\n' | 410 '}\n' |
| 406 ); | 411 ); |
| 407 }); | 412 }); |
| 408 | 413 |
| 414 test('CU - mixed comments', () { |
| 415 expectCUFormatsTo( |
| 416 'library foo;\n' |
| 417 '\n' |
| 418 '\n' |
| 419 '/* Comment 1 */\n' |
| 420 '\n' |
| 421 '// Comment 2\n' |
| 422 '\n' |
| 423 '/* Comment 3 */', |
| 424 'library foo;\n' |
| 425 '\n' |
| 426 '\n' |
| 427 '/* Comment 1 */\n' |
| 428 '\n' |
| 429 '// Comment 2\n' |
| 430 '\n' |
| 431 '/* Comment 3 */' |
| 432 ); |
| 433 }); |
| 434 |
| 435 test('CU - comments (EOF)', () { |
| 436 expectCUFormatsTo( |
| 437 'library foo; //zamm', |
| 438 'library foo; //zamm\n' //<-- note extra NEWLINE |
| 439 ); |
| 440 }); |
| 441 |
| 442 test('CU - comments (0)', () { |
| 443 expectCUFormatsTo( |
| 444 'library foo; //zamm\n' |
| 445 '\n' |
| 446 'class A {\n' |
| 447 '}\n', |
| 448 'library foo; //zamm\n' |
| 449 '\n' |
| 450 'class A {\n' |
| 451 '}\n' |
| 452 ); |
| 453 }); |
| 454 |
| 455 test('CU - comments (1)', () { |
| 456 expectCUFormatsTo( |
| 457 '/* foo */ /* bar */\n', |
| 458 '/* foo */ /* bar */\n' |
| 459 ); |
| 460 }); |
| 461 |
| 462 test('CU - comments (2)', () { |
| 463 expectCUFormatsTo( |
| 464 '/** foo */ /** bar */\n', |
| 465 '/** foo */\n' |
| 466 '/** bar */\n' |
| 467 ); |
| 468 }); |
| 469 |
| 470 test('CU - comments (3)', () { |
| 471 expectCUFormatsTo( |
| 472 'var x; //x\n', |
| 473 'var x; //x\n' |
| 474 ); |
| 475 }); |
| 476 |
| 477 test('CU - comments (4)', () { |
| 478 expectCUFormatsTo( |
| 479 'class X { //X!\n' |
| 480 '}', |
| 481 'class X { //X!\n' |
| 482 '}' |
| 483 ); |
| 484 }); |
| 485 |
| 486 test('CU - comments (5)', () { |
| 487 expectCUFormatsTo( |
| 488 '//comment one\n\n' |
| 489 '//comment two\n\n', |
| 490 '//comment one\n\n' |
| 491 '//comment two\n\n' |
| 492 ); |
| 493 }); |
| 494 |
| 495 test('CU - comments (6)', () { |
| 496 expectCUFormatsTo( |
| 497 'var x; //x\n', |
| 498 'var x; //x\n' |
| 499 ); |
| 500 }); |
| 501 |
| 502 test('CU - comments (6)', () { |
| 503 expectCUFormatsTo( |
| 504 'var /* int */ x; //x\n', |
| 505 'var /* int */ x; //x\n' |
| 506 ); |
| 507 }); |
| 508 |
| 509 test('CU - comments (7)', () { |
| 510 expectCUFormatsTo( |
| 511 'library foo;\n' |
| 512 '\n' |
| 513 '/// Docs\n' |
| 514 '/// spanning\n' |
| 515 '/// lines.\n' |
| 516 'class A {\n' |
| 517 '}\n' |
| 518 '\n' |
| 519 '/// ... and\n' |
| 520 '\n' |
| 521 '/// Dangling ones too\n' |
| 522 'int x;\n', |
| 523 'library foo;\n' |
| 524 '\n' |
| 525 '/// Docs\n' |
| 526 '/// spanning\n' |
| 527 '/// lines.\n' |
| 528 'class A {\n' |
| 529 '}\n' |
| 530 '\n' |
| 531 '/// ... and\n' |
| 532 '\n' |
| 533 '/// Dangling ones too\n' |
| 534 'int x;\n' |
| 535 ); |
| 536 }); |
| 537 |
| 409 | 538 |
| 410 test('CU - constructor', () { | 539 test('CU - constructor', () { |
| 411 expectCUFormatsTo( | 540 expectCUFormatsTo( |
| 412 'class A {\n' | 541 'class A {\n' |
| 413 ' const _a;\n' | 542 ' const _a;\n' |
| 414 ' A();\n' | 543 ' A();\n' |
| 415 ' int a() => _a;\n' | 544 ' int a() => _a;\n' |
| 416 '}\n', | 545 '}\n', |
| 417 'class A {\n' | 546 'class A {\n' |
| 418 ' const _a;\n' | 547 ' const _a;\n' |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 String formatCU(src, {options: const FormatterOptions()}) => | 875 String formatCU(src, {options: const FormatterOptions()}) => |
| 747 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 876 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); |
| 748 | 877 |
| 749 String formatStatement(src, {options: const FormatterOptions()}) => | 878 String formatStatement(src, {options: const FormatterOptions()}) => |
| 750 new CodeFormatter(options).format(CodeKind.STATEMENT, src); | 879 new CodeFormatter(options).format(CodeKind.STATEMENT, src); |
| 751 | 880 |
| 752 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); | 881 expectCUFormatsTo(src, expected) => expect(formatCU(src), equals(expected)); |
| 753 | 882 |
| 754 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), | 883 expectStmtFormatsTo(src, expected) => expect(formatStatement(src), |
| 755 equals(expected)); | 884 equals(expected)); |
| OLD | NEW |