Skip to content

Commit 0f22828

Browse files
committed
C#: Add test cases corresponding to the System.Linq.Enumerable extensions methods.
1 parent cdb892d commit 0f22828

File tree

1 file changed

+133
-1
lines changed

1 file changed

+133
-1
lines changed

csharp/ql/test/utils/model-generator/typebasedflow/TypeBasedSummaries.cs

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,136 @@ public class TypeBasedNoCollection<T> : IEnumerable {
7575
public T Get() { throw null; }
7676

7777
public void Set(T x) { throw null; }
78-
}
78+
}
79+
80+
/*
81+
* Representative subset of Linq.
82+
*
83+
* Only methods that will get summaries generated correctly are commented in.
84+
* The remaning methods and interfaces are commented out with a descriptive reason.
85+
* In some cases we will not be able correctly generate a summary based purely on the
86+
* type information.
87+
*/
88+
public static class SystemLinqEnumerable {
89+
90+
public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func) { throw null; }
91+
public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func) { throw null; }
92+
public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector) { throw null; }
93+
public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
94+
public static bool Any<TSource>(this IEnumerable<TSource> source) { throw null; }
95+
public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
96+
public static IEnumerable<TSource> Append<TSource>(this IEnumerable<TSource> source, TSource element) { throw null; }
97+
public static IEnumerable<TSource> AsEnumerable<TSource>(this IEnumerable<TSource> source) { throw null; }
98+
public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) { throw null; }
99+
// Summary will not be derivables based on type information.
100+
// public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source) { throw null; }
101+
public static IEnumerable<TSource[]> Chunk<TSource>(this IEnumerable<TSource> source, int size) { throw null; }
102+
public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) { throw null; }
103+
public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value) { throw null; }
104+
public static int Count<TSource>(this IEnumerable<TSource> source) { throw null; }
105+
public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
106+
public static IEnumerable<TSource?> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source) { throw null; }
107+
public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue) { throw null; }
108+
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
109+
public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source) { throw null; }
110+
public static TSource? ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index) { throw null; }
111+
public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index) { throw null; }
112+
public static IEnumerable<TResult> Empty<TResult>() { throw null; }
113+
// These summaries will not be derivable based on type information.
114+
// public static IEnumerable<TSource> ExceptBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) { throw null; }
115+
// public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) { throw null; }
116+
public static TSource? FirstOrDefault<TSource>(this IEnumerable<TSource> source) { throw null; }
117+
public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, TSource defaultValue) { throw null; }
118+
public static TSource? FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
119+
// Summary will not be correctly derivable based on type information.
120+
// public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, TSource defaultValue) { throw null; }
121+
public static TSource First<TSource>(this IEnumerable<TSource> source) { throw null; }
122+
public static TSource First<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
123+
// Missing summary for Argument[0].Element -> Argument[2].Parameter[1].Element and similar problem for GroupJoin (issue with generator)
124+
// public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector) { throw null; }
125+
// public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector) { throw null; }
126+
public static IEnumerable<TSource> IntersectBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TKey> second, Func<TSource, TKey> keySelector) { throw null; }
127+
public static IEnumerable<TSource> Intersect<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) { throw null; }
128+
public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector) { throw null; }
129+
public static TSource? LastOrDefault<TSource>(this IEnumerable<TSource> source) { throw null; }
130+
public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, TSource defaultValue) { throw null; }
131+
public static TSource? LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
132+
// Summary will not be correctly derivable based on type information (same problem as for FirstOrDefault)
133+
// public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, TSource defaultValue) { throw null; }
134+
public static TSource Last<TSource>(this IEnumerable<TSource> source) { throw null; }
135+
public static TSource Last<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
136+
public static long LongCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
137+
public static TSource? MaxBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
138+
public static TSource? Max<TSource>(this IEnumerable<TSource> source) { throw null; }
139+
public static decimal Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector) { throw null; }
140+
public static TResult? Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) { throw null; }
141+
public static TSource? MinBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
142+
public static TSource? Min<TSource>(this IEnumerable<TSource> source) { throw null; }
143+
public static TResult? Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) { throw null; }
144+
// These summaries will not be derivable based on type information.
145+
// public static IEnumerable<TResult> OfType<TResult>(this IEnumerable source) { throw null; }
146+
public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
147+
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
148+
public static IEnumerable<TSource> Prepend<TSource>(this IEnumerable<TSource> source, TSource element) { throw null; }
149+
public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count) { throw null; }
150+
public static IEnumerable<TSource> Reverse<TSource>(this IEnumerable<TSource> source) { throw null; }
151+
public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector) { throw null; }
152+
public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector) { throw null; }
153+
public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) { throw null; }
154+
public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) { throw null; }
155+
public static TSource? SingleOrDefault<TSource>(this IEnumerable<TSource> source) { throw null; }
156+
public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, TSource defaultValue) { throw null; }
157+
public static TSource? SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
158+
// Summary will not be correctly derivable based on type information (same problem as for FirstOrDefault)
159+
// public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, TSource defaultValue) { throw null; }
160+
public static TSource Single<TSource>(this IEnumerable<TSource> source) { throw null; }
161+
public static TSource Single<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
162+
public static IEnumerable<TSource> SkipLast<TSource>(this IEnumerable<TSource> source, int count) { throw null; }
163+
public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
164+
public static IEnumerable<TSource> Skip<TSource>(this IEnumerable<TSource> source, int count) { throw null; }
165+
public static IEnumerable<TSource> TakeLast<TSource>(this IEnumerable<TSource> source, int count) { throw null; }
166+
public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
167+
public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count) { throw null; }
168+
public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
169+
public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
170+
// Missing summary for Argument[0].Element -> ReturnValue.Element (issue with generator)
171+
// public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source) { throw null; }
172+
// Summaries related to dictionaries is not generated correctly as dictionaries are not identified as collections of keys and values (issue with generator).
173+
// public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TKey : notnull { throw null; }
174+
// public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TKey : notnull { throw null; }
175+
public static HashSet<TSource> ToHashSet<TSource>(this IEnumerable<TSource> source) { throw null; }
176+
public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source) { throw null; }
177+
// Type to complicated to be handled by the generator (issue with generator).
178+
// public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { throw null; }
179+
// public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) { throw null; }
180+
public static IEnumerable<TSource> UnionBy<TSource, TKey>(this IEnumerable<TSource> first, IEnumerable<TSource> second, Func<TSource, TKey> keySelector) { throw null; }
181+
public static IEnumerable<TSource> Union<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) { throw null; }
182+
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { throw null; }
183+
// Type to complicated to be handled by the generator (issue with generator).
184+
// public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second) { throw null; }
185+
// public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third) { throw null; }
186+
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector) { throw null; }
187+
}
188+
189+
public interface IGrouping<out TKey, out TElement> : IEnumerable<TElement>, IEnumerable {
190+
TKey Key { get; }
191+
}
192+
193+
// public interface ILookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable {
194+
// IEnumerable<TElement> this[TKey key] { get; }
195+
// bool Contains(TKey key);
196+
// }
197+
198+
public interface IOrderedEnumerable<out TElement> : IEnumerable<TElement>, IEnumerable {
199+
IOrderedEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending);
200+
}
201+
202+
// public partial class Lookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable, ILookup<TKey, TElement>{
203+
// internal Lookup() { }
204+
// public int Count { get { throw null; } }
205+
// public IEnumerable<TElement> this[TKey key] { get { throw null; } }
206+
// public IEnumerable<TResult> ApplyResultSelector<TResult>(Func<TKey, IEnumerable<TElement>, TResult> resultSelector) { throw null; }
207+
// public bool Contains(TKey key) { throw null; }
208+
// public IEnumerator<IGrouping<TKey, TElement>> GetEnumerator() { throw null; }
209+
// IEnumerator IEnumerable.GetEnumerator() { throw null; }
210+
// }

0 commit comments

Comments
 (0)