Index: tests/compiler/dart2js/type_representation_test.dart |
diff --git a/tests/compiler/dart2js/type_representation_test.dart b/tests/compiler/dart2js/type_representation_test.dart |
index 1c946eeea1453ebfc28d44020d0c67e40e00e6ab..2f0cd6f1da406f3583b83957c01b20d7d829de42 100644 |
--- a/tests/compiler/dart2js/type_representation_test.dart |
+++ b/tests/compiler/dart2js/type_representation_test.dart |
@@ -17,7 +17,7 @@ void main() { |
} |
void testTypeRepresentations() { |
- var env = new TypeEnvironment(r""" |
+ TypeEnvironment.create(r""" |
typedef void Typedef(); |
void m1() {} |
@@ -30,121 +30,121 @@ void testTypeRepresentations() { |
m8(int a, {String b}) {} |
m9(int a, String b, {List<int> c, d}) {} |
m10(void f(int a, [b])) {} |
- """); |
- |
- TypeRepresentationGenerator typeRepresentation = |
- new TypeRepresentationGenerator(env.compiler); |
- String onVariable(TypeVariableType type) => type.name.slowToString(); |
- |
- void expect(String expectedRepresentation, DartType type) { |
- String foundRepresentation = |
- typeRepresentation.getTypeRepresentation(type, onVariable); |
- Expect.stringEquals(expectedRepresentation, foundRepresentation); |
- } |
- |
- JavaScriptBackend backend = env.compiler.backend; |
- String func = backend.namer.functionTypeTag(); |
- String retvoid = backend.namer.functionTypeVoidReturnTag(); |
- String ret = backend.namer.functionTypeReturnTypeTag(); |
- String args = backend.namer.functionTypeRequiredParametersTag(); |
- String opt = backend.namer.functionTypeOptionalParametersTag(); |
- String named = backend.namer.functionTypeNamedParametersTag(); |
- |
- ClassElement List_ = env.getElement('List'); |
- TypeVariableType List_E = List_.typeVariables.head; |
- ClassElement Map_ = env.getElement('Map'); |
- TypeVariableType Map_K = Map_.typeVariables.head; |
- TypeVariableType Map_V = Map_.typeVariables.tail.head; |
- |
- DartType Object_ = env['Object']; |
- DartType int_ = env['int']; |
- DartType String_ = env['String']; |
- DartType dynamic_ = env['dynamic']; |
- DartType Typedef_ = env['Typedef']; |
- |
- String List_rep = typeRepresentation.getJsName(List_); |
- String List_E_rep = onVariable(List_E); |
- String Map_rep = typeRepresentation.getJsName(Map_); |
- String Map_K_rep = onVariable(Map_K); |
- String Map_V_rep = onVariable(Map_V); |
- |
- String Object_rep = typeRepresentation.getJsName(Object_.element); |
- String int_rep = typeRepresentation.getJsName(int_.element); |
- String String_rep = typeRepresentation.getJsName(String_.element); |
- |
- expect('$int_rep', int_); |
- expect('$String_rep', String_); |
- expect('null', dynamic_); |
- |
- // List<E> |
- expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler)); |
- // List |
- expect('$List_rep', List_.rawType); |
- // List<dynamic> |
- expect('[$List_rep, null]', instantiate(List_, [dynamic_])); |
- // List<int> |
- expect('[$List_rep, $int_rep]', instantiate(List_, [int_])); |
- // List<Typedef> |
- expect('[$List_rep, {$func: "void_", $retvoid: true}]', |
- instantiate(List_, [Typedef_])); |
- |
- // Map<K,V> |
- expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler)); |
- // Map |
- expect('$Map_rep', Map_.rawType); |
- // Map<dynamic,dynamic> |
- expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_])); |
- // Map<int,String> |
- expect('[$Map_rep, $int_rep, $String_rep]', |
- instantiate(Map_, [int_, String_])); |
- |
- // void m1() {} |
- expect('{$func: "void_", $retvoid: true}', |
- env.getElement('m1').computeType(env.compiler)); |
- |
- // int m2() => 0; |
- expect('{$func: "int_", $ret: $int_rep}', |
- env.getElement('m2').computeType(env.compiler)); |
- |
- // List<int> m3() => null; |
- expect('{$func: "List_", $ret: [$List_rep, $int_rep]}', |
- env.getElement('m3').computeType(env.compiler)); |
- |
- // m4() {} |
- expect('{$func: "dynamic_"}', |
- env.getElement('m4').computeType(env.compiler)); |
- |
- // m5(int a, String b) {} |
- expect('{$func: "dynamic__int_String", $args: [$int_rep, $String_rep]}', |
- env.getElement('m5').computeType(env.compiler)); |
- |
- // m6(int a, [String b]) {} |
- expect('{$func: "dynamic__int__String", $args: [$int_rep],' |
- ' $opt: [$String_rep]}', |
- env.getElement('m6').computeType(env.compiler)); |
- |
- // m7(int a, String b, [List<int> c, d]) {} |
- expect('{$func: "dynamic__int_String__List_dynamic",' |
- ' $args: [$int_rep, $String_rep],' |
- ' $opt: [[$List_rep, $int_rep], null]}', |
- env.getElement('m7').computeType(env.compiler)); |
- |
- // m8(int a, {String b}) {} |
- expect('{$func: "dynamic__int__String0",' |
- ' $args: [$int_rep], $named: {b: $String_rep}}', |
- env.getElement('m8').computeType(env.compiler)); |
- |
- // m9(int a, String b, {List<int> c, d}) {} |
- expect('{$func: "dynamic__int_String__List_dynamic0",' |
- ' $args: [$int_rep, $String_rep],' |
- ' $named: {c: [$List_rep, $int_rep], d: null}}', |
- env.getElement('m9').computeType(env.compiler)); |
- |
- // m10(void f(int a, [b])) {} |
- expect('{$func: "dynamic__void__int__dynamic", $args:' |
- ' [{$func: "void__int__dynamic",' |
- ' $retvoid: true, $args: [$int_rep], $opt: [null]}]}', |
- env.getElement('m10').computeType(env.compiler)); |
+ """).then((env) { |
+ TypeRepresentationGenerator typeRepresentation = |
+ new TypeRepresentationGenerator(env.compiler); |
+ String onVariable(TypeVariableType type) => type.name.slowToString(); |
+ |
+ void expect(String expectedRepresentation, DartType type) { |
+ String foundRepresentation = |
+ typeRepresentation.getTypeRepresentation(type, onVariable); |
+ Expect.stringEquals(expectedRepresentation, foundRepresentation); |
+ } |
+ |
+ JavaScriptBackend backend = env.compiler.backend; |
+ String func = backend.namer.functionTypeTag(); |
+ String retvoid = backend.namer.functionTypeVoidReturnTag(); |
+ String ret = backend.namer.functionTypeReturnTypeTag(); |
+ String args = backend.namer.functionTypeRequiredParametersTag(); |
+ String opt = backend.namer.functionTypeOptionalParametersTag(); |
+ String named = backend.namer.functionTypeNamedParametersTag(); |
+ |
+ ClassElement List_ = env.getElement('List'); |
+ TypeVariableType List_E = List_.typeVariables.head; |
+ ClassElement Map_ = env.getElement('Map'); |
+ TypeVariableType Map_K = Map_.typeVariables.head; |
+ TypeVariableType Map_V = Map_.typeVariables.tail.head; |
+ |
+ DartType Object_ = env['Object']; |
+ DartType int_ = env['int']; |
+ DartType String_ = env['String']; |
+ DartType dynamic_ = env['dynamic']; |
+ DartType Typedef_ = env['Typedef']; |
+ |
+ String List_rep = typeRepresentation.getJsName(List_); |
+ String List_E_rep = onVariable(List_E); |
+ String Map_rep = typeRepresentation.getJsName(Map_); |
+ String Map_K_rep = onVariable(Map_K); |
+ String Map_V_rep = onVariable(Map_V); |
+ |
+ String Object_rep = typeRepresentation.getJsName(Object_.element); |
+ String int_rep = typeRepresentation.getJsName(int_.element); |
+ String String_rep = typeRepresentation.getJsName(String_.element); |
+ |
+ expect('$int_rep', int_); |
+ expect('$String_rep', String_); |
+ expect('null', dynamic_); |
+ |
+ // List<E> |
+ expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler)); |
+ // List |
+ expect('$List_rep', List_.rawType); |
+ // List<dynamic> |
+ expect('[$List_rep, null]', instantiate(List_, [dynamic_])); |
+ // List<int> |
+ expect('[$List_rep, $int_rep]', instantiate(List_, [int_])); |
+ // List<Typedef> |
+ expect('[$List_rep, {$func: "void_", $retvoid: true}]', |
+ instantiate(List_, [Typedef_])); |
+ |
+ // Map<K,V> |
+ expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler)); |
+ // Map |
+ expect('$Map_rep', Map_.rawType); |
+ // Map<dynamic,dynamic> |
+ expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_])); |
+ // Map<int,String> |
+ expect('[$Map_rep, $int_rep, $String_rep]', |
+ instantiate(Map_, [int_, String_])); |
+ |
+ // void m1() {} |
+ expect('{$func: "void_", $retvoid: true}', |
+ env.getElement('m1').computeType(env.compiler)); |
+ |
+ // int m2() => 0; |
+ expect('{$func: "int_", $ret: $int_rep}', |
+ env.getElement('m2').computeType(env.compiler)); |
+ |
+ // List<int> m3() => null; |
+ expect('{$func: "List_", $ret: [$List_rep, $int_rep]}', |
+ env.getElement('m3').computeType(env.compiler)); |
+ |
+ // m4() {} |
+ expect('{$func: "dynamic_"}', |
+ env.getElement('m4').computeType(env.compiler)); |
+ |
+ // m5(int a, String b) {} |
+ expect('{$func: "dynamic__int_String", $args: [$int_rep, $String_rep]}', |
+ env.getElement('m5').computeType(env.compiler)); |
+ |
+ // m6(int a, [String b]) {} |
+ expect('{$func: "dynamic__int__String", $args: [$int_rep],' |
+ ' $opt: [$String_rep]}', |
+ env.getElement('m6').computeType(env.compiler)); |
+ |
+ // m7(int a, String b, [List<int> c, d]) {} |
+ expect('{$func: "dynamic__int_String__List_dynamic",' |
+ ' $args: [$int_rep, $String_rep],' |
+ ' $opt: [[$List_rep, $int_rep], null]}', |
+ env.getElement('m7').computeType(env.compiler)); |
+ |
+ // m8(int a, {String b}) {} |
+ expect('{$func: "dynamic__int__String0",' |
+ ' $args: [$int_rep], $named: {b: $String_rep}}', |
+ env.getElement('m8').computeType(env.compiler)); |
+ |
+ // m9(int a, String b, {List<int> c, d}) {} |
+ expect('{$func: "dynamic__int_String__List_dynamic0",' |
+ ' $args: [$int_rep, $String_rep],' |
+ ' $named: {c: [$List_rep, $int_rep], d: null}}', |
+ env.getElement('m9').computeType(env.compiler)); |
+ |
+ // m10(void f(int a, [b])) {} |
+ expect('{$func: "dynamic__void__int__dynamic", $args:' |
+ ' [{$func: "void__int__dynamic",' |
+ ' $retvoid: true, $args: [$int_rep], $opt: [null]}]}', |
+ env.getElement('m10').computeType(env.compiler)); |
+ }); |
} |