mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Fixed issue with multiple Dispose calls on foreach enumerator
This commit is contained in:
parent
9236b3e0d2
commit
85462e6d62
2 changed files with 60 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
#pragma warning disable 168
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
|
@ -12,6 +13,21 @@ namespace Tests
|
|||
public int32 mB;
|
||||
}
|
||||
|
||||
class EnumeratorTest : IEnumerator<int32>, IDisposable
|
||||
{
|
||||
public int mDispCount;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
mDispCount++;
|
||||
}
|
||||
|
||||
public Result<int32> GetNext()
|
||||
{
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -26,6 +42,37 @@ namespace Tests
|
|||
StructA sa = val;
|
||||
int idx = @val;
|
||||
}
|
||||
|
||||
var e = scope EnumeratorTest();
|
||||
for (var val in e)
|
||||
{
|
||||
}
|
||||
Test.Assert(e.mDispCount == 1);
|
||||
for (var val in e)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Test.Assert(e.mDispCount == 2);
|
||||
TestEnumerator1(e);
|
||||
Test.Assert(e.mDispCount == 3);
|
||||
TestEnumerator2(e);
|
||||
Test.Assert(e.mDispCount == 4);
|
||||
}
|
||||
|
||||
public static void TestEnumerator1(EnumeratorTest e)
|
||||
{
|
||||
for (var val in e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void TestEnumerator2(EnumeratorTest e)
|
||||
{
|
||||
for (var val in e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue