Chromium Code Reviews| 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('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/leg.dart", prefix:'leg'); | 9 #import("../../../lib/compiler/implementation/leg.dart", prefix:'leg'); |
| 10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); | 10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 const coreLib = @''' | 24 const coreLib = @''' |
| 25 #library('corelib'); | 25 #library('corelib'); |
| 26 class Object {} | 26 class Object {} |
| 27 interface bool {} | 27 interface bool {} |
| 28 interface num {} | 28 interface num {} |
| 29 interface int extends num {} | 29 interface int extends num {} |
| 30 interface double extends num {} | 30 interface double extends num {} |
| 31 interface String {} | 31 interface String {} |
| 32 interface Function {} | 32 interface Function {} |
| 33 interface List {} | 33 interface List {} |
| 34 interface Map {} | |
| 34 interface Closure {} | 35 interface Closure {} |
| 35 interface Dynamic {} | 36 interface Dynamic {} |
| 36 interface Null {} | 37 interface Null {} |
| 37 assert() {} | 38 assert() {} |
| 38 class Math { | 39 class Math { |
| 39 static double parseDouble(String s) => 1.0; | 40 static double parseDouble(String s) => 1.0; |
| 40 } | 41 } |
| 41 '''; | 42 '''; |
| 42 | 43 |
| 43 const ioLib = @''' | 44 const ioLib = @''' |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 var src = ''' | 470 var src = ''' |
| 470 main() { | 471 main() { |
| 471 function localfoo() {} | 472 function localfoo() {} |
| 472 localfoo(); | 473 localfoo(); |
| 473 } | 474 } |
| 474 '''; | 475 '''; |
| 475 MockCompiler compiler = new MockCompiler(); | 476 MockCompiler compiler = new MockCompiler(); |
| 476 compiler.parseScript(src); | 477 compiler.parseScript(src); |
| 477 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); | 478 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN); |
| 478 compiler.processQueue(compiler.enqueuer.resolution, mainElement); | 479 compiler.processQueue(compiler.enqueuer.resolution, mainElement); |
| 479 PlaceholderCollector collector = new PlaceholderCollector(compiler); | 480 PlaceholderCollector collector = |
| 481 new PlaceholderCollector(compiler, new Set<String>()); | |
| 480 collector.collect(mainElement, | 482 collector.collect(mainElement, |
| 481 compiler.enqueuer.resolution.resolvedElements[mainElement]); | 483 compiler.enqueuer.resolution.resolvedElements[mainElement]); |
| 482 FunctionExpression mainNode = mainElement.parseNode(compiler); | 484 FunctionExpression mainNode = mainElement.parseNode(compiler); |
| 483 FunctionExpression fooNode = mainNode.body.statements.nodes.head.function; | 485 FunctionExpression fooNode = mainNode.body.statements.nodes.head.function; |
| 484 LocalPlaceholder fooPlaceholder = | 486 LocalPlaceholder fooPlaceholder = |
| 485 collector.functionScopes[mainElement].localPlaceholders.iterator().next(); | 487 collector.functionScopes[mainElement].localPlaceholders.iterator().next(); |
| 486 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); | 488 Expect.isTrue(fooPlaceholder.nodes.contains(fooNode.name)); |
| 487 } | 489 } |
| 488 | 490 |
| 489 testDefaultClassNamePlaceholder() { | 491 testDefaultClassNamePlaceholder() { |
| 490 var src = ''' | 492 var src = ''' |
| 491 interface I default C{ | 493 interface I default C{ |
| 492 I(); | 494 I(); |
| 493 } | 495 } |
| 494 | 496 |
| 495 class C { | 497 class C { |
| 496 I() {} | 498 I() {} |
| 497 } | 499 } |
| 498 | 500 |
| 499 main() { | 501 main() { |
| 500 new I(); | 502 new I(); |
| 501 } | 503 } |
| 502 '''; | 504 '''; |
| 503 MockCompiler compiler = new MockCompiler(); | 505 MockCompiler compiler = new MockCompiler(); |
| 504 compiler.parseScript(src); | 506 compiler.parseScript(src); |
| 505 ClassElement interfaceElement = compiler.mainApp.find(buildSourceString('I')); | 507 ClassElement interfaceElement = compiler.mainApp.find(buildSourceString('I')); |
| 506 interfaceElement.ensureResolved(compiler); | 508 interfaceElement.ensureResolved(compiler); |
| 507 PlaceholderCollector collector = new PlaceholderCollector(compiler); | 509 PlaceholderCollector collector = |
| 510 new PlaceholderCollector(compiler, new Set<String>()); | |
| 508 collector.collect(interfaceElement, | 511 collector.collect(interfaceElement, |
| 509 compiler.enqueuer.resolution.resolvedElements[interfaceElement]); | 512 compiler.enqueuer.resolution.resolvedElements[interfaceElement]); |
| 510 ClassNode interfaceNode = interfaceElement.parseNode(compiler); | 513 ClassNode interfaceNode = interfaceElement.parseNode(compiler); |
| 511 Node defaultTypeNode = interfaceNode.defaultClause.typeName; | 514 Node defaultTypeNode = interfaceNode.defaultClause.typeName; |
| 512 ClassElement classElement = compiler.mainApp.find(buildSourceString('C')); | 515 ClassElement classElement = compiler.mainApp.find(buildSourceString('C')); |
| 513 // Check that 'C' in default clause of I gets into placeholders. | 516 // Check that 'C' in default clause of I gets into placeholders. |
| 514 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode)); | 517 Expect.isTrue(collector.elementNodes[classElement].contains(defaultTypeNode)); |
| 515 } | 518 } |
| 516 | 519 |
| 517 testFactoryRename() { | 520 testFactoryRename() { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 arg = 6; | 740 arg = 6; |
| 738 } | 741 } |
| 739 | 742 |
| 740 main() { | 743 main() { |
| 741 new A().a; | 744 new A().a; |
| 742 A.foo(8); | 745 A.foo(8); |
| 743 fooglobal(8); | 746 fooglobal(8); |
| 744 } | 747 } |
| 745 '''; | 748 '''; |
| 746 var expectedResult = | 749 var expectedResult = |
| 747 'class A{var a;static B(b){b=5;}}' | 750 'class A{var D;static B(b){b=5;}}' |
| 748 'C(a,[optionalarg=7]){a=6;}' | 751 'C(a,[optionalarg=7]){a=6;}' |
| 749 'main(){new A().a; A.B(8); C(8);}'; | 752 'main(){new A().D; A.B(8); C(8);}'; |
| 750 testDart2Dart(src, | 753 testDart2Dart(src, |
| 751 (String result) { Expect.equals(expectedResult, result); }, minify: true); | 754 (String result) { Expect.equals(expectedResult, result); }, minify: true); |
| 752 } | 755 } |
| 753 | 756 |
| 754 testTypeVariablesInDifferentLibraries() { | 757 testTypeVariablesInDifferentLibraries() { |
| 755 // This is a simplified version of what we have in | 758 // This is a simplified version of what we have in |
| 756 // lib/compiler/implementation/util. | 759 // lib/compiler/implementation/util. |
| 757 var librarySrc = ''' | 760 var librarySrc = ''' |
| 758 #library('mylib'); | 761 #library('mylib'); |
| 759 #import('script.dart'); | 762 #import('script.dart'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 foo("5"); | 799 foo("5"); |
| 797 } | 800 } |
| 798 '''; | 801 '''; |
| 799 var expectedResult = | 802 var expectedResult = |
| 800 ' foo( arg){}main(){var localvar; foo("5");}'; | 803 ' foo( arg){}main(){var localvar; foo("5");}'; |
| 801 testDart2Dart(src, | 804 testDart2Dart(src, |
| 802 (String result) { Expect.equals(expectedResult, result); }, | 805 (String result) { Expect.equals(expectedResult, result); }, |
| 803 cutDeclarationTypes: true); | 806 cutDeclarationTypes: true); |
| 804 } | 807 } |
| 805 | 808 |
| 806 main() { | 809 main() { |
|
Roman
2012/08/29 08:40:09
Please add one complicated test for member renames
Anton Muhin
2012/08/29 09:43:46
I thought about that, but eventually decided again
| |
| 807 testSignedConstants(); | 810 testSignedConstants(); |
| 808 testGenericTypes(); | 811 testGenericTypes(); |
| 809 testForLoop(); | 812 testForLoop(); |
| 810 testEmptyList(); | 813 testEmptyList(); |
| 811 testClosure(); | 814 testClosure(); |
| 812 testIndexedOperatorDecl(); | 815 testIndexedOperatorDecl(); |
| 813 testNativeMethods(); | 816 testNativeMethods(); |
| 814 testPrefixIncrements(); | 817 testPrefixIncrements(); |
| 815 testConstModifier(); | 818 testConstModifier(); |
| 816 testSimpleFileUnparse(); | 819 testSimpleFileUnparse(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 839 testDoubleMains(); | 842 testDoubleMains(); |
| 840 testInterfaceDefaultAnotherLib(); | 843 testInterfaceDefaultAnotherLib(); |
| 841 testStaticAccessIoLib(); | 844 testStaticAccessIoLib(); |
| 842 testLocalFunctionPlaceholder(); | 845 testLocalFunctionPlaceholder(); |
| 843 testMinification(); | 846 testMinification(); |
| 844 testClosureLocalsMinified(); | 847 testClosureLocalsMinified(); |
| 845 testParametersMinified(); | 848 testParametersMinified(); |
| 846 testTypeVariablesInDifferentLibraries(); | 849 testTypeVariablesInDifferentLibraries(); |
| 847 testDeclarationTypePlaceholders(); | 850 testDeclarationTypePlaceholders(); |
| 848 } | 851 } |
| OLD | NEW |