mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-23 18:18:00 +02:00
Initial checkin
This commit is contained in:
parent
c74712dad9
commit
078564ac9e
3242 changed files with 1616395 additions and 0 deletions
118
IDEHelper/Tests/src/Enums.bf
Normal file
118
IDEHelper/Tests/src/Enums.bf
Normal file
|
@ -0,0 +1,118 @@
|
|||
#pragma warning disable 168
|
||||
|
||||
using System;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
class Enums
|
||||
{
|
||||
enum EnumA
|
||||
{
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
enum EnumB
|
||||
{
|
||||
A,
|
||||
B = 600
|
||||
}
|
||||
|
||||
enum EnumC
|
||||
{
|
||||
A,
|
||||
B = 0x7FFFFFFF
|
||||
}
|
||||
|
||||
enum EnumD
|
||||
{
|
||||
A,
|
||||
B = 0x7FFFFFFFFFFFFFFFL
|
||||
}
|
||||
|
||||
enum EnumE
|
||||
{
|
||||
case A;
|
||||
case B(int a);
|
||||
case C(int a, int b);
|
||||
}
|
||||
|
||||
enum EnumF
|
||||
{
|
||||
case None;
|
||||
case EE(EnumE ee);
|
||||
}
|
||||
|
||||
[Test]
|
||||
static void TestBasic()
|
||||
{
|
||||
EnumA ea = .A;
|
||||
Test.Assert((int)ea == 0);
|
||||
Test.Assert(sizeof(EnumA) == 1);
|
||||
Test.Assert(sizeof(EnumB) == 2);
|
||||
Test.Assert(sizeof(EnumC) == 4);
|
||||
Test.Assert(sizeof(EnumD) == 8);
|
||||
}
|
||||
|
||||
[Test]
|
||||
static void TestPayloads()
|
||||
{
|
||||
Test.Assert(sizeof(EnumE) == sizeof(int)*2 + 1);
|
||||
Test.Assert(sizeof(EnumF) == sizeof(int)*2 + 1 + 1);
|
||||
|
||||
EnumE ee = .C(1, 2);
|
||||
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
switch (ee)
|
||||
{
|
||||
case .A:
|
||||
case .B(out a):
|
||||
case .C(out a, out b):
|
||||
}
|
||||
Test.Assert(a == 1);
|
||||
Test.Assert(b == 2);
|
||||
|
||||
EnumF ef = .EE(.C(3, 4));
|
||||
switch (ef)
|
||||
{
|
||||
case .EE(let eeVal):
|
||||
if (!(eeVal case .C(out a, out b)))
|
||||
{
|
||||
Test.FatalError();
|
||||
}
|
||||
default:
|
||||
}
|
||||
Test.Assert(a == 3);
|
||||
Test.Assert(b == 4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
static void TestCases()
|
||||
{
|
||||
EnumE ee = .A;
|
||||
|
||||
int val = 123;
|
||||
bool matches = ee case .B(out val);
|
||||
Test.Assert(val == 0);
|
||||
|
||||
// We only assign to 'val' on true here
|
||||
val = 123;
|
||||
if (ee case .B(out val))
|
||||
{
|
||||
Test.Assert(val == 0 );
|
||||
}
|
||||
Test.Assert(val == 123);
|
||||
|
||||
// We always assign to 'val' here because we may enter even if there's no match
|
||||
val = 123;
|
||||
if ((ee case .B(out val)) || (val > 0))
|
||||
{
|
||||
}
|
||||
Test.Assert(val == 0);
|
||||
|
||||
ee = .B(10);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue