1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-15 23:04:09 +02:00
Beef/IDEHelper/Tests/src/Loops.bf

94 lines
1.3 KiB
Beef
Raw Normal View History

#pragma warning disable 168
2020-12-06 09:06:14 -08:00
using System;
using System.Collections;
2020-12-06 09:06:14 -08:00
namespace Tests
{
class Loops
{
struct StructA
{
public int32 mA;
public int32 mB;
}
class EnumeratorTest : IEnumerator<int32>, IDisposable
{
public int mDispCount;
public void Dispose()
{
mDispCount++;
}
public Result<int32> GetNext()
{
return .Err;
}
}
static int sGetValCount = 0;
static int GetVal()
{
return 10 + sGetValCount++;
}
2020-12-06 09:06:14 -08:00
[Test]
public static void TestBasics()
{
while (false)
{
}
StructA[0] zeroLoop = default;
for (var val in zeroLoop)
{
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);
int iterations = 0;
for (int i < GetVal())
{
iterations++;
}
Test.Assert(iterations == 10);
Test.Assert(sGetValCount == 1);
}
public static void TestEnumerator1(EnumeratorTest e)
{
for (var val in e)
{
return;
}
}
public static void TestEnumerator2(EnumeratorTest e)
{
for (var val in e)
{
return;
}
2020-12-06 09:06:14 -08:00
}
}
}