Skip to content

Commit 3dee710

Browse files
authored
Merge pull request #1031 from FirelyTeam/copilot/fix-1029-2
Remove redundant empty check from CqlOperators.Slice method
2 parents 08c1861 + 7d79bda commit 3dee710

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Cql/CoreTests/PrimitiveTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,28 @@ public void SliceTakeIsNull()
38853885
Assert.AreEqual(expectedList, slicedList);
38863886
}
38873887

3888+
[TestMethod]
3889+
public void SliceEmptyEnumerableWithIEnumerableNotCollection()
3890+
{
3891+
// Test Slice with empty enumerable that's not a collection type
3892+
// This ensures behavior remains consistent after removing the redundant empty check
3893+
var rtx = GetNewContext();
3894+
var inputEnumerable = Enumerable.Empty<int>().Where(x => true); // Creates IEnumerable<int> not a collection
3895+
var expectedList = new List<int>();
3896+
3897+
// Test various slice operations on empty enumerable
3898+
var slicedList1 = rtx.Operators.Slice(inputEnumerable, 0, 5);
3899+
var slicedList2 = rtx.Operators.Slice(inputEnumerable, 2, null);
3900+
var slicedList3 = rtx.Operators.Slice(inputEnumerable, null, null);
3901+
3902+
Assert.IsNotNull(slicedList1);
3903+
Assert.IsNotNull(slicedList2);
3904+
Assert.IsNotNull(slicedList3);
3905+
CollectionAssert.AreEqual(expectedList, slicedList1.ToList());
3906+
CollectionAssert.AreEqual(expectedList, slicedList2.ToList());
3907+
CollectionAssert.AreEqual(expectedList, slicedList3.ToList());
3908+
}
3909+
38883910
#endregion
38893911

38903912
#region ListSkip and ListTake tests

Cql/Cql.Runtime/Operators/CqlOperators.ListOperators.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,6 @@ internal partial class CqlOperators
10481048
if (source == null)
10491049
return null;
10501050

1051-
if (!source.Any())
1052-
return Enumerable.Empty<T>();
1053-
10541051
if (startIndex == null && endIndex == null)
10551052
return source;
10561053

0 commit comments

Comments
 (0)