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 | 6 |
| 7 #import("../../../lib/compiler/implementation/leg.dart"); | 7 #import("../../../lib/compiler/implementation/leg.dart"); |
| 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 8 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 9 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 10 #import("../../../lib/compiler/implementation/util/util.dart"); | 10 #import("../../../lib/compiler/implementation/util/util.dart"); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 // testTwoInterfaces(); // Generates unexpected error message. | 66 // testTwoInterfaces(); // Generates unexpected error message. |
| 67 testFunctionExpression(); | 67 testFunctionExpression(); |
| 68 testNewExpression(); | 68 testNewExpression(); |
| 69 testTopLevelFields(); | 69 testTopLevelFields(); |
| 70 testClassHierarchy(); | 70 testClassHierarchy(); |
| 71 testInitializers(); | 71 testInitializers(); |
| 72 testThis(); | 72 testThis(); |
| 73 testSuperCalls(); | 73 testSuperCalls(); |
| 74 testTypeVariables(); | 74 testTypeVariables(); |
| 75 testToString(); | 75 testToString(); |
| 76 testIndexedOperator(); | |
| 76 } | 77 } |
| 77 | 78 |
| 78 testTypeVariables() { | 79 testTypeVariables() { |
| 79 matchResolvedTypes(visitor, text, name, expectedElements) { | 80 matchResolvedTypes(visitor, text, name, expectedElements) { |
| 80 VariableDefinitions definition = parseStatement(text); | 81 VariableDefinitions definition = parseStatement(text); |
| 81 visitor.visit(definition.type); | 82 visitor.visit(definition.type); |
| 82 InterfaceType type = visitor.mapping.getType(definition.type); | 83 InterfaceType type = visitor.mapping.getType(definition.type); |
| 83 Expect.equals(definition.type.typeArguments.length(), | 84 Expect.equals(definition.type.typeArguments.length(), |
| 84 length(type.arguments)); | 85 length(type.arguments)); |
| 85 int index = 0; | 86 int index = 0; |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 | 720 |
| 720 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); | 721 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |
| 721 | 722 |
| 722 List<String> asSortedStrings(Link link) { | 723 List<String> asSortedStrings(Link link) { |
| 723 List<String> result = <String>[]; | 724 List<String> result = <String>[]; |
| 724 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); | 725 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); |
| 725 result.sort((s1, s2) => s1.compareTo(s2)); | 726 result.sort((s1, s2) => s1.compareTo(s2)); |
| 726 return result; | 727 return result; |
| 727 } | 728 } |
| 728 | 729 |
| 730 compileScript(String source, f(compiler)) { | |
|
kasperl
2012/08/14 07:13:13
Could this just return the compiler instead?
Anton Muhin
2012/08/14 11:34:44
Done.
| |
| 731 Uri uri = new Uri.fromComponents(scheme: 'source'); | |
| 732 MockCompiler compiler = compilerFor(source, uri); | |
| 733 compiler.runCompiler(uri); | |
| 734 f(compiler); | |
| 735 } | |
| 736 | |
| 729 testToString() { | 737 testToString() { |
| 730 Uri uri = new Uri.fromComponents(scheme: 'source'); | 738 compileScript(@"class C { toString() => 'C'; } main() { '${new C()}'; }", |
|
kasperl
2012/08/14 07:13:13
Maybe stuff the script code in a string variable t
Anton Muhin
2012/08/14 11:34:44
Hopefully obsolete after addressing your previous
| |
| 731 MockCompiler compiler = compilerFor( | 739 (compiler) { |
| 732 @"class C { toString() => 'C'; } main() { '${new C()}'; }", | 740 Element toStringMethod = findElement(compiler, 'C') |
| 733 uri); | 741 .lookupLocalMember(buildSourceString('toString')); |
| 734 compiler.runCompiler(uri); | 742 Expect.isNotNull(toStringMethod); |
| 735 | 743 |
| 736 Element toStringMethod = findElement(compiler, 'C') | 744 Expect.isNotNull( |
| 737 .lookupLocalMember(buildSourceString('toString')); | 745 compiler.enqueuer.resolution.getCachedElements(toStringMethod)); |
| 738 Expect.isNotNull(toStringMethod); | 746 }); |
| 747 } | |
| 739 | 748 |
| 740 Expect.isNotNull( | 749 testIndexedOperator() { |
| 741 compiler.enqueuer.resolution.getCachedElements(toStringMethod)); | 750 compileScript(@""" |
|
kasperl
2012/08/14 07:13:13
Separate string variable for the script code.
Anton Muhin
2012/08/14 11:34:44
Done.
| |
| 751 class C { | |
| 752 operator[](ix) => ix; | |
| 753 operator[]=(ix, v) {} | |
| 754 } | |
| 755 main() { var c = new C(); c[0]++ ; }""", | |
| 756 (compiler) { | |
| 757 Element indexedOperator = findElement(compiler, 'C') | |
| 758 .lookupLocalMember(buildSourceString(@'operator$index')); | |
|
kasperl
2012/08/14 07:13:13
It would be nice if you didn't have to hardcode th
Anton Muhin
2012/08/14 11:34:44
Done.
| |
| 759 Expect.isNotNull(indexedOperator); | |
| 760 Expect.isNotNull( | |
| 761 compiler.enqueuer.resolution.getCachedElements(indexedOperator)); | |
| 762 | |
| 763 Element indexedSetOperator = findElement(compiler, 'C') | |
| 764 .lookupLocalMember(buildSourceString(@'operator$indexSet')); | |
| 765 Expect.isNotNull(indexedOperator); | |
| 766 Expect.isNotNull( | |
| 767 compiler.enqueuer.resolution.getCachedElements(indexedSetOperator)); | |
| 768 }); | |
| 742 } | 769 } |
| OLD | NEW |