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