Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(880)

Side by Side Diff: pkg/analyzer_experimental/test/services/formatter_test.dart

Issue 26280005: Formatter code transform bit-flip support. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 'int x;\n' 534 'int x;\n'
535 ); 535 );
536 }); 536 });
537 537
538 test('CU - EOF nl', () { 538 test('CU - EOF nl', () {
539 expectCUFormatsTo( 539 expectCUFormatsTo(
540 'var x = 1;', 540 'var x = 1;',
541 'var x = 1;\n' 541 'var x = 1;\n'
542 ); 542 );
543 }); 543 });
544 544
545 test('CU - constructor', () { 545 test('CU - constructor', () {
546 expectCUFormatsTo( 546 expectCUFormatsTo(
547 'class A {\n' 547 'class A {\n'
548 ' const _a;\n' 548 ' const _a;\n'
549 ' A();\n' 549 ' A();\n'
550 ' int a() => _a;\n' 550 ' int a() => _a;\n'
551 '}\n', 551 '}\n',
552 'class A {\n' 552 'class A {\n'
553 ' const _a;\n' 553 ' const _a;\n'
554 ' A();\n' 554 ' A();\n'
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 '}\n' 616 '}\n'
617 ); 617 );
618 }); 618 });
619 619
620 test('CU - parts', () { 620 test('CU - parts', () {
621 expectCUFormatsTo( 621 expectCUFormatsTo(
622 'part of foo;', 622 'part of foo;',
623 'part of foo;\n' 623 'part of foo;\n'
624 ); 624 );
625 }); 625 });
626 626
627 test('CU (cons inits)', () { 627 test('CU (cons inits)', () {
628 expectCUFormatsTo('class X {\n' 628 expectCUFormatsTo('class X {\n'
629 ' var x, y;\n' 629 ' var x, y;\n'
630 ' X() : x = 1, y = 2;\n' 630 ' X() : x = 1, y = 2;\n'
631 '}\n', 631 '}\n',
632 'class X {\n' 632 'class X {\n'
633 ' var x, y;\n' 633 ' var x, y;\n'
634 ' X()\n' 634 ' X()\n'
635 ' : x = 1,\n' 635 ' : x = 1,\n'
636 ' y = 2;\n' 636 ' y = 2;\n'
637 '}\n' 637 '}\n'
638 ); 638 );
639 }); 639 });
640 640
641 test('stmt', () { 641 test('stmt', () {
642 expectStmtFormatsTo( 642 expectStmtFormatsTo(
643 'if (true){\n' 643 'if (true){\n'
644 'if (true){\n' 644 'if (true){\n'
645 'if (true){\n' 645 'if (true){\n'
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 '}' 685 '}'
686 ); 686 );
687 }); 687 });
688 688
689 test('stmt (generics)', () { 689 test('stmt (generics)', () {
690 expectStmtFormatsTo( 690 expectStmtFormatsTo(
691 'var numbers = <int>[1, 2, (3 + 4)];', 691 'var numbers = <int>[1, 2, (3 + 4)];',
692 'var numbers = <int>[1, 2, (3 + 4)];' 692 'var numbers = <int>[1, 2, (3 + 4)];'
693 ); 693 );
694 }); 694 });
695 695
696 test('stmt (lists)', () { 696 test('stmt (lists)', () {
697 expectStmtFormatsTo( 697 expectStmtFormatsTo(
698 'var l = [1,2,3,4];', 698 'var l = [1,2,3,4];',
699 'var l = [1, 2, 3, 4];' 699 'var l = [1, 2, 3, 4];'
700 ); 700 );
701 //Dangling ',' 701 //Dangling ','
702 expectStmtFormatsTo( 702 expectStmtFormatsTo(
703 'var l = [1,];', 703 'var l = [1,];',
704 'var l = [1,];' 704 'var l = [1,];'
705 ); 705 );
706 }); 706 });
707 707
708 test('stmt (maps)', () { 708 test('stmt (maps)', () {
709 expectStmtFormatsTo( 709 expectStmtFormatsTo(
710 'var map = const {"foo": "bar", "fuz": null};', 710 'var map = const {"foo": "bar", "fuz": null};',
711 'var map = const {"foo": "bar", "fuz": null};' 711 'var map = const {"foo": "bar", "fuz": null};'
712 ); 712 );
713 713
714 //Dangling ',' 714 //Dangling ','
715 expectStmtFormatsTo( 715 expectStmtFormatsTo(
716 'var map = {"foo": "bar",};', 716 'var map = {"foo": "bar",};',
717 'var map = {"foo": "bar",};' 717 'var map = {"foo": "bar",};'
718 ); 718 );
719 }); 719 });
720 720
721 test('stmt (try/catch)', () { 721 test('stmt (try/catch)', () {
722 expectStmtFormatsTo( 722 expectStmtFormatsTo(
723 'try {\n' 723 'try {\n'
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 ); 771 );
772 expectStmtFormatsTo( 772 expectStmtFormatsTo(
773 'for (final foo in bar.foos) {\n' 773 'for (final foo in bar.foos) {\n'
774 ' print(foo);\n' 774 ' print(foo);\n'
775 '}', 775 '}',
776 'for (final foo in bar.foos) {\n' 776 'for (final foo in bar.foos) {\n'
777 ' print(foo);\n' 777 ' print(foo);\n'
778 '}' 778 '}'
779 ); 779 );
780 }); 780 });
781 781
782 test('Statement (if)', () { 782 test('Statement (if)', () {
783 expectStmtFormatsTo('if (true) print("true!");', 783 expectStmtFormatsTo('if (true) print("true!");',
784 'if (true) print("true!");'); 784 'if (true) print("true!");');
785 expectStmtFormatsTo('if (true) { print("true!"); }', 785 expectStmtFormatsTo('if (true) { print("true!"); }',
786 'if (true) {\n' 786 'if (true) {\n'
787 ' print("true!");\n' 787 ' print("true!");\n'
788 '}'); 788 '}');
789 expectStmtFormatsTo('if (true) print("true!"); else print("false!");', 789 expectStmtFormatsTo('if (true) print("true!"); else print("false!");',
790 'if (true) {\n' 790 'if (true) {\n'
791 ' print("true!");\n' 791 ' print("true!");\n'
792 '} else {\n' 792 '} else {\n'
793 ' print("false!");\n' 793 ' print("false!");\n'
794 '}'); 794 '}');
795 }); 795 expectStmtFormatsTo('if (true) print("true!"); else print("false!");',
Brian Wilkerson 2013/10/07 21:37:29 I expect you'll want to test the "transforms: true
pquitslund 2013/10/07 22:33:44 The expect above actually does that. I like your
796 'if (true) print("true!"); else print("false!");',
797 transforms: false);
798 });
796 799
797 test('initialIndent', () { 800 test('initialIndent', () {
798 var formatter = new CodeFormatter( 801 var formatter = new CodeFormatter(
799 new FormatterOptions(initialIndentationLevel: 2)); 802 new FormatterOptions(initialIndentationLevel: 2));
800 var formattedSource = 803 var formattedSource =
801 formatter.format(CodeKind.STATEMENT, 'var x;').source; 804 formatter.format(CodeKind.STATEMENT, 'var x;').source;
802 expect(formattedSource, startsWith(' ')); 805 expect(formattedSource, startsWith(' '));
803 }); 806 });
804 807
805 test('selections', () { 808 test('selections', () {
806 expectSelectedPostFormat('class X {}', '}'); 809 expectSelectedPostFormat('class X {}', '}');
807 expectSelectedPostFormat('class X{}', '{'); 810 expectSelectedPostFormat('class X{}', '{');
808 expectSelectedPostFormat('class X{int y;}', ';'); 811 expectSelectedPostFormat('class X{int y;}', ';');
809 expectSelectedPostFormat('class X{int y;}', '}'); 812 expectSelectedPostFormat('class X{int y;}', '}');
810 expectSelectedPostFormat('class X {}', ' {'); 813 expectSelectedPostFormat('class X {}', ' {');
811 }); 814 });
812 815
813 }); 816 });
814 817
815 818
816 /// Token streams 819 /// Token streams
817 group('token streams', () { 820 group('token streams', () {
818 821
819 test('string tokens', () { 822 test('string tokens', () {
820 expectTokenizedEqual('class A{}', 'class A{ }'); 823 expectTokenizedEqual('class A{}', 'class A{ }');
821 expectTokenizedEqual('class A{}', 'class A{\n }\n'); 824 expectTokenizedEqual('class A{}', 'class A{\n }\n');
822 expectTokenizedEqual('class A {}', 'class A{ }'); 825 expectTokenizedEqual('class A {}', 'class A{ }');
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 expect(()=> expectStreamsEqual(tokenize(s1), tokenize(s2)), 1021 expect(()=> expectStreamsEqual(tokenize(s1), tokenize(s2)),
1019 throwsA(new isInstanceOf<FormatterException>())); 1022 throwsA(new isInstanceOf<FormatterException>()));
1020 1023
1021 expectStreamsEqual(Token t1, Token t2) => 1024 expectStreamsEqual(Token t1, Token t2) =>
1022 new TokenStreamComparator(null, t1, t2).verifyEquals(); 1025 new TokenStreamComparator(null, t1, t2).verifyEquals();
1023 1026
1024 expectStreamsNotEqual(Token t1, Token t2) => 1027 expectStreamsNotEqual(Token t1, Token t2) =>
1025 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(), 1028 expect(() => new TokenStreamComparator(null, t1, t2).verifyEquals(),
1026 throwsA(new isInstanceOf<FormatterException>())); 1029 throwsA(new isInstanceOf<FormatterException>()));
1027 1030
1028 expectCUFormatsTo(src, expected) => 1031 expectCUFormatsTo(src, expected) =>
1029 expect(formatCU(src).source, equals(expected)); 1032 expect(formatCU(src).source, equals(expected));
1030 1033
1031 expectStmtFormatsTo(src, expected) => 1034 expectStmtFormatsTo(src, expected, {transforms: true}) =>
1032 expect(formatStatement(src), equals(expected)); 1035 expect(formatStatement(src, options:
1036 new FormatterOptions(codeTransforms: transforms)), equals(expected));
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/services/formatter_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698