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

Unified Diff: tests/language/null_is_bottom_test.dart

Issue 2587343006: Runtime support for Null as any in dart2js (Closed)
Patch Set: Update tests. Created 4 years 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 | « tests/language/language.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/null_is_bottom_test.dart
diff --git a/tests/language/null_is_bottom_test.dart b/tests/language/null_is_bottom_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7b0f2f8b1d098e68d14406106030a356cb06382b
--- /dev/null
+++ b/tests/language/null_is_bottom_test.dart
@@ -0,0 +1,142 @@
+// Copyright (c) 2016, 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.
+
+// Test that Null is a subtype of any other type.
+
+import 'package:expect/expect.dart';
+
+class A {}
+typedef A ReturnA();
+typedef TakeA(A a);
+typedef Null ReturnNull();
+typedef TakeNull(Null n);
+
+@NoInline()
+testA(A testAsListA) {}
+
+@NoInline()
+testListA(List<A> list) {}
+
+@NoInline()
+testIsListA(var a) => a is List<A>;
+
+@NoInline()
+testAsListA(var a) => a as List<A>;
+
+@NoInline()
+testNull(Null n) {}
+
+@NoInline()
+testListNull(List<Null> list) {}
+
+@NoInline()
+testIsListNull(var a) => a is List<Null>;
+
+@NoInline()
+testAsListNull(var a) => a as List<Null>;
+
+@NoInline()
+testReturnA(ReturnA f) {}
+
+@NoInline()
+testIsReturnA(var f) => f is ReturnA;
+
+@NoInline()
+testAsReturnA(var f) => f as ReturnA;
+
+@NoInline()
+testReturnNull(ReturnNull f) {}
+
+@NoInline()
+testIsReturnNull(var f) => f is ReturnNull;
+
+@NoInline()
+testAsReturnNull(var f) => f as ReturnNull;
+
+@NoInline()
+testTakeA(TakeA f) {}
+
+@NoInline()
+testIsTakeA(var f) => f is TakeA;
+
+@NoInline()
+testAsTakeA(var f) => f as TakeA;
+
+@NoInline()
+testTakeNull(TakeNull f) {}
+
+@NoInline()
+testIsTakeNull(var f) => f is TakeNull;
+
+@NoInline()
+testAsTakeNull(var f) => f as TakeNull;
+
+Null returnNullFunc() => null;
+takeNullFunc(Null n) {}
+A returnAFunc() => null;
+takeAFunc(A a) {}
+
+main() {
+ var n = null;
+ var listNull = new List<Null>();
+ var a = new A();
+ var listA = new List<A>();
+
+ testA(null); /// 01: ok
+ testA(a); /// 02: ok
+ testListA(listNull); /// 03: ok
+ testListA(listA); /// 04: ok
+ Expect.isTrue(testIsListA(listNull)); /// 05: ok
+ Expect.isTrue(testIsListA(listA)); /// 06: ok
+ testAsListA(listNull); /// 07: ok
+ testAsListA(listA); /// 08: ok
+
+ testNull(n); /// 09: ok
+ testNull(a); /// 10: dynamic type error
+ testListNull(listNull); /// 11: ok
+ testListNull(listA); /// 12: dynamic type error
+ Expect.isTrue(testIsListNull(listNull)); /// 13: ok
+ Expect.isFalse(testIsListNull(listA)); /// 14: ok
+ testAsListNull(listNull); /// 15: ok
+ Expect.throws(() => testAsListNull(listA), (e) => e is CastError); /// 16: ok
+
+ var returnNull = returnNullFunc;
+ var takeNull = takeNullFunc;
+ var returnA = returnAFunc;
+ var takeA = takeAFunc;
+
+ testReturnA(returnA); /// 17: ok
+ testReturnA(returnNull); /// 18: ok
+ Expect.isTrue(testIsReturnA(returnA)); /// 19: ok
+ Expect.isTrue(testIsReturnA(returnNull)); /// 20: ok
+ testAsReturnA(returnA); /// 21: ok
+ testAsReturnA(returnNull); /// 22: ok
+
+ // This is not valid in strong-mode: ()->A <: ()->Null
+ testReturnNull(returnA); /// 23: ok
+ testReturnNull(returnNull); /// 24: ok
+ // This is not valid in strong-mode: ()->A <: ()->Null
+ Expect.isTrue(testIsReturnNull(returnA)); /// 25: ok
+ Expect.isTrue(testIsReturnNull(returnNull)); /// 26: ok
+ // This is not valid in strong-mode: ()->A <: ()->Null
+ testAsReturnNull(returnA); /// 27: ok
+ testAsReturnNull(returnNull); /// 28: ok
+
+ testTakeA(takeA); /// 29: ok
+ // This is not valid in strong-mode: (Null)-> <: (A)->
+ testTakeA(takeNull); /// 30: ok
+ Expect.isTrue(testIsTakeA(takeA)); /// 31: ok
+ // This is not valid in strong-mode: (Null)-> <: (A)->
+ Expect.isTrue(testIsTakeA(takeNull)); /// 32: ok
+ testAsTakeA(takeA); /// 33: ok
+ // This is not valid in strong-mode: (Null)-> <: (A)->
+ testAsTakeA(takeNull); /// 34: ok
+
+ testTakeNull(takeA); /// 35: ok
+ testTakeNull(takeNull); /// 36: ok
+ Expect.isTrue(testIsTakeNull(takeA)); /// 37: ok
+ Expect.isTrue(testIsTakeNull(takeNull)); /// 38: ok
+ testAsTakeNull(takeA); /// 39: ok
+ testAsTakeNull(takeNull); /// 40: ok
+}
« no previous file with comments | « tests/language/language.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698