| 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.throws(() => v is Unresolved, (e) => e is TypeError); | 12 Expect.throws(() => v is Unresolved, (e) => e is TypeError); |
| 13 Expect.throws(() => v is Unresolved<int>, (e) => e is TypeError); | 13 Expect.throws(() => v is Unresolved<int>, (e) => e is TypeError); |
| 14 Expect.throws(() => v is prefix.Unresolved, (e) => e is TypeError); | 14 Expect.throws(() => v is prefix.Unresolved, (e) => e is TypeError); |
| 15 Expect.throws(() => v is prefix.Unresolved<int>, (e) => e is TypeError); | 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>); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 { |
| 46 Expect.throws(() => v as List<Unresolved>, (e) => e is CastError); | 46 Expect.throws(() => v as List<Unresolved>, (e) => e is CastError); |
| 47 Expect.throws(() => v as List<Unresolved<int>>, (e) => e is CastError); | 47 Expect.throws(() => v as List<Unresolved<int>>, (e) => e is CastError); |
| 48 Expect.throws(() => v as List<prefix.Unresolved>, (e) => e is CastError); | 48 Expect.throws(() => v as List<prefix.Unresolved>, (e) => e is CastError); |
| 49 Expect.throws(() => v as List<prefix.Unresolved<int>>, | 49 Expect.throws( |
| 50 (e) => e is CastError); | 50 () => v as List<prefix.Unresolved<int>>, (e) => e is CastError); |
| 51 Expect.throws(() => v as List<int, String>, (e) => e is CastError); | 51 Expect.throws(() => v as List<int, String>, (e) => e is CastError); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 checkIsMapDynamic(bool first, bool second, var v) { | 55 checkIsMapDynamic(bool first, bool second, var v) { |
| 56 Expect.equals(first, v is Map<String, Object> && v is Map<int, Object>); | 56 Expect.equals(first, v is Map<String, Object> && v is Map<int, Object>); |
| 57 Expect.equals(second, v is Map<Object, int> && v is Map<Object, String>); | 57 Expect.equals(second, v is Map<Object, int> && v is Map<Object, String>); |
| 58 } | 58 } |
| 59 | 59 |
| 60 | |
| 61 void main() { | 60 void main() { |
| 62 checkIsUnresolved(''); | 61 checkIsUnresolved(''); |
| 63 checkIsUnresolved(0); | 62 checkIsUnresolved(0); |
| 64 checkIsListUnresolved(false, ''); | 63 checkIsListUnresolved(false, ''); |
| 65 checkIsListUnresolved(true, new List()); | 64 checkIsListUnresolved(true, new List()); |
| 66 checkIsListUnresolved(true, new List<int>()); | 65 checkIsListUnresolved(true, new List<int>()); |
| 67 checkIsListUnresolved(true, new List<String>()); | 66 checkIsListUnresolved(true, new List<String>()); |
| 68 checkIsListUnresolved(true, new List<int, String>()); | 67 checkIsListUnresolved(true, new List<int, String>()); |
| 69 | 68 |
| 70 checkAsUnresolved(''); | 69 checkAsUnresolved(''); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 checkIsListDynamic(true, new List<int, String>()); | 92 checkIsListDynamic(true, new List<int, String>()); |
| 94 | 93 |
| 95 checkIsMapDynamic(true, true, <dynamic, dynamic>{}); | 94 checkIsMapDynamic(true, true, <dynamic, dynamic>{}); |
| 96 checkIsMapDynamic(true, true, {}); | 95 checkIsMapDynamic(true, true, {}); |
| 97 checkIsMapDynamic(true, true, <>{}); //# 03: compile-time error | 96 checkIsMapDynamic(true, true, <>{}); //# 03: compile-time error |
| 98 checkIsMapDynamic(true, true, <int>{}); | 97 checkIsMapDynamic(true, true, <int>{}); |
| 99 checkIsMapDynamic(false, false, <String, int>{}); | 98 checkIsMapDynamic(false, false, <String, int>{}); |
| 100 checkIsMapDynamic(true, true, <String, int, String>{}); | 99 checkIsMapDynamic(true, true, <String, int, String>{}); |
| 101 checkIsMapDynamic(true, false, <Unresolved, int>{}); | 100 checkIsMapDynamic(true, false, <Unresolved, int>{}); |
| 102 checkIsMapDynamic(false, true, <String, Unresolved<int>>{}); | 101 checkIsMapDynamic(false, true, <String, Unresolved<int>>{}); |
| 103 checkIsMapDynamic(true, false, <prefix.Unresolved, int>{}); | 102 checkIsMapDynamic(true, false, <prefix.Unresolved, int>{}); |
| 104 checkIsMapDynamic(false, true, <String, prefix.Unresolved<int>>{}); | 103 checkIsMapDynamic(false, true, <String, prefix.Unresolved<int>>{}); |
| 105 | 104 |
| 106 checkIsMapDynamic(true, true, new Map()); | 105 checkIsMapDynamic(true, true, new Map()); |
| 107 checkIsMapDynamic(true, true, new Map<>); //# 04: compile-time error | 106 checkIsMapDynamic(true, true, new Map<>); //# 04: compile-time error |
| 108 checkIsMapDynamic(true, true, new Map<int>()); | 107 checkIsMapDynamic(true, true, new Map<int>()); |
| 109 checkIsMapDynamic(false, false, new Map<String, int>()); | 108 checkIsMapDynamic(false, false, new Map<String, int>()); |
| 110 checkIsMapDynamic(true, true, new Map<String, int, String>()); | 109 checkIsMapDynamic(true, true, new Map<String, int, String>()); |
| 111 checkIsMapDynamic(true, false, new Map<Unresolved, int>()); | 110 checkIsMapDynamic(true, false, new Map<Unresolved, int>()); |
| 112 checkIsMapDynamic(false, true, new Map<String, Unresolved<int>>()); | 111 checkIsMapDynamic(false, true, new Map<String, Unresolved<int>>()); |
| 113 checkIsMapDynamic(true, false, new Map<prefix.Unresolved, int>()); | 112 checkIsMapDynamic(true, false, new Map<prefix.Unresolved, int>()); |
| 114 checkIsMapDynamic(false, true, new Map<String, prefix.Unresolved<int>>()); | 113 checkIsMapDynamic(false, true, new Map<String, prefix.Unresolved<int>>()); |
| 115 | 114 |
| 116 Expect.throws(() => new Unresolved(), (e) => true); | 115 Expect.throws(() => new Unresolved(), (e) => true); |
| 117 Expect.throws(() => new Unresolved<int>(), (e) => true); | 116 Expect.throws(() => new Unresolved<int>(), (e) => true); |
| 118 Expect.throws(() => new prefix.Unresolved(), (e) => true); | 117 Expect.throws(() => new prefix.Unresolved(), (e) => true); |
| 119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); | 118 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); |
| 120 | 119 |
| 121 // The expression 'undeclared_prefix.Unresolved()' is parsed as the invocation | 120 // The expression 'undeclared_prefix.Unresolved()' is parsed as the invocation |
| 122 // of the named constructor 'Unresolved' on the type 'undeclared_prefix'. | 121 // of the named constructor 'Unresolved' on the type 'undeclared_prefix'. |
| 123 Expect.throws(() => new undeclared_prefix.Unresolved(), (e) => true); | 122 Expect.throws(() => new undeclared_prefix.Unresolved(), (e) => true); |
| 124 // The expression 'undeclared_prefix.Unresolved<int>' is a malformed type. | 123 // The expression 'undeclared_prefix.Unresolved<int>' is a malformed type. |
| 125 Expect.throws(() => new undeclared_prefix.Unresolved<int>(), (e) => true); | 124 Expect.throws(() => new undeclared_prefix.Unresolved<int>(), (e) => true); |
| 126 | 125 |
| 127 try { | 126 try { |
| 128 try { | 127 try { |
| 129 throw 'foo'; | 128 throw 'foo'; |
| 130 } on Unresolved catch (e) { | 129 } on Unresolved catch (e) { |
| 131 Expect.fail("This code shouldn't be executed"); | 130 Expect.fail("This code shouldn't be executed"); |
| 132 } | 131 } |
| 133 Expect.fail("This code shouldn't be executed"); | 132 Expect.fail("This code shouldn't be executed"); |
| 134 } on TypeError catch (e) { | 133 } on TypeError catch (e) {} |
| 135 } | |
| 136 try { | 134 try { |
| 137 try { | 135 try { |
| 138 throw 'foo'; | 136 throw 'foo'; |
| 139 } on Unresolved<int> catch (e) { | 137 } on Unresolved<int> catch (e) { |
| 140 Expect.fail("This code shouldn't be executed"); | 138 Expect.fail("This code shouldn't be executed"); |
| 141 } | 139 } |
| 142 Expect.fail("This code shouldn't be executed"); | 140 Expect.fail("This code shouldn't be executed"); |
| 143 } on TypeError catch (e) { | 141 } on TypeError catch (e) {} |
| 144 } | |
| 145 try { | 142 try { |
| 146 try { | 143 try { |
| 147 throw 'foo'; | 144 throw 'foo'; |
| 148 } on prefix.Unresolved catch (e) { | 145 } on prefix.Unresolved catch (e) { |
| 149 Expect.fail("This code shouldn't be executed"); | 146 Expect.fail("This code shouldn't be executed"); |
| 150 } | 147 } |
| 151 Expect.fail("This code shouldn't be executed"); | 148 Expect.fail("This code shouldn't be executed"); |
| 152 } on TypeError catch (e) { | 149 } on TypeError catch (e) {} |
| 153 } | |
| 154 try { | 150 try { |
| 155 try { | 151 try { |
| 156 throw 'foo'; | 152 throw 'foo'; |
| 157 } on prefix.Unresolved<int> catch (e) { | 153 } on prefix.Unresolved<int> catch (e) { |
| 158 Expect.fail("This code shouldn't be executed"); | 154 Expect.fail("This code shouldn't be executed"); |
| 159 } | 155 } |
| 160 Expect.fail("This code shouldn't be executed"); | 156 Expect.fail("This code shouldn't be executed"); |
| 161 } on TypeError catch (e) { | 157 } on TypeError catch (e) {} |
| 162 } | |
| 163 try { | 158 try { |
| 164 throw 'foo'; | 159 throw 'foo'; |
| 165 } | 160 } |
| 166 on undeclared_prefix.Unresolved<int> // //# 06: runtime error | 161 on undeclared_prefix.Unresolved<int> // //# 06: runtime error |
| 167 catch (e) { | 162 catch (e) {} |
| 168 } | 163 } |
| 169 } | |
| OLD | NEW |