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: o
k |
87 testA(a); /// 02: ok | 87 testA(a); // /// 02: o
k |
88 testListA(listNull); /// 03: ok | 88 testListA(listNull); // /// 03: o
k |
89 testListA(listA); /// 04: ok | 89 testListA(listA); // /// 04: o
k |
90 Expect.isTrue(testIsListA(listNull)); /// 05: ok | 90 Expect.isTrue(testIsListA(listNull)); // /// 05: o
k |
91 Expect.isTrue(testIsListA(listA)); /// 06: ok | 91 Expect.isTrue(testIsListA(listA)); // /// 06: o
k |
92 testAsListA(listNull); /// 07: ok | 92 testAsListA(listNull); // /// 07: o
k |
93 testAsListA(listA); /// 08: ok | 93 testAsListA(listA); // /// 08: o
k |
94 | 94 |
95 testNull(n); /// 09: ok | 95 testNull(n); // /// 09: o
k |
96 testNull(a); /// 10: dynamic type error | 96 testNull(a); // /// 10: dynamic type erro
r |
97 testListNull(listNull); /// 11: ok | 97 testListNull(listNull); // /// 11: o
k |
98 testListNull(listA); /// 12: dynamic type error | 98 testListNull(listA); // /// 12: dynamic type erro
r |
99 Expect.isTrue(testIsListNull(listNull)); /// 13: ok | 99 Expect.isTrue(testIsListNull(listNull)); // /// 13: o
k |
100 Expect.isFalse(testIsListNull(listA)); /// 14: ok | 100 Expect.isFalse(testIsListNull(listA)); // /// 14: o
k |
101 testAsListNull(listNull); /// 15: ok | 101 testAsListNull(listNull); // /// 15: o
k |
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: o
k |
110 testReturnA(returnNull); /// 18: ok | 110 testReturnA(returnNull); // /// 18: o
k |
111 Expect.isTrue(testIsReturnA(returnA)); /// 19: ok | 111 Expect.isTrue(testIsReturnA(returnA)); // /// 19: o
k |
112 Expect.isTrue(testIsReturnA(returnNull)); /// 20: ok | 112 Expect.isTrue(testIsReturnA(returnNull)); // /// 20: o
k |
113 testAsReturnA(returnA); /// 21: ok | 113 testAsReturnA(returnA); // /// 21: o
k |
114 testAsReturnA(returnNull); /// 22: ok | 114 testAsReturnA(returnNull); // /// 22: o
k |
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: o
k |
118 testReturnNull(returnNull); /// 24: ok | 118 testReturnNull(returnNull); // /// 24: o
k |
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: o
k |
121 Expect.isTrue(testIsReturnNull(returnNull)); /// 26: ok | 121 Expect.isTrue(testIsReturnNull(returnNull)); // /// 26: o
k |
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: o
k |
124 testAsReturnNull(returnNull); /// 28: ok | 124 testAsReturnNull(returnNull); // /// 28: o
k |
125 | 125 |
126 testTakeA(takeA); /// 29: ok | 126 testTakeA(takeA); // /// 29: o
k |
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: o
k |
129 Expect.isTrue(testIsTakeA(takeA)); /// 31: ok | 129 Expect.isTrue(testIsTakeA(takeA)); // /// 31: o
k |
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: o
k |
132 testAsTakeA(takeA); /// 33: ok | 132 testAsTakeA(takeA); // /// 33: o
k |
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: o
k |
135 | 135 |
136 testTakeNull(takeA); /// 35: ok | 136 testTakeNull(takeA); // /// 35: o
k |
137 testTakeNull(takeNull); /// 36: ok | 137 testTakeNull(takeNull); // /// 36: o
k |
138 Expect.isTrue(testIsTakeNull(takeA)); /// 37: ok | 138 Expect.isTrue(testIsTakeNull(takeA)); // /// 37: o
k |
139 Expect.isTrue(testIsTakeNull(takeNull)); /// 38: ok | 139 Expect.isTrue(testIsTakeNull(takeNull)); // /// 38: o
k |
140 testAsTakeNull(takeA); /// 39: ok | 140 testAsTakeNull(takeA); // /// 39: o
k |
141 testAsTakeNull(takeNull); /// 40: ok | 141 testAsTakeNull(takeNull); // /// 40: o
k |
142 } | 142 } |
OLD | NEW |