2021-01-19 05:40:57 -08:00
|
|
|
#pragma warning disable 168
|
|
|
|
|
2020-12-06 09:06:14 -08:00
|
|
|
using System;
|
2021-05-31 07:01:56 -07:00
|
|
|
using System.Collections;
|
2020-12-06 09:06:14 -08:00
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
class Loops
|
|
|
|
{
|
2021-01-19 05:40:57 -08:00
|
|
|
struct StructA
|
|
|
|
{
|
|
|
|
public int32 mA;
|
|
|
|
public int32 mB;
|
|
|
|
}
|
|
|
|
|
2021-05-31 07:01:56 -07:00
|
|
|
class EnumeratorTest : IEnumerator<int32>, IDisposable
|
|
|
|
{
|
|
|
|
public int mDispCount;
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
mDispCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Result<int32> GetNext()
|
|
|
|
{
|
|
|
|
return .Err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 09:06:31 -07:00
|
|
|
static int sGetValCount = 0;
|
|
|
|
|
|
|
|
static int GetVal()
|
|
|
|
{
|
2021-07-20 12:28:23 -07:00
|
|
|
return 10 + sGetValCount++ / 2;
|
2021-07-16 09:06:31 -07:00
|
|
|
}
|
|
|
|
|
2020-12-06 09:06:14 -08:00
|
|
|
[Test]
|
|
|
|
public static void TestBasics()
|
|
|
|
{
|
|
|
|
while (false)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2021-01-19 05:40:57 -08:00
|
|
|
|
|
|
|
StructA[0] zeroLoop = default;
|
|
|
|
for (var val in zeroLoop)
|
|
|
|
{
|
|
|
|
StructA sa = val;
|
|
|
|
int idx = @val;
|
|
|
|
}
|
2021-05-31 07:01:56 -07:00
|
|
|
|
|
|
|
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);
|
2021-07-16 09:06:31 -07:00
|
|
|
|
|
|
|
int iterations = 0;
|
|
|
|
for (int i < GetVal())
|
|
|
|
{
|
|
|
|
iterations++;
|
|
|
|
}
|
2021-07-20 12:28:23 -07:00
|
|
|
Test.Assert(iterations == 19);
|
|
|
|
Test.Assert(sGetValCount == 20);
|
2021-07-21 07:48:37 -07:00
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
for (int i in 1..<10)
|
|
|
|
total += i;
|
|
|
|
Test.Assert(total == 1+2+3+4+5+6+7+8+9);
|
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (int i in 1...10)
|
|
|
|
total += i;
|
|
|
|
Test.Assert(total == 1+2+3+4+5+6+7+8+9+10);
|
2021-05-31 07:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|