This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/System.Collections.Immutable/tests Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -374,6 +374,25 @@ public void RemoveNonExistentKeepsReference()
374
374
Assert . Same ( list , list . Remove ( 3 ) ) ;
375
375
}
376
376
377
+ /// <summary>
378
+ /// Verifies that RemoveRange does not enumerate its argument if the list is empty
379
+ /// and therefore could not possibly have any elements to remove anyway.
380
+ /// </summary>
381
+ /// <remarks>
382
+ /// While this would seem an implementation detail and simply an optimization,
383
+ /// it turns out that changing this behavior now *could* represent a breaking change
384
+ /// because if the enumerable were to throw an exception, that exception would not be
385
+ /// observed previously, but would start to be thrown if this behavior changed.
386
+ /// So this is a test to lock the behavior in place.
387
+ /// </remarks>
388
+ /// <seealso cref="ImmutableSetTest.ExceptDoesEnumerateSequenceIfThisIsEmpty"/>
389
+ [ Fact ]
390
+ public void RemoveRangeDoesNotEnumerateSequenceIfThisIsEmpty ( )
391
+ {
392
+ var list = ImmutableList < int > . Empty ;
393
+ list . RemoveRange ( Enumerable . Range ( 1 , 1 ) . Select ( n => { Assert . False ( true , "Sequence should not have been enumerated." ) ; return n ; } ) ) ;
394
+ }
395
+
377
396
[ Fact ]
378
397
public void RemoveAtTest ( )
379
398
{
Original file line number Diff line number Diff line change @@ -58,6 +58,25 @@ public void ExceptTest()
58
58
this . ExceptTestHelper ( Empty < int > ( ) . Add ( 1 ) . Add ( 3 ) . Add ( 5 ) . Add ( 7 ) , 3 , 7 ) ;
59
59
}
60
60
61
+ /// <summary>
62
+ /// Verifies that Except *does* enumerate its argument if the collection is empty.
63
+ /// </summary>
64
+ /// <remarks>
65
+ /// While this would seem an implementation detail and simply lack of an optimization,
66
+ /// it turns out that changing this behavior now *could* represent a breaking change
67
+ /// because if the enumerable were to throw an exception, that exception would be
68
+ /// observed previously, but would no longer be thrown if this behavior changed.
69
+ /// So this is a test to lock the behavior in place or be thoughtful if adding the optimization.
70
+ /// </remarks>
71
+ /// <seealso cref="ImmutableListTest.RemoveRangeDoesNotEnumerateSequenceIfThisIsEmpty"/>
72
+ [ Fact ]
73
+ public void ExceptDoesEnumerateSequenceIfThisIsEmpty ( )
74
+ {
75
+ bool enumerated = false ;
76
+ Empty < int > ( ) . Except ( Enumerable . Range ( 1 , 1 ) . Select ( n => { enumerated = true ; return n ; } ) ) ;
77
+ Assert . True ( enumerated ) ;
78
+ }
79
+
61
80
[ Fact ]
62
81
public void SymmetricExceptTest ( )
63
82
{
You can’t perform that action at this time.
0 commit comments