OLD | NEW |
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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:uri'; | 7 import 'dart:uri'; |
8 import 'parser_helper.dart'; | 8 import 'parser_helper.dart'; |
9 import 'mock_compiler.dart'; | 9 import 'mock_compiler.dart'; |
10 import '../../../sdk/lib/_internal/compiler/compiler.dart'; | 10 import '../../../sdk/lib/_internal/compiler/compiler.dart'; |
11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l
eg; | 11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' as l
eg; |
12 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac
kend.dart'; | 12 import '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_bac
kend.dart'; |
13 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t'; |
14 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
15 | 15 |
16 const coreLib = r''' | 16 const coreLib = r''' |
17 library corelib; | 17 library corelib; |
18 class Object {} | 18 class Object {} |
19 interface bool {} | 19 class bool {} |
20 interface num {} | 20 class num {} |
21 interface int extends num {} | 21 class int extends num {} |
22 interface double extends num {} | 22 class double extends num {} |
23 abstract class String {} | 23 abstract class String {} |
24 interface Function {} | 24 class Function {} |
25 interface List<T> {} | 25 class List<T> {} |
26 interface Map<K,V> {} | 26 class Map<K,V> {} |
27 interface Closure {} | 27 class Closure {} |
28 interface Dynamic_ {} | 28 class Dynamic_ {} |
29 interface Null {} | 29 class Null {} |
30 interface TypeError {} | 30 class TypeError {} |
31 class Type {} | 31 class Type {} |
32 class LinkedHashMap {} | 32 class LinkedHashMap {} |
33 class Math { | 33 class Math { |
34 static double parseDouble(String s) => 1.0; | 34 static double parseDouble(String s) => 1.0; |
35 } | 35 } |
36 print(x) {} | 36 print(x) {} |
37 identical(a, b) => true; | 37 identical(a, b) => true; |
38 '''; | 38 '''; |
39 | 39 |
40 const ioLib = r''' | 40 const ioLib = r''' |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 'class A{foo(){}}' | 379 'class A{foo(){}}' |
380 'p_topfoo(){var x=5;}' | 380 'p_topfoo(){var x=5;}' |
381 'class p_A{num foo(){}p_A.fromFoo(){}A myliba;List<p_A> mylist;}' | 381 'class p_A{num foo(){}p_A.fromFoo(){}A myliba;List<p_A> mylist;}' |
382 'A getA()=>null;' | 382 'A getA()=>null;' |
383 'main(){var a=new A();a.foo();var b=new p_A.fromFoo();b.foo();' | 383 'main(){var a=new A();a.foo();var b=new p_A.fromFoo();b.foo();' |
384 'var GREATVAR=b.myliba;b.mylist;a=getA();p_topfoo();topfoo();}'; | 384 'var GREATVAR=b.myliba;b.mylist;a=getA();p_topfoo();topfoo();}'; |
385 testDart2DartWithLibrary(mainSrc, librarySrc, | 385 testDart2DartWithLibrary(mainSrc, librarySrc, |
386 continuation: (String result) { Expect.equals(expectedResult, result); }); | 386 continuation: (String result) { Expect.equals(expectedResult, result); }); |
387 } | 387 } |
388 | 388 |
389 testDefaultClassWithArgs() { | |
390 testDart2Dart('main(){var result=new IA<String>();}' | |
391 'interface IA<T> default A<T extends Object>{IA();}' | |
392 'class A<T extends Object> implements IA<T>{factory A(){}}'); | |
393 } | |
394 | |
395 testClassExtendsWithArgs() { | 389 testClassExtendsWithArgs() { |
396 testDart2Dart('main(){new B<Object>();}' | 390 testDart2Dart('main(){new B<Object>();}' |
397 'class A<T extends Object>{}' | 391 'class A<T extends Object>{}' |
398 'class B<T extends Object> extends A<T>{}'); | 392 'class B<T extends Object> extends A<T>{}'); |
399 } | 393 } |
400 | 394 |
401 testStaticInvocation() { | 395 testStaticInvocation() { |
402 testDart2Dart('main(){var x=Math.parseDouble("1");}'); | 396 testDart2Dart('main(){var x=Math.parseDouble("1");}'); |
403 } | 397 } |
404 | 398 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); | 456 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); |
463 compiler.processQueue(compiler.enqueuer.resolution, mainElement); | 457 compiler.processQueue(compiler.enqueuer.resolution, mainElement); |
464 PlaceholderCollector collector = collectPlaceholders(compiler, mainElement); | 458 PlaceholderCollector collector = collectPlaceholders(compiler, mainElement); |
465 FunctionExpression mainNode = mainElement.parseNode(compiler); | 459 FunctionExpression mainNode = mainElement.parseNode(compiler); |
466 FunctionExpression fooNode = mainNode.body.statements.nodes.head.function; | 460 FunctionExpression fooNode = mainNode.body.statements.nodes.head.function; |
467 LocalPlaceholder fooPlaceholder = | 461 LocalPlaceholder fooPlaceholder = |
468 collector.functionScopes[mainElement].localPlaceholders.first; | 462 collector.functionScopes[mainElement].localPlaceholders.first; |
469 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); | 463 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); |
470 } | 464 } |
471 | 465 |
472 testDefaultClassNamePlaceholder() { | |
473 var src = ''' | |
474 interface I default C{ | |
475 I(); | |
476 } | |
477 | |
478 class C { | |
479 I() {} | |
480 } | |
481 | |
482 main() { | |
483 new I(); | |
484 } | |
485 '''; | |
486 MockCompiler compiler = new MockCompiler(); | |
487 compiler.parseScript(src); | |
488 ClassElement interfaceElement = compiler.mainApp.find(buildSourceString('I')); | |
489 interfaceElement.ensureResolved(compiler); | |
490 PlaceholderCollector collector = | |
491 collectPlaceholders(compiler, interfaceElement); | |
492 ClassNode interfaceNode = interfaceElement.parseNode(compiler); | |
493 Node defaultTypeNode = interfaceNode.defaultClause.typeName; | |
494 ClassElement classElement = compiler.mainApp.find(buildSourceString('C')); | |
495 // Check that 'C' in default clause of I gets into placeholders. | |
496 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode)); | |
497 } | |
498 | |
499 testTypeVariablesAreRenamed() { | 466 testTypeVariablesAreRenamed() { |
500 // Somewhat a hack: we require all the references of the identifier | 467 // Somewhat a hack: we require all the references of the identifier |
501 // to be renamed in the same way for the whole library. Hence | 468 // to be renamed in the same way for the whole library. Hence |
502 // if we have a class and type variable with the same name, they | 469 // if we have a class and type variable with the same name, they |
503 // both should be renamed. | 470 // both should be renamed. |
504 var librarySrc = ''' | 471 var librarySrc = ''' |
505 library mylib; | 472 library mylib; |
506 typedef void MyFunction<T extends num>(T arg); | 473 typedef void MyFunction<T extends num>(T arg); |
507 class T {} | 474 class T {} |
508 class B<T> {} | 475 class B<T> {} |
(...skipping 28 matching lines...) Expand all Loading... |
537 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;' | 504 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;' |
538 'new p_T();new A<int>().f;new T();}'; | 505 'new p_T();new A<int>().f;new T();}'; |
539 testDart2DartWithLibrary(mainSrc, librarySrc, | 506 testDart2DartWithLibrary(mainSrc, librarySrc, |
540 continuation: (String result) { Expect.equals(expectedResult, result); }); | 507 continuation: (String result) { Expect.equals(expectedResult, result); }); |
541 } | 508 } |
542 | 509 |
543 testClassTypeArgumentBound() { | 510 testClassTypeArgumentBound() { |
544 var librarySrc = ''' | 511 var librarySrc = ''' |
545 library mylib; | 512 library mylib; |
546 | 513 |
547 interface I {} | 514 class I {} |
548 class A<T extends I> {} | 515 class A<T extends I> {} |
549 | 516 |
550 '''; | 517 '''; |
551 var mainSrc = ''' | 518 var mainSrc = ''' |
552 import 'mylib.dart' as mylib; | 519 import 'mylib.dart' as mylib; |
553 | 520 |
554 interface I {} | 521 class I {} |
555 class A<T extends I> {} | 522 class A<T extends I> {} |
556 | 523 |
557 main() { | 524 main() { |
558 new A(); | 525 new A(); |
559 new mylib.A(); | 526 new mylib.A(); |
560 } | 527 } |
561 '''; | 528 '''; |
562 var expectedResult = | 529 var expectedResult = |
563 'interface I{}' | 530 'class I{}' |
564 'class A<T extends I>{}' | 531 'class A<T extends I>{}' |
565 'interface p_I{}' | 532 'class p_I{}' |
566 'class p_A<p_T extends p_I>{}' | 533 'class p_A<p_T extends p_I>{}' |
567 'main(){new p_A();new A();}'; | 534 'main(){new p_A();new A();}'; |
568 testDart2DartWithLibrary(mainSrc, librarySrc, | 535 testDart2DartWithLibrary(mainSrc, librarySrc, |
569 continuation: (String result) { Expect.equals(expectedResult, result); }); | 536 continuation: (String result) { Expect.equals(expectedResult, result); }); |
570 } | 537 } |
571 | 538 |
572 testDoubleMains() { | 539 testDoubleMains() { |
573 var librarySrc = ''' | 540 var librarySrc = ''' |
574 library mylib; | 541 library mylib; |
575 main() {} | 542 main() {} |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 testSimpleTopLevelClass(); | 705 testSimpleTopLevelClass(); |
739 testClassWithSynthesizedConstructor(); | 706 testClassWithSynthesizedConstructor(); |
740 testClassWithMethod(); | 707 testClassWithMethod(); |
741 testExtendsImplements(); | 708 testExtendsImplements(); |
742 testVariableDefinitions(); | 709 testVariableDefinitions(); |
743 testGetSet(); | 710 testGetSet(); |
744 testAbstractClass(); | 711 testAbstractClass(); |
745 testConflictSendsRename(); | 712 testConflictSendsRename(); |
746 testNoConflictSendsRename(); | 713 testNoConflictSendsRename(); |
747 testConflictLibraryClassRename(); | 714 testConflictLibraryClassRename(); |
748 testDefaultClassWithArgs(); | |
749 testClassExtendsWithArgs(); | 715 testClassExtendsWithArgs(); |
750 testStaticInvocation(); | 716 testStaticInvocation(); |
751 testLibraryGetSet(); | 717 testLibraryGetSet(); |
752 testFieldTypeOutput(); | 718 testFieldTypeOutput(); |
753 testDefaultClassNamePlaceholder(); | |
754 testTypeVariablesAreRenamed(); | 719 testTypeVariablesAreRenamed(); |
755 testClassTypeArgumentBound(); | 720 testClassTypeArgumentBound(); |
756 testDoubleMains(); | 721 testDoubleMains(); |
757 testStaticAccessIoLib(); | 722 testStaticAccessIoLib(); |
758 testLocalFunctionPlaceholder(); | 723 testLocalFunctionPlaceholder(); |
759 testMinification(); | 724 testMinification(); |
760 testClosureLocalsMinified(); | 725 testClosureLocalsMinified(); |
761 testParametersMinified(); | 726 testParametersMinified(); |
762 testDeclarationTypePlaceholders(); | 727 testDeclarationTypePlaceholders(); |
763 testPlatformLibraryMemberNamesAreFixed(); | 728 testPlatformLibraryMemberNamesAreFixed(); |
764 testConflictsWithCoreLib(); | 729 testConflictsWithCoreLib(); |
765 testUnresolvedNamedConstructor(); | 730 testUnresolvedNamedConstructor(); |
766 } | 731 } |
OLD | NEW |