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

Side by Side Diff: tests/compiler/dart2js/dart_backend_test.dart

Issue 11345031: [dart2dart] Support cosntructor redirects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « tests/co19/co19-dart2dart.status ('k') | tests/language/language.status » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 'dart:uri'; 5 import 'dart:uri';
6 import 'parser_helper.dart'; 6 import 'parser_helper.dart';
7 import 'mock_compiler.dart'; 7 import 'mock_compiler.dart';
8 import '../../../lib/compiler/compiler.dart'; 8 import '../../../lib/compiler/compiler.dart';
9 import '../../../lib/compiler/implementation/dart2jslib.dart' as leg; 9 import '../../../lib/compiler/implementation/dart2jslib.dart' as leg;
10 import '../../../lib/compiler/implementation/dart_backend/dart_backend.dart'; 10 import '../../../lib/compiler/implementation/dart_backend/dart_backend.dart';
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 testGetSet() { 165 testGetSet() {
166 // Top-level get/set. 166 // Top-level get/set.
167 testDart2Dart('set foo(arg){}get foo{return 5;}main(){foo;foo=5;}'); 167 testDart2Dart('set foo(arg){}get foo{return 5;}main(){foo;foo=5;}');
168 // Field get/set. 168 // Field get/set.
169 testDart2Dart('main(){var a=new A();a.foo;a.foo=5;}' 169 testDart2Dart('main(){var a=new A();a.foo;a.foo=5;}'
170 'class A{set foo(a){}get foo{return 5;}}'); 170 'class A{set foo(a){}get foo{return 5;}}');
171 // Typed get/set. 171 // Typed get/set.
172 testDart2Dart('String get foo{return "a";}main(){foo;}'); 172 testDart2Dart('String get foo{return "a";}main(){foo;}');
173 } 173 }
174 174
175 testFactoryConstructor() {
176 testDart2Dart('main(){new A.fromFoo();}class A{A.fromFoo();}');
177 // Now more complicated, with normal constructor and factory parameters.
178 testDart2Dart('main(){new A.fromFoo(5);}'
179 'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}');
180 // Now even more complicated, with interface and default factory.
181 testDart2Dart('main(){new A.fromFoo(5);new I.fromFoo();}'
182 'class IFactory{factory I.fromFoo()=>new A(5);}'
183 'interface I default IFactory{I.fromFoo();}'
184 'class A implements I{A(this.f);A.fromFoo(foo):this("f");'
185 'final String f;}');
186 }
187
188 testAbstractClass() { 175 testAbstractClass() {
189 testDart2Dart('main(){A.foo;}abstract class A{final static num foo;}'); 176 testDart2Dart('main(){A.foo;}abstract class A{final static num foo;}');
190 } 177 }
191 178
192 testConflictSendsRename() { 179 testConflictSendsRename() {
193 // Various Send-s to current library and external library. Verify that 180 // Various Send-s to current library and external library. Verify that
194 // everything is renamed correctly in conflicting class names and global 181 // everything is renamed correctly in conflicting class names and global
195 // functions. 182 // functions.
196 var librarySrc = ''' 183 var librarySrc = '''
197 #library("mylib.dart"); 184 #library("mylib.dart");
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 interfaceElement.ensureResolved(compiler); 463 interfaceElement.ensureResolved(compiler);
477 PlaceholderCollector collector = 464 PlaceholderCollector collector =
478 collectPlaceholders(compiler, interfaceElement); 465 collectPlaceholders(compiler, interfaceElement);
479 ClassNode interfaceNode = interfaceElement.parseNode(compiler); 466 ClassNode interfaceNode = interfaceElement.parseNode(compiler);
480 Node defaultTypeNode = interfaceNode.defaultClause.typeName; 467 Node defaultTypeNode = interfaceNode.defaultClause.typeName;
481 ClassElement classElement = compiler.mainApp.find(buildSourceString('C')); 468 ClassElement classElement = compiler.mainApp.find(buildSourceString('C'));
482 // Check that 'C' in default clause of I gets into placeholders. 469 // Check that 'C' in default clause of I gets into placeholders.
483 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode)); 470 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode));
484 } 471 }
485 472
486 testFactoryRename() {
487 var librarySrc = '''
488 #library('mylib');
489
490 interface I default B { I(); }
491 class A implements I { A() {} }
492 class B { factory I() {} }
493
494 ''';
495 var mainSrc = '''
496 #import('mylib.dart', prefix: 'mylib');
497
498 interface I default B { I(); }
499 class A implements I { A() {} }
500 class B { factory I() {} }
501
502 main() {
503 new I();
504 new A();
505
506 new mylib.I();
507 new mylib.A();
508 }
509 ''';
510 var expectedResult =
511 'interface I default B{I();}'
512 'class A implements I{A(){}}'
513 'class B{factory I(){}}'
514 'interface p_I default p_B{p_I();}'
515 'class p_A implements p_I{p_A(){}}'
516 'class p_B{factory p_I(){}}'
517 'main(){new p_I();new p_A();new I();new A();}';
518 testDart2DartWithLibrary(mainSrc, librarySrc,
519 continuation: (String result) { Expect.equals(expectedResult, result); });
520 }
521
522 testTypeVariablesAreRenamed() { 473 testTypeVariablesAreRenamed() {
523 // Somewhat a hack: we require all the references of the identifier 474 // Somewhat a hack: we require all the references of the identifier
524 // to be renamed in the same way for the whole library. Hence 475 // to be renamed in the same way for the whole library. Hence
525 // if we have a class and type variable with the same name, they 476 // if we have a class and type variable with the same name, they
526 // both should be renamed. 477 // both should be renamed.
527 var librarySrc = ''' 478 var librarySrc = '''
528 #library('mylib'); 479 #library('mylib');
529 typedef void MyFunction<T extends num>(T arg); 480 typedef void MyFunction<T extends num>(T arg);
530 class T {} 481 class T {}
531 class B<T> {} 482 class B<T> {}
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 mylib.main(); 554 mylib.main();
604 } 555 }
605 '''; 556 ''';
606 var expectedResult = 557 var expectedResult =
607 'p_main(){}' 558 'p_main(){}'
608 'main(){p_main();}'; 559 'main(){p_main();}';
609 testDart2DartWithLibrary(mainSrc, librarySrc, 560 testDart2DartWithLibrary(mainSrc, librarySrc,
610 continuation: (String result) { Expect.equals(expectedResult, result); }); 561 continuation: (String result) { Expect.equals(expectedResult, result); });
611 } 562 }
612 563
613 testInterfaceDefaultAnotherLib() {
614 var librarySrc = '''
615 #library('mylib');
616 class C<T> {
617 factory I() {}
618 }
619 ''';
620 var mainSrc = '''
621 #import('mylib.dart', prefix: 'mylib');
622
623 interface I<T> default mylib.C<T> {
624 I();
625 }
626
627 main() {
628 new I();
629 }
630 ''';
631 var expectedResult =
632 'class C<T>{factory I(){}}'
633 'interface I<T> default C<T>{I();}'
634 'main(){new I();}';
635 testDart2DartWithLibrary(mainSrc, librarySrc,
636 continuation: (String result) { Expect.equals(expectedResult, result); });
637 }
638
639 testStaticAccessIoLib() { 564 testStaticAccessIoLib() {
640 var src = ''' 565 var src = '''
641 #import('dart:io'); 566 #import('dart:io');
642 567
643 main() { 568 main() {
644 Platform.operatingSystem; 569 Platform.operatingSystem;
645 } 570 }
646 '''; 571 ''';
647 var expectedResult = 'import "dart:io" as p;' 572 var expectedResult = 'import "dart:io" as p;'
648 'main(){p.Platform.operatingSystem;}'; 573 'main(){p.Platform.operatingSystem;}';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 fooglobal(8); 628 fooglobal(8);
704 } 629 }
705 '''; 630 ''';
706 var expectedResult = 631 var expectedResult =
707 'class B{var E;static C(A){A=5;}}D(A,[optionalarg=7]){A=6;}' 632 'class B{var E;static C(A){A=5;}}D(A,[optionalarg=7]){A=6;}'
708 'main(){new B().E;B.C(8);D(8);}'; 633 'main(){new B().E;B.C(8);D(8);}';
709 testDart2Dart(src, continuation: 634 testDart2Dart(src, continuation:
710 (String result) { Expect.equals(expectedResult, result); }, minify: true); 635 (String result) { Expect.equals(expectedResult, result); }, minify: true);
711 } 636 }
712 637
713 testTypeVariablesInDifferentLibraries() {
714 // This is a simplified version of what we have in
715 // lib/compiler/implementation/util.
716 var librarySrc = '''
717 #library('mylib');
718 #import('script.dart');
719 interface Iterable<K> {}
720
721 interface Link<T> extends Iterable<T> default LinkFactory<T> {
722 Link();
723 }
724 ''';
725 var mainSrc = '''
726 #library('script.dart');
727 #import('mylib.dart');
728
729 class LinkFactory<T> {
730 factory Link() {}
731 }
732
733 main() {
734 new Link<int>();
735 }
736 ''';
737 var expectedResult =
738 'interface Iterable<K>{}'
739 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}'
740 'class LinkFactory<T>{factory Link(){}}'
741 'main(){new Link<int>();}';
742 testDart2DartWithLibrary(mainSrc, librarySrc,
743 continuation: (String result) { Expect.equals(expectedResult, result); });
744 }
745
746 testDeclarationTypePlaceholders() { 638 testDeclarationTypePlaceholders() {
747 var src = ''' 639 var src = '''
748 String globalfield; 640 String globalfield;
749 const String globalconstfield; 641 const String globalconstfield;
750 642
751 void foo(String arg) {} 643 void foo(String arg) {}
752 644
753 main() { 645 main() {
754 String localvar; 646 String localvar;
755 foo("5"); 647 foo("5");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 692
801 main() { 693 main() {
802 testSimpleFileUnparse(); 694 testSimpleFileUnparse();
803 testTopLevelField(); 695 testTopLevelField();
804 testSimpleTopLevelClass(); 696 testSimpleTopLevelClass();
805 testClassWithSynthesizedConstructor(); 697 testClassWithSynthesizedConstructor();
806 testClassWithMethod(); 698 testClassWithMethod();
807 testExtendsImplements(); 699 testExtendsImplements();
808 testVariableDefinitions(); 700 testVariableDefinitions();
809 testGetSet(); 701 testGetSet();
810 testFactoryConstructor();
811 testAbstractClass(); 702 testAbstractClass();
812 testConflictSendsRename(); 703 testConflictSendsRename();
813 testNoConflictSendsRename(); 704 testNoConflictSendsRename();
814 testConflictLibraryClassRename(); 705 testConflictLibraryClassRename();
815 testDefaultClassWithArgs(); 706 testDefaultClassWithArgs();
816 testClassExtendsWithArgs(); 707 testClassExtendsWithArgs();
817 testStaticInvocation(); 708 testStaticInvocation();
818 testLibraryGetSet(); 709 testLibraryGetSet();
819 testFieldTypeOutput(); 710 testFieldTypeOutput();
820 testDefaultClassNamePlaceholder(); 711 testDefaultClassNamePlaceholder();
821 testFactoryRename();
822 testTypeVariablesAreRenamed(); 712 testTypeVariablesAreRenamed();
823 testClassTypeArgumentBound(); 713 testClassTypeArgumentBound();
824 testDoubleMains(); 714 testDoubleMains();
825 testInterfaceDefaultAnotherLib();
826 testStaticAccessIoLib(); 715 testStaticAccessIoLib();
827 testLocalFunctionPlaceholder(); 716 testLocalFunctionPlaceholder();
828 testMinification(); 717 testMinification();
829 testClosureLocalsMinified(); 718 testClosureLocalsMinified();
830 testParametersMinified(); 719 testParametersMinified();
831 testTypeVariablesInDifferentLibraries();
832 testDeclarationTypePlaceholders(); 720 testDeclarationTypePlaceholders();
833 testPlatformLibraryMemberNamesAreFixed(); 721 testPlatformLibraryMemberNamesAreFixed();
834 testConflictsWithCoreLib(); 722 testConflictsWithCoreLib();
835 } 723 }
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2dart.status ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698