| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Tests that malformed types are handled as dynamic, and that types with the | 5 // Tests that malformed types are handled as dynamic, and that types with the |
| 6 // wrong number of type arguments are handled as raw types. | 6 // wrong number of type arguments are handled as raw types. |
| 7 | 7 |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 import 'package:expect/expect.dart' as prefix; // Define 'prefix'. | 9 import 'package:expect/expect.dart' as prefix; // Define 'prefix'. |
| 10 | 10 |
| 11 checkIsUnresolved(var v) { | 11 checkIsUnresolved(var v) { |
| 12 Expect.isTrue(v is Unresolved); | 12 Expect.throws(() => v is Unresolved, (e) => e is TypeError); |
| 13 Expect.isTrue(v is Unresolved<int>); | 13 Expect.throws(() => v is Unresolved<int>, (e) => e is TypeError); |
| 14 Expect.isTrue(v is prefix.Unresolved); | 14 Expect.throws(() => v is prefix.Unresolved, (e) => e is TypeError); |
| 15 Expect.isTrue(v is prefix.Unresolved<int>); | 15 Expect.throws(() => v is prefix.Unresolved<int>, (e) => e is TypeError); |
| 16 } | 16 } |
| 17 | 17 |
| 18 checkIsListUnresolved(bool expect, var v) { | 18 checkIsListUnresolved(bool expect, var v) { |
| 19 Expect.equals(expect, v is List<Unresolved>); | 19 Expect.equals(expect, v is List<Unresolved>); |
| 20 Expect.equals(expect, v is List<Unresolved<int>>); | 20 Expect.equals(expect, v is List<Unresolved<int>>); |
| 21 Expect.equals(expect, v is List<prefix.Unresolved>); | 21 Expect.equals(expect, v is List<prefix.Unresolved>); |
| 22 Expect.equals(expect, v is List<prefix.Unresolved<int>>); | 22 Expect.equals(expect, v is List<prefix.Unresolved<int>>); |
| 23 Expect.equals(expect, v is List<int, String>); | 23 Expect.equals(expect, v is List<int, String>); |
| 24 } | 24 } |
| 25 | 25 |
| 26 checkIsListDynamic(bool expect, var v) { | 26 checkIsListDynamic(bool expect, var v) { |
| 27 checkIsListUnresolved(true, v); | 27 checkIsListUnresolved(true, v); |
| 28 Expect.equals(expect, v is List<int> && v is List<String>); | 28 Expect.equals(expect, v is List<int> && v is List<String>); |
| 29 } | 29 } |
| 30 | 30 |
| 31 checkAsUnresolved(var v) { | 31 checkAsUnresolved(var v) { |
| 32 Expect.equals(v, v as Unresolved); | 32 Expect.throws(() => v as Unresolved, (e) => e is TypeError); |
| 33 Expect.equals(v, v as Unresolved<int>); | 33 Expect.throws(() => v as Unresolved<int>, (e) => e is TypeError); |
| 34 Expect.equals(v, v as prefix.Unresolved); | 34 Expect.throws(() => v as prefix.Unresolved, (e) => e is TypeError); |
| 35 Expect.equals(v, v as prefix.Unresolved<int>); | 35 Expect.throws(() => v as prefix.Unresolved<int>, (e) => e is TypeError); |
| 36 } | 36 } |
| 37 | 37 |
| 38 checkAsListUnresolved(bool expect, var v) { | 38 checkAsListUnresolved(bool expect, var v) { |
| 39 if (expect) { | 39 if (expect) { |
| 40 Expect.equals(v, v as List<Unresolved>); | 40 Expect.equals(v, v as List<Unresolved>); |
| 41 Expect.equals(v, v as List<Unresolved<int>>); | 41 Expect.equals(v, v as List<Unresolved<int>>); |
| 42 Expect.equals(v, v as List<prefix.Unresolved>); | 42 Expect.equals(v, v as List<prefix.Unresolved>); |
| 43 Expect.equals(v, v as List<prefix.Unresolved<int>>); | 43 Expect.equals(v, v as List<prefix.Unresolved<int>>); |
| 44 Expect.equals(v, v as List<int, String>); | 44 Expect.equals(v, v as List<int, String>); |
| 45 } else { | 45 } else { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 Expect.throws(() => new prefix.Unresolved(), (e) => true); | 118 Expect.throws(() => new prefix.Unresolved(), (e) => true); |
| 119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); | 119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); |
| 120 | 120 |
| 121 // The expression 'undeclared_prefix.Unresolved()' is parsed as the invocation | 121 // The expression 'undeclared_prefix.Unresolved()' is parsed as the invocation |
| 122 // of the named constructor 'Unresolved' on the type 'undeclared_prefix'. | 122 // of the named constructor 'Unresolved' on the type 'undeclared_prefix'. |
| 123 Expect.throws(() => new undeclared_prefix.Unresolved(), (e) => true); | 123 Expect.throws(() => new undeclared_prefix.Unresolved(), (e) => true); |
| 124 // The expression 'undeclared_prefix.Unresolved<int>' cannot be parsed. | 124 // The expression 'undeclared_prefix.Unresolved<int>' cannot be parsed. |
| 125 Expect.throws(() => new undeclared_prefix.Unresolved<int>(), (e) => true); //
/ 05: compile-time error | 125 Expect.throws(() => new undeclared_prefix.Unresolved<int>(), (e) => true); //
/ 05: compile-time error |
| 126 | 126 |
| 127 try { | 127 try { |
| 128 throw 'foo'; | 128 try { |
| 129 } on Unresolved catch (e) { | 129 throw 'foo'; |
| 130 // Equivalent to 'on dynamic', catches 'foo'. | 130 } on Unresolved catch (e) { |
| 131 Expect.fail("This code shouldn't be executed"); |
| 132 } |
| 133 Expect.fail("This code shouldn't be executed"); |
| 134 } on TypeError catch (e) { |
| 135 } |
| 136 try { |
| 137 try { |
| 138 throw 'foo'; |
| 139 } on Unresolved<int> catch (e) { |
| 140 Expect.fail("This code shouldn't be executed"); |
| 141 } |
| 142 Expect.fail("This code shouldn't be executed"); |
| 143 } on TypeError catch (e) { |
| 144 } |
| 145 try { |
| 146 try { |
| 147 throw 'foo'; |
| 148 } on prefix.Unresolved catch (e) { |
| 149 Expect.fail("This code shouldn't be executed"); |
| 150 } |
| 151 Expect.fail("This code shouldn't be executed"); |
| 152 } on TypeError catch (e) { |
| 153 } |
| 154 try { |
| 155 try { |
| 156 throw 'foo'; |
| 157 } on prefix.Unresolved<int> catch (e) { |
| 158 Expect.fail("This code shouldn't be executed"); |
| 159 } |
| 160 Expect.fail("This code shouldn't be executed"); |
| 161 } on TypeError catch (e) { |
| 131 } | 162 } |
| 132 try { | 163 try { |
| 133 throw 'foo'; | 164 throw 'foo'; |
| 134 } on Unresolved<int> catch (e) { | |
| 135 // Equivalent to 'on dynamic', catches 'foo'. | |
| 136 } | |
| 137 try { | |
| 138 throw 'foo'; | |
| 139 } on prefix.Unresolved catch (e) { | |
| 140 // Equivalent to 'on dynamic', catches 'foo'. | |
| 141 } | |
| 142 try { | |
| 143 throw 'foo'; | |
| 144 } on prefix.Unresolved<int> catch (e) { | |
| 145 // Equivalent to 'on dynamic', catches 'foo'. | |
| 146 } | |
| 147 try { | |
| 148 throw 'foo'; | |
| 149 } | 165 } |
| 150 on undeclared_prefix.Unresolved<int> /// 06: compile-time error | 166 on undeclared_prefix.Unresolved<int> /// 06: compile-time error |
| 151 catch (e) { | 167 catch (e) { |
| 152 } | 168 } |
| 153 } | 169 } |
| OLD | NEW |