OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 of hash set type checking. | |
6 | |
7 library hash_set_type_check_test; | |
8 | |
9 import "package:expect/expect.dart"; | |
10 import 'dart:collection'; | |
11 | |
12 testSet(Set<String> newSet()) { | |
13 Set<String> s = newSet(); | |
14 Expect.throws(() => s.add(1), (e) => e is Error); | |
15 Expect.isNull(s.lookup(1)); | |
16 } | |
17 | |
18 void testIdentitySet(Set create()) { | |
19 Set<String> s = create(); | |
20 Expect.throws(() => s.add(1), (e) => e is Error); | |
21 Expect.isNull(s.lookup(1)); | |
22 } | |
23 | |
24 bool get inCheckedMode { | |
25 try { | |
26 var i = 1; | |
27 String j = i; | |
28 } catch (_) { | |
29 return true; | |
30 } | |
31 return false; | |
32 } | |
33 | |
34 void main() { | |
35 if (!inCheckedMode) return; | |
36 | |
37 testSet(() => new Set<String>()); | |
38 testSet(() => new HashSet<String>()); | |
39 testSet(() => new LinkedHashSet<String>()); | |
40 testIdentitySet(() => new Set<String>.identity()); | |
41 testIdentitySet(() => new HashSet<String>.identity()); | |
42 testIdentitySet(() => new LinkedHashSet<String>.identity()); | |
43 testIdentitySet(() => new HashSet<String>( | |
44 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); | |
45 testIdentitySet(() => new LinkedHashSet<String>( | |
46 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); | |
47 } | |
OLD | NEW |