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

Unified Diff: tests/language/function_subtype_checked0_test.dart

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix Created 7 years, 6 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
Index: tests/language/function_subtype_checked0_test.dart
diff --git a/tests/language/function_subtype_checked0_test.dart b/tests/language/function_subtype_checked0_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ee293d62b654d259af9a6d1452f951b11c3a957a
--- /dev/null
+++ b/tests/language/function_subtype_checked0_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2013, 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.
+// Dart test program for constructors and initializers.
+
+// Check function subtyping of typedef vs. inlined function types.
+
+import 'package:expect/expect.dart';
+
+typedef int Foo<T>(T a, [String b]);
+typedef int Bar<T>(T a, [String b]);
+typedef int Baz<T>(T a, {String b});
+typedef int Boz<T>(T a);
+
+int foo(bool a, [String b]) => null;
+int baz(bool a, {String b}) => null;
+int boz(bool a, {int b}) => null;
+
+class C<T> {
+ void test1a(Foo<T> f) {}
+ void test1b(Bar<T> f) {}
+ void test1c(int f(T a, [String b])) {}
+
+ void test2a(Baz<T> f) {}
+ void test2b(int f(T a, {String b})) {}
+
+ void test3a(Boz<T> f) {}
+ void test3b(int f(T a)) {}
+
+ void test(String nameOfT, bool expectedResult) {
+ check(bool expectedResult, f()) {
+ if (inCheckedMode() && !expectedResult) {
+ Expect.throws(f, (e) => true);
+ } else {
+ f();
+ }
+ }
+
+ check(expectedResult, () => test1a(foo));
+ check(expectedResult, () => test1b(foo));
+ check(expectedResult, () => test1b(foo));
+ check(false, () => test2a(foo));
+ check(false, () => test2b(foo));
+ check(expectedResult, () => test3a(foo));
+ check(expectedResult, () => test3b(foo));
+
+ check(false, () => test1a(baz));
+ check(false, () => test1b(baz));
+ check(false, () => test1b(baz));
+ check(expectedResult, () => test2a(baz));
+ check(expectedResult, () => test2b(baz));
+ check(expectedResult, () => test3a(baz));
+ check(expectedResult, () => test3b(baz));
+
+ check(false, () => test1a(boz));
+ check(false, () => test1b(boz));
+ check(false, () => test1b(boz));
+ check(false, () => test2a(boz));
+ check(false, () => test2b(boz));
+ check(expectedResult, () => test3a(boz));
+ check(expectedResult, () => test3b(boz));
+ }
+}
+
+main() {
+ new C<bool>().test('bool', true);
+ new C<int>().test('int', false);
+ new C().test('dynamic', true);
+}
+
+bool inCheckedMode() {
+ try {
+ var x = 42;
+ String a = x;
+ } catch (e) {
+ return true;
+ }
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698