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

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

Issue 177963002: Use List instead of Link in the type system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 5 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 "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import "package:compiler/implementation/resolution/resolution.dart"; 10 import "package:compiler/implementation/resolution/resolution.dart";
11 import "compiler_helper.dart"; 11 import "compiler_helper.dart";
12 import "parser_helper.dart"; 12 import "parser_helper.dart";
13 13
14 import 'package:compiler/implementation/dart_types.dart'; 14 import 'package:compiler/implementation/dart_types.dart';
15 import 'package:compiler/implementation/elements/modelx.dart'; 15 import 'package:compiler/implementation/elements/modelx.dart';
16 import 'link_helper.dart';
16 17
17 Node buildIdentifier(String name) => new Identifier(scan(name)); 18 Node buildIdentifier(String name) => new Identifier(scan(name));
18 19
19 Node buildInitialization(String name) => 20 Node buildInitialization(String name) =>
20 parseBodyCode('$name = 1', 21 parseBodyCode('$name = 1',
21 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); 22 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens));
22 23
23 createLocals(List variables) { 24 createLocals(List variables) {
24 var locals = []; 25 var locals = <Node>[];
25 for (final variable in variables) { 26 for (final variable in variables) {
26 String name = variable[0]; 27 String name = variable[0];
27 bool init = variable[1]; 28 bool init = variable[1];
28 if (init) { 29 if (init) {
29 locals.add(buildInitialization(name)); 30 locals.add(buildInitialization(name));
30 } else { 31 } else {
31 locals.add(buildIdentifier(name)); 32 locals.add(buildIdentifier(name));
32 } 33 }
33 } 34 }
34 var definitions = new NodeList(null, new Link.fromList(locals), null, null); 35 var definitions = new NodeList(null, LinkFromList(locals), null, null);
35 return new VariableDefinitions(null, Modifiers.EMPTY, definitions); 36 return new VariableDefinitions(null, Modifiers.EMPTY, definitions);
36 } 37 }
37 38
38 Future testLocals(List variables) { 39 Future testLocals(List variables) {
39 return MockCompiler.create((MockCompiler compiler) { 40 return MockCompiler.create((MockCompiler compiler) {
40 ResolverVisitor visitor = compiler.resolverVisitor(); 41 ResolverVisitor visitor = compiler.resolverVisitor();
41 Element element = visitor.visit(createLocals(variables)); 42 Element element = visitor.visit(createLocals(variables));
42 // A VariableDefinitions does not have an element. 43 // A VariableDefinitions does not have an element.
43 Expect.equals(null, element); 44 Expect.equals(null, element);
44 Expect.equals(variables.length, map(visitor).length); 45 Expect.equals(variables.length, map(visitor).length);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 }), 128 }),
128 ]); 129 ]);
129 } 130 }
130 131
131 Future testTypeVariables() { 132 Future testTypeVariables() {
132 matchResolvedTypes(visitor, text, name, expectedElements) { 133 matchResolvedTypes(visitor, text, name, expectedElements) {
133 VariableDefinitions definition = parseStatement(text); 134 VariableDefinitions definition = parseStatement(text);
134 visitor.visit(definition.type); 135 visitor.visit(definition.type);
135 InterfaceType type = visitor.registry.mapping.getType(definition.type); 136 InterfaceType type = visitor.registry.mapping.getType(definition.type);
136 Expect.equals(definition.type.typeArguments.slowLength(), 137 Expect.equals(definition.type.typeArguments.slowLength(),
137 length(type.typeArguments)); 138 type.typeArguments.length);
138 int index = 0; 139 int index = 0;
139 Link<DartType> arguments = type.typeArguments; 140 for (DartType argument in type.typeArguments) {
140 while (!arguments.isEmpty) {
141 Expect.equals(true, index < expectedElements.length); 141 Expect.equals(true, index < expectedElements.length);
142 Expect.equals(expectedElements[index], arguments.head.element); 142 Expect.equals(expectedElements[index], argument.element);
143 index++; 143 index++;
144 arguments = arguments.tail;
145 } 144 }
146 Expect.equals(index, expectedElements.length); 145 Expect.equals(index, expectedElements.length);
147 } 146 }
148 147
149 return Future.wait([ 148 return Future.wait([
150 MockCompiler.create((MockCompiler compiler) { 149 MockCompiler.create((MockCompiler compiler) {
151 ResolverVisitor visitor = compiler.resolverVisitor(); 150 ResolverVisitor visitor = compiler.resolverVisitor();
152 compiler.parseScript('class Foo<T, U> {}'); 151 compiler.parseScript('class Foo<T, U> {}');
153 ClassElement foo = compiler.mainApp.find('Foo'); 152 ClassElement foo = compiler.mainApp.find('Foo');
154 matchResolvedTypes(visitor, 'Foo<int, String> x;', 'Foo', 153 matchResolvedTypes(visitor, 'Foo<int, String> x;', 'Foo',
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 }"""; 1076 }""";
1078 asyncTest(() => compileScript(script2).then((compiler) { 1077 asyncTest(() => compileScript(script2).then((compiler) {
1079 expect(compiler, 1078 expect(compiler,
1080 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], 1079 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS],
1081 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, 1080 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
1082 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, 1081 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
1083 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, 1082 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD,
1084 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); 1083 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]);
1085 })); 1084 }));
1086 } 1085 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mixin_typevariable_test.dart ('k') | tests/compiler/dart2js/subtype_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698