Chromium Code Reviews| Index: tests/compiler/dart2js/type_equals_test.dart |
| diff --git a/tests/compiler/dart2js/type_equals_test.dart b/tests/compiler/dart2js/type_equals_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e41758ae77b1d848eb3ab2d97e733a6fa277f6b0 |
| --- /dev/null |
| +++ b/tests/compiler/dart2js/type_equals_test.dart |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#import("../../../lib/compiler/implementation/leg.dart"); |
| +#import("../../../lib/compiler/implementation/elements/elements.dart"); |
| +#import("../../../lib/compiler/implementation/tree/tree.dart"); |
| +#import("../../../lib/compiler/implementation/util/util.dart"); |
| +#import("mock_compiler.dart"); |
| +#import("parser_helper.dart"); |
| +#import("dart:uri"); |
| + |
| +Compiler compile(String script) { |
|
ahe
2012/09/17 08:19:58
You'd probably be better off using compilerFor in
Johnni Winther
2012/09/18 08:14:30
Done.
|
| + String core = "$DEFAULT_CORELIB\n$script"; |
| + MockCompiler compiler = new MockCompiler(coreSource: core); |
| + return compiler; |
| +} |
| + |
| +bool test(compiler, String name1, String name2, [bool expect]) { |
|
ahe
2012/09/17 08:19:58
Should use {}, not [].
Since the argument is requ
Johnni Winther
2012/09/18 08:14:30
Done.
|
| + var clazz = |
|
ahe
2012/09/17 08:19:58
You can use the word "class".
Johnni Winther
2012/09/18 08:14:30
The VM complains.
|
| + compiler.coreLibrary.buildScope().lookup(buildSourceString("Class")); |
| + clazz.ensureResolved(compiler); |
| + var element1 = clazz.buildScope().lookup(buildSourceString(name1)); |
| + var element2 = clazz.buildScope().lookup(buildSourceString(name2)); |
| + Expect.isNotNull(element1); |
| + Expect.isNotNull(element2); |
| + Expect.isTrue(element1 is FunctionElement); |
|
ahe
2012/09/17 08:19:58
Test the kind instead, it is more precise.
Also,
Johnni Winther
2012/09/18 08:14:30
Done.
|
| + Expect.isTrue(element2 is FunctionElement); |
| + var signature1 = element1.computeSignature(compiler); |
|
ahe
2012/09/17 08:19:58
Use a type here for improved readability.
Johnni Winther
2012/09/18 08:14:30
Done.
|
| + var signature2 = element2.computeSignature(compiler); |
| + |
| + var value1; |
|
ahe
2012/09/17 08:19:58
A type here would also improve. Especially since t
Johnni Winther
2012/09/18 08:14:30
Done.
|
| + var value2; |
| + if (signature1.requiredParameterCount == 0) { |
| + value1 = signature1.returnType; |
| + } else { |
| + value1 = signature1.requiredParameters.head.computeType(compiler); |
| + } |
| + if (signature2.requiredParameterCount == 0) { |
| + value2 = signature2.returnType; |
| + } else { |
| + value2 = signature2.requiredParameters.head.computeType(compiler); |
| + } |
| + if (expect) { |
| + Expect.equals(value1, value2, "$value1 != $value2"); |
| + } else { |
| + Expect.notEquals(value1, value2, "$value1 == $value2"); |
| + } |
|
ahe
2012/09/17 08:19:58
I find this test confusing. It seems like you don'
Johnni Winther
2012/09/18 08:14:30
Comments added as to why function signatures are u
|
| +} |
| + |
| +void main() { |
| + var compiler = compile( |
| + """ |
| + typedef int Typedef1<X,Y>(String s1); |
| + typedef void Typedef2<Z>(T t1, S s1); |
| + |
| + class Class<T,S> { |
| + void void1() {} |
| + void void2() {} |
| + void int1(int a) {} |
| + void int2(int b) {} |
| + void String1(String a) {} |
| + void String2(String b) {} |
| + void ListInt1(List<int> a) {} |
| + void ListInt2(List<int> b) {} |
| + void ListString1(List<String> a) {} |
| + void ListString2(List<String> b) {} |
| + void MapIntString1(Map<int,String> a) {} |
| + void MapIntString2(Map<int,String> b) {} |
| + void TypeVar1(T t1, S s1) {} |
| + void TypeVar2(T t2, S s2) {} |
| + void Function1a(int a(String s1)) {} |
| + void Function2a(int b(String s2)) {} |
| + void Function1b(void a(T t1, S s1)) {} |
| + void Function2b(void b(T t2, S s2)) {} |
| + void Typedef1a(Typedef1<int,String> a) {} |
| + void Typedef2a(Typedef1<int,String> b) {} |
| + void Typedef1b(Typedef2<T> a) {} |
| + void Typedef2b(Typedef2<T> b) {} |
| + void Typedef1c(Typedef2<S> a) {} |
| + void Typedef2c(Typedef2<S> b) {} |
| + } |
| + """ |
| + ); |
| + test(compiler, "void1", "void2", expect: true); |
| + test(compiler, "int1", "int2", expect: true); |
| + test(compiler, "String1", "String2", expect: true); |
| + test(compiler, "ListInt1", "ListInt2", expect: true); |
| + test(compiler, "ListString1", "ListString2", expect: true); |
| + test(compiler, "MapIntString1", "MapIntString2", expect: true); |
| + test(compiler, "TypeVar1", "TypeVar2", expect: true); |
| + test(compiler, "Function1a", "Function2a", expect: true); |
| + test(compiler, "Function1b", "Function2b", expect: true); |
| + test(compiler, "Typedef1a", "Typedef2a", expect: true); |
| + test(compiler, "Typedef1b", "Typedef2b", expect: true); |
| + test(compiler, "Typedef1c", "Typedef2c", expect: true); |
| + |
| + test(compiler, "void1", "int1", expect: false); |
| + test(compiler, "int1", "String1", expect: false); |
| + test(compiler, "String1", "ListInt1", expect: false); |
| + test(compiler, "ListInt1", "ListString1", expect: false); |
| + test(compiler, "ListString1", "MapIntString1", expect: false); |
| + test(compiler, "MapIntString1", "TypeVar1", expect: false); |
| + test(compiler, "TypeVar1", "Function1a", expect: false); |
| + test(compiler, "Function1a", "Function1b", expect: false); |
| + test(compiler, "Function1b", "Typedef1a", expect: false); |
| + test(compiler, "Typedef1a", "Typedef1b", expect: false); |
| + test(compiler, "Typedef1b", "Typedef1c", expect: false); |
| +} |