Skip to content

Commit

Permalink
fix List.AllIndicesOf node (#13773)
Browse files Browse the repository at this point in the history
  • Loading branch information
aparajit-pratap authored Feb 24, 2023
1 parent 0b1a5cf commit 19f6734
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -1346,7 +1346,7 @@ public static IList AllIndicesOf(IList list, object item)
if (list == null)
return new List<int> { };

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

Expand Down
21 changes: 20 additions & 1 deletion test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -948,6 +948,25 @@ public static void AllIndicesOf()
Assert.IsEmpty(indices);
}

[Test]
[Category("UnitTests")]
public static void AllIndicesOfNullTest()
{
var input = new List<object> { true, false, null };

var indices = List.AllIndicesOf(input, true);
Assert.True(indices.Count == 1);
Assert.AreEqual(0, indices[0]);

indices = List.AllIndicesOf(input, false);
Assert.True(indices.Count == 1);
Assert.AreEqual(1, indices[0]);

indices = List.AllIndicesOf(input, null);
Assert.True(indices.Count == 1);
Assert.AreEqual(2, indices[0]);
}

[Test]
[Category("UnitTests")]
public static void CleanNullsPreserveIndices()
Expand Down

0 comments on commit 19f6734

Please sign in to comment.