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

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

Issue 10824276: Register toString dynamic invocation in the presence of string interpolation. (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
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');
6
5 #import("../../../lib/compiler/implementation/leg.dart"); 7 #import("../../../lib/compiler/implementation/leg.dart");
6 #import("../../../lib/compiler/implementation/elements/elements.dart"); 8 #import("../../../lib/compiler/implementation/elements/elements.dart");
9 #import('../../../lib/compiler/implementation/source_file.dart');
7 #import("../../../lib/compiler/implementation/tree/tree.dart"); 10 #import("../../../lib/compiler/implementation/tree/tree.dart");
8 #import("../../../lib/compiler/implementation/util/util.dart"); 11 #import("../../../lib/compiler/implementation/util/util.dart");
9 #import("mock_compiler.dart"); 12 #import("mock_compiler.dart");
10 #import("parser_helper.dart"); 13 #import("parser_helper.dart");
11 14
12 Node buildIdentifier(String name) => new Identifier(scan(name)); 15 Node buildIdentifier(String name) => new Identifier(scan(name));
13 16
14 Node buildInitialization(String name) => 17 Node buildInitialization(String name) =>
15 parseBodyCode('$name = 1', 18 parseBodyCode('$name = 1',
16 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); 19 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // testOneInterface(); // Generates unexpected error message. 65 // testOneInterface(); // Generates unexpected error message.
63 // testTwoInterfaces(); // Generates unexpected error message. 66 // testTwoInterfaces(); // Generates unexpected error message.
64 testFunctionExpression(); 67 testFunctionExpression();
65 testNewExpression(); 68 testNewExpression();
66 testTopLevelFields(); 69 testTopLevelFields();
67 testClassHierarchy(); 70 testClassHierarchy();
68 testInitializers(); 71 testInitializers();
69 testThis(); 72 testThis();
70 testSuperCalls(); 73 testSuperCalls();
71 testTypeVariables(); 74 testTypeVariables();
75 testToString();
72 } 76 }
73 77
74 testTypeVariables() { 78 testTypeVariables() {
75 matchResolvedTypes(visitor, text, name, expectedElements) { 79 matchResolvedTypes(visitor, text, name, expectedElements) {
76 VariableDefinitions definition = parseStatement(text); 80 VariableDefinitions definition = parseStatement(text);
77 visitor.visit(definition.type); 81 visitor.visit(definition.type);
78 InterfaceType type = visitor.mapping.getType(definition.type); 82 InterfaceType type = visitor.mapping.getType(definition.type);
79 Expect.equals(definition.type.typeArguments.length(), 83 Expect.equals(definition.type.typeArguments.length(),
80 length(type.arguments)); 84 length(type.arguments));
81 int index = 0; 85 int index = 0;
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; 715 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1;
712 716
713 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 717 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
714 718
715 List<String> asSortedStrings(Link link) { 719 List<String> asSortedStrings(Link link) {
716 List<String> result = <String>[]; 720 List<String> result = <String>[];
717 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); 721 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString());
718 result.sort((s1, s2) => s1.compareTo(s2)); 722 result.sort((s1, s2) => s1.compareTo(s2));
719 return result; 723 return result;
720 } 724 }
725
726 testToString() {
727 String fileName = 'p.dart';
728 MockCompiler compiler = new MockCompiler();
729 compiler.sourceFiles[fileName] = new SourceFile(
730 fileName,
731 @"class C { toString() => 'C'; } main() { '${new C()}'; }");
ahe 2012/08/13 13:26:55 Why can't this test use compiler.parseScript?
Anton Muhin 2012/08/13 13:49:42 Something like this: testToString() { MockCompi
ahe 2012/08/13 15:05:56 Try: compiler.parseScript("class C { toString() =
732
733 final mainApp = compiler.scanner.loadLibrary(new Uri(fileName), null);
734 final Element main = mainApp.find(buildSourceString('main'));
735 compiler.phase = Compiler.PHASE_RESOLVING;
736 compiler.processQueue(compiler.enqueuer.resolution, main);
737
738 ClassElement classC = mainApp.find(buildSourceString('C'));
739 Element toStringMethod =
740 classC.lookupLocalMember(buildSourceString('toString'));
741 Expect.isNotNull(toStringMethod);
742
743 final resolvedElements = compiler.enqueuer.resolution.resolvedElements;
744 Expect.isTrue(resolvedElements.containsKey(toStringMethod));
745 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698