Skip to content

Commit 1b44b4b

Browse files
aparajit-pratapQilongTang
authored andcommitted
fix List.AllIndicesOf node (#13773)
1 parent b2b08c5 commit 1b44b4b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Libraries/CoreNodes/List.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -1346,7 +1346,7 @@ public static IList AllIndicesOf(IList list, object item)
13461346
if (list == null)
13471347
return new List<int> { };
13481348

1349-
var indices = Enumerable.Range(0, list.Count).Where(i => list[i].Equals(item)).ToList();
1349+
var indices = Enumerable.Range(0, list.Count).Where(i => list[i] != null ? list[i].Equals(item) : item == null).ToList();
13501350
return indices;
13511351
}
13521352

test/Libraries/CoreNodesTests/ListTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -948,6 +948,25 @@ public static void AllIndicesOf()
948948
Assert.IsEmpty(indices);
949949
}
950950

951+
[Test]
952+
[Category("UnitTests")]
953+
public static void AllIndicesOfNullTest()
954+
{
955+
var input = new List<object> { true, false, null };
956+
957+
var indices = List.AllIndicesOf(input, true);
958+
Assert.True(indices.Count == 1);
959+
Assert.AreEqual(0, indices[0]);
960+
961+
indices = List.AllIndicesOf(input, false);
962+
Assert.True(indices.Count == 1);
963+
Assert.AreEqual(1, indices[0]);
964+
965+
indices = List.AllIndicesOf(input, null);
966+
Assert.True(indices.Count == 1);
967+
Assert.AreEqual(2, indices[0]);
968+
}
969+
951970
[Test]
952971
[Category("UnitTests")]
953972
public static void CleanNullsPreserveIndices()

0 commit comments

Comments
 (0)