Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: tests/language/malformed_test.dart

Issue 19097003: Support new malformed types semantics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix unittests. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
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.
7
8 import 'package:expect/expect.dart';
9
10 checkIsUnresolved(var v) {
11 Expect.isTrue(v is Unresolved);
12 Expect.isTrue(v is Unresolved<int>);
13 Expect.isTrue(v is prefix.Unresolved);
14 Expect.isTrue(v is prefix.Unresolved<int>);
15 }
16
17 checkIsListUnresolved(bool expect, var v) {
18 Expect.equals(expect, v is List<Unresolved>);
19 Expect.equals(expect, v is List<Unresolved<int>>);
20 Expect.equals(expect, v is List<prefix.Unresolved>);
21 Expect.equals(expect, v is List<prefix.Unresolved<int>>);
22 Expect.equals(expect, v is List<int, String>);
23 }
24
25 checkIsListDynamic(bool expect, var v) {
26 checkIsListUnresolved(true, v);
27 Expect.equals(expect, v is List<int> && v is List<String>);
28 }
29
30 checkAsUnresolved(var v) {
31 Expect.equals(v, v as Unresolved);
32 Expect.equals(v, v as Unresolved<int>);
33 Expect.equals(v, v as prefix.Unresolved);
34 Expect.equals(v, v as prefix.Unresolved<int>);
35 }
36
37 checkAsListUnresolved(bool expect, var v) {
38 if (expect) {
39 Expect.equals(v, v as List<Unresolved>);
40 Expect.equals(v, v as List<Unresolved<int>>);
41 Expect.equals(v, v as List<prefix.Unresolved>);
42 Expect.equals(v, v as List<prefix.Unresolved<int>>);
43 Expect.equals(v, v as List<int, String>);
44 } else {
45 Expect.throws(() => v as List<Unresolved>, (e) => e is CastError);
46 Expect.throws(() => v as List<Unresolved<int>>, (e) => e is CastError);
47 Expect.throws(() => v as List<prefix.Unresolved>, (e) => e is CastError);
48 Expect.throws(() => v as List<prefix.Unresolved<int>>,
49 (e) => e is CastError);
50 Expect.throws(() => v as List<int, String>, (e) => e is CastError);
51 }
52 }
53
54 checkIsMapDynamic(bool first, bool second, var v) {
55 Expect.equals(first, v is Map<String, Object> && v is Map<int, Object>);
56 Expect.equals(second, v is Map<Object, int> && v is Map<Object, String>);
57 }
58
59
60 void main() {
61 checkIsUnresolved('');
62 checkIsUnresolved(0);
63 checkIsListUnresolved(false, '');
64 checkIsListUnresolved(true, new List());
65 checkIsListUnresolved(true, new List<int>());
66 checkIsListUnresolved(true, new List<String>());
67 checkIsListUnresolved(true, new List<int, String>());
68
69 checkAsUnresolved('');
70 checkAsUnresolved(0);
71 checkAsListUnresolved(false, '');
72 checkAsListUnresolved(true, new List());
73 checkAsListUnresolved(true, new List<int>());
74 checkAsListUnresolved(true, new List<String>());
75 checkAsListUnresolved(true, new List<int, String>());
76
77 checkIsListDynamic(true, []);
78 checkIsListDynamic(true, <>[]); /// 01: compile-time error
79 // TODO(johnniwinther): Create runtime type information on literal lists.
80 // checkIsListDynamic(false, <int>[]);
81 checkIsListDynamic(true, <Unresolved>[]);
82 checkIsListDynamic(true, <Unresolved<int>>[]);
83 checkIsListDynamic(true, <prefix.Unresolved>[]);
84 checkIsListDynamic(true, <prefix.Unresolved<int>>[]);
85 checkIsListDynamic(true, <int, String>[]);
86
87 checkIsListDynamic(true, new List());
88 checkIsListDynamic(true, new List<>()); /// 02: compile-time error
89 checkIsListDynamic(true, new List<Unresolved>());
90 checkIsListDynamic(true, new List<Unresolved<int>>());
91 checkIsListDynamic(true, new List<prefix.Unresolved>());
92 checkIsListDynamic(true, new List<prefix.Unresolved<int>>());
93 checkIsListDynamic(true, new List<int, String>());
94
95 checkIsMapDynamic(true, true, {});
96 checkIsMapDynamic(true, true, <>{}); /// 03: compile-time error
97 checkIsMapDynamic(true, true, <int>{});
98 // TODO(johnniwinther): Create runtime type information on literal maps.
99 // checkIsMapDynamic(false, false, <String, int>{});
100 checkIsMapDynamic(true, true, <String, int, String>{});
101 // checkIsMapDynamic(true, false, <Unresolved, int>{});
102 // checkIsMapDynamic(false, true, <String, Unresolved<int>>{});
103 // checkIsMapDynamic(true, false, <prefix.Unresolved, int>{});
104 // checkIsMapDynamic(false, true, <String, prefix.Unresolved<int>>{});
105
106 checkIsMapDynamic(true, true, new Map());
107 checkIsMapDynamic(true, true, new Map<>); /// 04: compile-time error
108 checkIsMapDynamic(true, true, new Map<int>());
109 checkIsMapDynamic(false, false, new Map<String, int>());
110 checkIsMapDynamic(true, true, new Map<String, int, String>());
111 checkIsMapDynamic(true, false, new Map<Unresolved, int>());
112 checkIsMapDynamic(false, true, new Map<String, Unresolved<int>>());
113 checkIsMapDynamic(true, false, new Map<prefix.Unresolved, int>());
114 checkIsMapDynamic(false, true, new Map<String, prefix.Unresolved<int>>());
115
116 Expect.throws(() => new Unresolved(), (e) => true);
117 Expect.throws(() => new Unresolved<int>(), (e) => true);
118 Expect.throws(() => new prefix.Unresolved(), (e) => true);
119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true);
120
121 try {
122 throw 'foo';
123 } on Unresolved catch (e) {
124 } catch (e) {
125 Expect.fail();
126 }
127 try {
128 throw 'foo';
129 } on Unresolved<int> catch (e) {
130 } catch (e) {
131 Expect.fail();
132 }
133 try {
134 throw 'foo';
135 } on prefix.Unresolved catch (e) {
136 } catch (e) {
137 Expect.fail();
138 }
139 try {
140 throw 'foo';
141 } on prefix.Unresolved<int> catch (e) {
142 } catch (e) {
143 Expect.fail();
144 }
145 }
OLDNEW
« no previous file with comments | « tests/language/malformed_inheritance_test.dart ('k') | tests/language/new_expression_type_args_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698