1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-21 17:28:00 +02:00
Beef/IDEHelper/Tests/src/Switches.bf

71 lines
1 KiB
Beef
Raw Normal View History

2024-11-20 11:33:28 -05:00
#pragma warning disable 168
using System;
namespace Tests
{
class Switches
{
2024-11-01 19:01:21 -04:00
enum Shape
{
case Rectangle(int x, int y, int width, int height);
case Circle(int x, int y, int radius);
}
static int Switch0(Result<int> res)
{
switch (res)
{
case .Ok(let a):
return 0;
case .Err(let b):
return 1;
}
}
2024-11-01 19:01:21 -04:00
static int Switch1(Shape shape)
{
switch (shape)
{
2024-11-01 19:09:30 -04:00
case .Circle(let x, let y, let radius) when x == 10:
2024-11-01 19:01:21 -04:00
return 12;
default:
return 23;
}
}
[Test]
public static void TestBasics()
{
Result<int> val0 = .Ok(1);
Test.Assert(Switch0(val0) == 0);
val0 = .Err;
Test.Assert(Switch0(val0) == 1);
Shape shape = .Circle(10, 20, 30);
Test.Assert(Switch1(shape) == 12);
2024-11-20 11:33:28 -05:00
int val = 123;
int result = 0;
switch (val)
{
case 0:
result = 1;
default:
SWITCH2:
switch (val)
{
case 2:
result = 2;
default:
result = 3;
break SWITCH2;
}
result = 4;
}
Test.Assert(result == 4);
2024-11-01 19:01:21 -04:00
}
}
}