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

Side by Side Diff: tests/language/function_subtype_top_level1_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, 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
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4 // Dart test program for constructors and initializers.
5
6 // Check function subtyping for top level functions.
7
8 import 'package:expect/expect.dart';
9
10 typedef int Foo<T>(T a, [String b]);
11 typedef int Bar<T>(T a, [String b]);
12 typedef int Baz<T>(T a, {String b});
13 typedef int Boz<T>(T a);
14
15 int foo(bool a, [String b]) => null;
16 int baz(bool a, {String b}) => null;
17 int boz(bool a, {int b}) => null;
18
19 class C<T> {
20 void test(String nameOfT, bool expectedResult) {
21 Expect.equals(expectedResult, foo is Foo<T>, 'foo is Foo<$nameOfT>');
22 Expect.equals(expectedResult, foo is Bar<T>, 'foo is Bar<$nameOfT>');
23 Expect.isFalse(foo is Baz<T>, 'foo is Baz<$nameOfT>');
24 Expect.equals(expectedResult, foo is Boz<T>, 'foo is Boz<$nameOfT>');
25
26 Expect.isFalse(baz is Foo<T>, 'foo is Foo<$nameOfT>');
27 Expect.isFalse(baz is Bar<T>, 'foo is Bar<$nameOfT>');
28 Expect.equals(expectedResult, baz is Baz<T>, 'foo is Baz<$nameOfT>');
29 Expect.equals(expectedResult, baz is Boz<T>, 'foo is Boz<$nameOfT>');
30
31 Expect.isFalse(boz is Foo<T>, 'foo is Foo<$nameOfT>');
32 Expect.isFalse(boz is Bar<T>, 'foo is Bar<$nameOfT>');
33 Expect.isFalse(boz is Baz<T>, 'foo is Baz<$nameOfT>');
34 Expect.equals(expectedResult, boz is Boz<T>, 'foo is Boz<$nameOfT>');
35 }
36 }
37
38 main() {
39 new C<bool>().test('bool', true);
40 new C<int>().test('int', false);
41 new C().test('dynamic', true);
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698