Changeset 2305 for cobra/trunk/Tests/420-extensions/400-extend-generics/220-extend-ancestor-interface.cobra
- Timestamp:
- 03/10/10 06:47:00 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Tests/420-extensions/400-extend-generics/220-extend-ancestor-interface.cobra
r2240 r2305 1 # Invoke a method in an extension of a generic, ancestor interface.2 # In this case, the class is Dictionary<of TKey, TValue>.KeyCollection3 # and the extension method is declared on IEnumerable<of TKey> which KeyCollection implements.4 5 # Then do it again for Dictionary<of TKey, TValue>.ValueCollection6 # Note that it implement IEnumerable<of TValue> which is using the *2nd* generic parameter, not the first.7 8 1 class Test 9 2 10 3 def main 4 .test1 5 .test2 6 7 def test1 8 # Invoke a method in an extension of a generic, ancestor interface. 9 # In this case, the class is Dictionary<of TKey, TValue>.KeyCollection 10 # and the extension method is declared on IEnumerable<of TKey> which KeyCollection implements. 11 12 # Then do it again for Dictionary<of TKey, TValue>.ValueCollection 13 # Note that it implement IEnumerable<of TValue> which is using the *2nd* generic parameter, not the first. 11 14 d = {'x': 1, 'y': 1} 12 15 … … 18 21 assert value == 1 19 22 assert (for value in d.values.toList get value) == [1, 1] 23 24 def test2 25 x = X() 26 .takeEnum(x) 27 y = x.toList # previously broken. Cobra would not find the extension method. 28 assert y == List<of int>(x) 29 assert y == [1, 2, 3] 30 31 def takeEnum(e as IEnumerable<of int>) 32 assert e.toList is not e 33 assert e.toList == List<of int>(e) 34 35 36 class X implements IEnumerable<of int> 37 38 def getEnumerator as IEnumerator<of int> 39 return [1, 2, 3].getEnumerator 40 41 def getEnumerator as System.Collections.IEnumerator 42 implements System.Collections.IEnumerable 43 return .getEnumerator



