Skip to content

Commit e022e5c

Browse files
committed
Unit test for #2271 (v2)
1 parent 21f6aee commit e022e5c

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/xunit.assert/Asserts

test/test.xunit.assert/Asserts/EqualityAssertsTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,44 @@ public class EqualityAssertsTests
1212
{
1313
public class Equal
1414
{
15+
public class ReferenceEquality
16+
{
17+
// https://github.com/xunit/xunit/issues/2271
18+
[Fact]
19+
public void TwoIdenticalReferencesShouldBeEqual()
20+
{
21+
Field x = new Field();
22+
23+
Assert.Equal(x, x);
24+
}
25+
26+
sealed class Field : IReadOnlyList<Field>
27+
{
28+
Field IReadOnlyList<Field>.this[int index]
29+
{
30+
get
31+
{
32+
if (index != 0)
33+
throw new ArgumentOutOfRangeException(nameof(index));
34+
35+
return this;
36+
}
37+
}
38+
39+
int IReadOnlyCollection<Field>.Count => 1;
40+
41+
IEnumerator<Field> IEnumerable<Field>.GetEnumerator()
42+
{
43+
yield return this;
44+
}
45+
46+
IEnumerator IEnumerable.GetEnumerator()
47+
{
48+
yield return this;
49+
}
50+
}
51+
}
52+
1553
public class Intrinsics
1654
{
1755
[Fact]

0 commit comments

Comments
 (0)