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

Unified Diff: tests/compiler/dart2js/type_equals_test.dart

Issue 10917290: DartType equals converted to operator == and tested. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/util/link_implementation.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f047570253d5c29fb6b0b37e34eee0951d195de0
--- /dev/null
+++ b/tests/compiler/dart2js/type_equals_test.dart
@@ -0,0 +1,118 @@
+// 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("compiler_helper.dart");
+#import("parser_helper.dart");
+#import("dart:uri");
+
+bool test(compiler, String name1, String name2, {bool expect}) {
+ Expect.isTrue(?expect, 'required parameter "expect" not given');
+ var clazz = findElement(compiler, "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.kind === ElementKind.FUNCTION);
+ Expect.isTrue(element2.kind === ElementKind.FUNCTION);
+ FunctionSignature signature1 = element1.computeSignature(compiler);
+ FunctionSignature signature2 = element2.computeSignature(compiler);
+
+ // Function signatures are used to be to provide void types (only occuring as
+ // as return types) and (inlined) function types (only occuring as method
+ // parameter types).
+ //
+ // Only a single type is used from each signature. That is, it is not the
+ // intention to check the whole signatures against eachother.
+ DartType type1;
+ DartType type2;
+ if (signature1.requiredParameterCount == 0) {
+ // If parameters is empty, use return type.
+ type1 = signature1.returnType;
+ } else {
+ // Otherwise use the first argument type.
+ type1 = signature1.requiredParameters.head.computeType(compiler);
+ }
+ if (signature2.requiredParameterCount == 0) {
+ // If parameters is empty, use return type.
+ type2 = signature2.returnType;
+ } else {
+ // Otherwise use the first argument type.
+ type2 = signature2.requiredParameters.head.computeType(compiler);
+ }
+ if (expect) {
+ Expect.equals(type1, type2, "$type1 != $type2");
+ } else {
+ Expect.notEquals(type1, type2, "$type1 == $type2");
+ }
+}
+
+void main() {
+ var uri = new Uri.fromComponents(scheme: 'source');
+ var compiler = compilerFor(
+ @"""
+ 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) {}
+ }
+
+ void main() {}
+ """,
+ uri);
+ compiler.runCompiler(uri);
+
+ 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);
+}
« no previous file with comments | « lib/compiler/implementation/util/link_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698