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

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

Issue 10823293: Support resolution of indexed operators. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « lib/compiler/implementation/resolver.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) 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/scanner/scannerlib.dart");
10 #import("../../../lib/compiler/implementation/util/util.dart"); 11 #import("../../../lib/compiler/implementation/util/util.dart");
11 #import("compiler_helper.dart"); 12 #import("compiler_helper.dart");
12 #import("mock_compiler.dart"); 13 #import("mock_compiler.dart");
13 #import("parser_helper.dart"); 14 #import("parser_helper.dart");
14 15
15 Node buildIdentifier(String name) => new Identifier(scan(name)); 16 Node buildIdentifier(String name) => new Identifier(scan(name));
16 17
17 Node buildInitialization(String name) => 18 Node buildInitialization(String name) =>
18 parseBodyCode('$name = 1', 19 parseBodyCode('$name = 1',
19 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); 20 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // testTwoInterfaces(); // Generates unexpected error message. 67 // testTwoInterfaces(); // Generates unexpected error message.
67 testFunctionExpression(); 68 testFunctionExpression();
68 testNewExpression(); 69 testNewExpression();
69 testTopLevelFields(); 70 testTopLevelFields();
70 testClassHierarchy(); 71 testClassHierarchy();
71 testInitializers(); 72 testInitializers();
72 testThis(); 73 testThis();
73 testSuperCalls(); 74 testSuperCalls();
74 testTypeVariables(); 75 testTypeVariables();
75 testToString(); 76 testToString();
77 testIndexedOperator();
76 } 78 }
77 79
78 testTypeVariables() { 80 testTypeVariables() {
79 matchResolvedTypes(visitor, text, name, expectedElements) { 81 matchResolvedTypes(visitor, text, name, expectedElements) {
80 VariableDefinitions definition = parseStatement(text); 82 VariableDefinitions definition = parseStatement(text);
81 visitor.visit(definition.type); 83 visitor.visit(definition.type);
82 InterfaceType type = visitor.mapping.getType(definition.type); 84 InterfaceType type = visitor.mapping.getType(definition.type);
83 Expect.equals(definition.type.typeArguments.length(), 85 Expect.equals(definition.type.typeArguments.length(),
84 length(type.arguments)); 86 length(type.arguments));
85 int index = 0; 87 int index = 0;
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 721
720 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 722 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
721 723
722 List<String> asSortedStrings(Link link) { 724 List<String> asSortedStrings(Link link) {
723 List<String> result = <String>[]; 725 List<String> result = <String>[];
724 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); 726 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString());
725 result.sort((s1, s2) => s1.compareTo(s2)); 727 result.sort((s1, s2) => s1.compareTo(s2));
726 return result; 728 return result;
727 } 729 }
728 730
731 compileScript(String source) {
732 Uri uri = new Uri.fromComponents(scheme: 'source');
733 MockCompiler compiler = compilerFor(source, uri);
734 compiler.runCompiler(uri);
735 return compiler;
736 }
737
729 testToString() { 738 testToString() {
730 Uri uri = new Uri.fromComponents(scheme: 'source'); 739 final script = @"class C { toString() => 'C'; } main() { '${new C()}'; }";
731 MockCompiler compiler = compilerFor( 740 final compiler = compileScript(script);
732 @"class C { toString() => 'C'; } main() { '${new C()}'; }",
733 uri);
734 compiler.runCompiler(uri);
735 741
736 Element toStringMethod = findElement(compiler, 'C') 742 Element toStringMethod = findElement(compiler, 'C')
737 .lookupLocalMember(buildSourceString('toString')); 743 .lookupLocalMember(buildSourceString('toString'));
738 Expect.isNotNull(toStringMethod); 744 Expect.isNotNull(toStringMethod);
739 745
740 Expect.isNotNull( 746 Expect.isNotNull(
741 compiler.enqueuer.resolution.getCachedElements(toStringMethod)); 747 compiler.enqueuer.resolution.getCachedElements(toStringMethod));
742 } 748 }
749
750 testIndexedOperator() {
751 final script = @"""
752 class C {
753 operator[](ix) => ix;
754 operator[]=(ix, v) {}
755 }
756 main() { var c = new C(); c[0]++ ; }""";
757 final compiler = compileScript(script);
758
759 operatorName(op) => Elements.constructOperatorName(
760 const SourceString('operator'), new SourceString(op));
761
762 Element indexedOperator = findElement(compiler, 'C')
763 .lookupLocalMember(operatorName('[]'));
764 Expect.isNotNull(indexedOperator);
765 Expect.isNotNull(
766 compiler.enqueuer.resolution.getCachedElements(indexedOperator));
767
768 Element indexedSetOperator = findElement(compiler, 'C')
769 .lookupLocalMember(operatorName('[]='));
770 Expect.isNotNull(indexedOperator);
771 Expect.isNotNull(
772 compiler.enqueuer.resolution.getCachedElements(indexedSetOperator));
773 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698