OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Test that Null is a subtype of any other type. | 5 // Test that Null is a subtype of any other type. |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 | 8 |
9 class A {} | 9 class A {} |
10 typedef A ReturnA(); | 10 typedef A ReturnA(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 takeNullFunc(Null n) {} | 76 takeNullFunc(Null n) {} |
77 A returnAFunc() => null; | 77 A returnAFunc() => null; |
78 takeAFunc(A a) {} | 78 takeAFunc(A a) {} |
79 | 79 |
80 main() { | 80 main() { |
81 var n = null; | 81 var n = null; |
82 var listNull = new List<Null>(); | 82 var listNull = new List<Null>(); |
83 var a = new A(); | 83 var a = new A(); |
84 var listA = new List<A>(); | 84 var listA = new List<A>(); |
85 | 85 |
86 testA(n); /// 01: ok | 86 testA(n); //# 01: ok |
87 testA(a); /// 02: ok | 87 testA(a); //# 02: ok |
88 testListA(listNull); /// 03: ok | 88 testListA(listNull); //# 03: ok |
89 testListA(listA); /// 04: ok | 89 testListA(listA); //# 04: ok |
90 Expect.isTrue(testIsListA(listNull)); /// 05: ok | 90 Expect.isTrue(testIsListA(listNull)); //# 05: ok |
91 Expect.isTrue(testIsListA(listA)); /// 06: ok | 91 Expect.isTrue(testIsListA(listA)); //# 06: ok |
92 testAsListA(listNull); /// 07: ok | 92 testAsListA(listNull); //# 07: ok |
93 testAsListA(listA); /// 08: ok | 93 testAsListA(listA); //# 08: ok |
94 | 94 |
95 testNull(n); /// 09: ok | 95 testNull(n); //# 09: ok |
96 testNull(a); /// 10: dynamic type error | 96 testNull(a); //# 10: dynamic type error |
97 testListNull(listNull); /// 11: ok | 97 testListNull(listNull); //# 11: ok |
98 testListNull(listA); /// 12: dynamic type error | 98 testListNull(listA); //# 12: dynamic type error |
99 Expect.isTrue(testIsListNull(listNull)); /// 13: ok | 99 Expect.isTrue(testIsListNull(listNull)); //# 13: ok |
100 Expect.isFalse(testIsListNull(listA)); /// 14: ok | 100 Expect.isFalse(testIsListNull(listA)); //# 14: ok |
101 testAsListNull(listNull); /// 15: ok | 101 testAsListNull(listNull); //# 15: ok |
102 Expect.throws(() => testAsListNull(listA), (e) => e is CastError); /// 16: ok | 102 Expect.throws(() => testAsListNull(listA), (e) => e is CastError); //# 16: ok |
103 | 103 |
104 var returnNull = returnNullFunc; | 104 var returnNull = returnNullFunc; |
105 var takeNull = takeNullFunc; | 105 var takeNull = takeNullFunc; |
106 var returnA = returnAFunc; | 106 var returnA = returnAFunc; |
107 var takeA = takeAFunc; | 107 var takeA = takeAFunc; |
108 | 108 |
109 testReturnA(returnA); /// 17: ok | 109 testReturnA(returnA); //# 17: ok |
110 testReturnA(returnNull); /// 18: ok | 110 testReturnA(returnNull); //# 18: ok |
111 Expect.isTrue(testIsReturnA(returnA)); /// 19: ok | 111 Expect.isTrue(testIsReturnA(returnA)); //# 19: ok |
112 Expect.isTrue(testIsReturnA(returnNull)); /// 20: ok | 112 Expect.isTrue(testIsReturnA(returnNull)); //# 20: ok |
113 testAsReturnA(returnA); /// 21: ok | 113 testAsReturnA(returnA); //# 21: ok |
114 testAsReturnA(returnNull); /// 22: ok | 114 testAsReturnA(returnNull); //# 22: ok |
115 | 115 |
116 // This is not valid in strong-mode: ()->A <: ()->Null | 116 // This is not valid in strong-mode: ()->A <: ()->Null |
117 testReturnNull(returnA); /// 23: ok | 117 testReturnNull(returnA); //# 23: ok |
118 testReturnNull(returnNull); /// 24: ok | 118 testReturnNull(returnNull); //# 24: ok |
119 // This is not valid in strong-mode: ()->A <: ()->Null | 119 // This is not valid in strong-mode: ()->A <: ()->Null |
120 Expect.isTrue(testIsReturnNull(returnA)); /// 25: ok | 120 Expect.isTrue(testIsReturnNull(returnA)); //# 25: ok |
121 Expect.isTrue(testIsReturnNull(returnNull)); /// 26: ok | 121 Expect.isTrue(testIsReturnNull(returnNull)); //# 26: ok |
122 // This is not valid in strong-mode: ()->A <: ()->Null | 122 // This is not valid in strong-mode: ()->A <: ()->Null |
123 testAsReturnNull(returnA); /// 27: ok | 123 testAsReturnNull(returnA); //# 27: ok |
124 testAsReturnNull(returnNull); /// 28: ok | 124 testAsReturnNull(returnNull); //# 28: ok |
125 | 125 |
126 testTakeA(takeA); /// 29: ok | 126 testTakeA(takeA); //# 29: ok |
127 // This is not valid in strong-mode: (Null)-> <: (A)-> | 127 // This is not valid in strong-mode: (Null)-> <: (A)-> |
128 testTakeA(takeNull); /// 30: ok | 128 testTakeA(takeNull); //# 30: ok |
129 Expect.isTrue(testIsTakeA(takeA)); /// 31: ok | 129 Expect.isTrue(testIsTakeA(takeA)); //# 31: ok |
130 // This is not valid in strong-mode: (Null)-> <: (A)-> | 130 // This is not valid in strong-mode: (Null)-> <: (A)-> |
131 Expect.isTrue(testIsTakeA(takeNull)); /// 32: ok | 131 Expect.isTrue(testIsTakeA(takeNull)); //# 32: ok |
132 testAsTakeA(takeA); /// 33: ok | 132 testAsTakeA(takeA); //# 33: ok |
133 // This is not valid in strong-mode: (Null)-> <: (A)-> | 133 // This is not valid in strong-mode: (Null)-> <: (A)-> |
134 testAsTakeA(takeNull); /// 34: ok | 134 testAsTakeA(takeNull); //# 34: ok |
135 | 135 |
136 testTakeNull(takeA); /// 35: ok | 136 testTakeNull(takeA); //# 35: ok |
137 testTakeNull(takeNull); /// 36: ok | 137 testTakeNull(takeNull); //# 36: ok |
138 Expect.isTrue(testIsTakeNull(takeA)); /// 37: ok | 138 Expect.isTrue(testIsTakeNull(takeA)); //# 37: ok |
139 Expect.isTrue(testIsTakeNull(takeNull)); /// 38: ok | 139 Expect.isTrue(testIsTakeNull(takeNull)); //# 38: ok |
140 testAsTakeNull(takeA); /// 39: ok | 140 testAsTakeNull(takeA); //# 39: ok |
141 testAsTakeNull(takeNull); /// 40: ok | 141 testAsTakeNull(takeNull); //# 40: ok |
142 } | 142 } |
OLD | NEW |