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

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

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month 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
« no previous file with comments | « tests/language/map_test.dart ('k') | tests/language/ordered_maps_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Checks that a method with an instantiated return type can override a method 5 // Checks that a method with an instantiated return type can override a method
6 // with a generic return type. 6 // with a generic return type.
7 7
8 typedef Collection<K> GetKeysFunctionType<K>(); 8 typedef V RemoveFunctionType<K, V>(K key);
9 9
10 class MapBase<K, V> implements Map<K, V> { 10 class MapBase<K, V> implements Map<K, V> {
11 Collection<K> getKeys() { 11 K remove(K key) {
12 throw 'Must be implemented'; 12 throw 'Must be implemented';
13 } 13 }
14 14
15 void Tests() { 15 void Tests() {
16 Expect.isTrue(this is MapBase<int, int>); 16 Expect.isTrue(this is MapBase<int, int>);
17 17
18 Expect.isTrue(getKeys is GetKeysFunctionType); 18 Expect.isTrue(remove is RemoveFunctionType);
19 Expect.isTrue(getKeys is GetKeysFunctionType<int>); 19 Expect.isTrue(remove is RemoveFunctionType<int, int>);
20 Expect.isTrue(getKeys is !GetKeysFunctionType<String>); 20 Expect.isTrue(remove is !RemoveFunctionType<String, int>);
21 Expect.isTrue(getKeys is !GetKeysFunctionType<MapBase<int, int>>); 21 Expect.isTrue(remove is !RemoveFunctionType<MapBase<int, int>, int>);
22 } 22 }
23 } 23 }
24 24
25 25
26 class MethodOverrideTest extends MapBase<String, String> { 26 class MethodOverrideTest extends MapBase<String, String> {
27 Collection<String> getKeys() { 27 String remove(String key) {
28 throw 'Is implemented'; 28 throw 'Must be implemented';
29 } 29 }
30 30
31 void Tests() { 31 void Tests() {
32 Expect.isTrue(this is MethodOverrideTest); 32 Expect.isTrue(this is MethodOverrideTest);
33 Expect.isTrue(this is MapBase<String, String>); 33 Expect.isTrue(this is MapBase<String, String>);
34 34
35 Expect.isTrue(getKeys is GetKeysFunctionType); 35 Expect.isTrue(remove is RemoveFunctionType);
36 Expect.isTrue(getKeys is GetKeysFunctionType<String>); 36 Expect.isTrue(remove is RemoveFunctionType<String, String>);
37 Expect.isTrue(getKeys is !GetKeysFunctionType<int>); 37 Expect.isTrue(remove is !RemoveFunctionType<int, int>);
38 Expect.isTrue(super.getKeys is GetKeysFunctionType); 38 Expect.isTrue(super.remove is RemoveFunctionType);
39 Expect.isTrue(super.getKeys is GetKeysFunctionType<String>); 39 Expect.isTrue(super.remove is RemoveFunctionType<String, String>);
40 Expect.isTrue(super.getKeys is !GetKeysFunctionType<int>); 40 Expect.isTrue(super.remove is !RemoveFunctionType<int, int>);
41 } 41 }
42 } 42 }
43 43
44 44
45 main() { 45 main() {
46 // Since method overriding is only checked statically, explicitly check 46 // Since method overriding is only checked statically, explicitly check
47 // the subtyping relation using a function type alias. 47 // the subtyping relation using a function type alias.
48 var x = new MethodOverrideTest(); 48 var x = new MethodOverrideTest();
49 Expect.isTrue(x.getKeys is GetKeysFunctionType<String>); 49 Expect.isTrue(x.remove is RemoveFunctionType<String, String>);
50 50
51 // Perform a few more tests. 51 // Perform a few more tests.
52 x.Tests(); 52 x.Tests();
53 53
54 var m = new MapBase<int, int>(); 54 var m = new MapBase<int, int>();
55 Expect.isTrue(m.getKeys is GetKeysFunctionType<int>); 55 Expect.isTrue(m.remove is RemoveFunctionType<int, int>);
56 56
57 // Perform a few more tests. 57 // Perform a few more tests.
58 m.Tests(); 58 m.Tests();
59 } 59 }
OLDNEW
« no previous file with comments | « tests/language/map_test.dart ('k') | tests/language/ordered_maps_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698