| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 of hash set type checking. | 5 // Tests of hash set type checking. |
| 6 | 6 |
| 7 library hash_set_type_check_test; | 7 library hash_set_type_check_test; |
| 8 | 8 |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 | 11 |
| 12 // TODO: all this test does now is verify that lookup takes a non-T |
| 13 // should merge this with `hash_test_test`. |
| 12 testSet(Set<String> newSet()) { | 14 testSet(Set<String> newSet()) { |
| 13 Set<String> s = newSet(); | 15 Set<String> s = newSet(); |
| 14 Expect.throws(() => s.add(1), (e) => e is Error); | |
| 15 Expect.isNull(s.lookup(1)); | 16 Expect.isNull(s.lookup(1)); |
| 16 } | 17 } |
| 17 | 18 |
| 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() { | 19 void main() { |
| 35 if (!inCheckedMode) return; | |
| 36 | |
| 37 testSet(() => new Set<String>()); | 20 testSet(() => new Set<String>()); |
| 38 testSet(() => new HashSet<String>()); | 21 testSet(() => new HashSet<String>()); |
| 39 testSet(() => new LinkedHashSet<String>()); | 22 testSet(() => new LinkedHashSet<String>()); |
| 40 testIdentitySet(() => new Set<String>.identity()); | 23 testSet(() => new Set<String>.identity()); |
| 41 testIdentitySet(() => new HashSet<String>.identity()); | 24 testSet(() => new HashSet<String>.identity()); |
| 42 testIdentitySet(() => new LinkedHashSet<String>.identity()); | 25 testSet(() => new LinkedHashSet<String>.identity()); |
| 43 testIdentitySet(() => new HashSet<String>( | 26 testSet(() => new HashSet<String>( |
| 44 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); | 27 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); |
| 45 testIdentitySet(() => new LinkedHashSet<String>( | 28 testSet(() => new LinkedHashSet<String>( |
| 46 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); | 29 equals: (x, y) => identical(x, y), hashCode: (x) => identityHashCode(x))); |
| 47 } | 30 } |
| OLD | NEW |