1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-25 19:18:01 +02:00
Beef/IDEHelper/Tests/src/Properties.bf

183 lines
2.7 KiB
Beef
Raw Normal View History

2020-04-10 07:53:56 -07:00
#pragma warning disable 168
using System;
namespace Tests
{
class Properties
{
struct StructA
{
public int mA = 111;
2022-03-31 08:26:23 -07:00
public static int sAutoProp { get; set; }
2020-04-10 07:53:56 -07:00
public this()
{
}
public this(int a)
{
mA = a;
}
2022-03-31 08:26:23 -07:00
public static void IncAutoProp()
{
Test.Assert(sAutoProp == 0);
int v = ++sAutoProp;
Test.Assert(v == 1);
Test.Assert(sAutoProp == 1);
int v2 = sAutoProp++;
Test.Assert(v == 1);
Test.Assert(sAutoProp == 2);
}
2020-04-10 07:53:56 -07:00
}
struct StructB
{
2020-05-08 16:35:05 -07:00
public StructA B { get; set mut; }
2022-03-01 09:49:02 -08:00
public ref StructA B2 { get mut; set mut; }
2020-04-10 07:53:56 -07:00
int mZ = 9;
public this()
{
B = .();
2022-03-01 09:49:02 -08:00
#unwarn
B.mA += 1000;
2022-03-01 09:49:02 -08:00
StructA sa = .();
sa.mA += 2000;
B2 = sa;
B2.mA += 3000;
2020-04-10 07:53:56 -07:00
}
}
struct StructC
{
public StructA B { get; }
public int C => 123;
[SkipCall]
public int D => 123;
public int E
{
get
{
return 1;
}
get mut
{
return 2;
}
}
2020-04-10 07:53:56 -07:00
int mZ = 9;
public int GetVal()
{
return 3;
}
public int GetVal() mut
{
return 4;
}
2020-04-10 07:53:56 -07:00
public this()
{
B = .();
}
}
class ClassB
{
public StructA B { get; set; }
2020-08-03 06:09:45 -07:00
public int IVal { get => 1; }
public virtual int IVal2 { get => 2; }
2020-04-10 07:53:56 -07:00
int mZ = 9;
public this()
{
}
}
2020-08-03 06:09:45 -07:00
class ClassC : ClassB
{
public new int IVal { get => base.IVal + 100; }
public override int IVal2 { get => base.IVal2 + 100; }
}
2021-01-19 10:40:38 -08:00
abstract class ClassD
{
public int32 Val { get; set; }
}
class ClassE : ClassD
{
}
static void MethodC<T>(T val) where T : ClassD
{
val.Val = 999;
}
static int MethodD<T>(T val) where T : ClassD
{
return val.Val;
}
2020-04-10 07:53:56 -07:00
[Test]
public static void TestBasics()
{
StructB sb = .();
StructA sa = sb.B;
2022-03-01 09:49:02 -08:00
StructA sa2 = sb.B2;
2020-04-10 07:53:56 -07:00
Test.Assert(sa.mA == 111);
sb.B = .(222);
sa = sb.B;
Test.Assert(sa.mA == 222);
2022-03-01 09:49:02 -08:00
Test.Assert(sa2.mA == 5111);
2020-04-10 07:53:56 -07:00
StructC sc = default;
Test.Assert(sc.C == 123);
Test.Assert(sc.D == 0);
let sc2 = sc;
Test.Assert(sc.E == 2);
Test.Assert(sc.GetVal() == 4);
Test.Assert(sc2.E == 1);
Test.Assert(sc2.GetVal() == 3);
2020-04-10 07:53:56 -07:00
ClassB cb = scope .();
sa = cb.B;
Test.Assert(sa.mA == 0);
cb.B = .(333);
sa = cb.B;
Test.Assert(sa.mA == 333);
2020-08-03 06:09:45 -07:00
ClassC cc = scope .();
Test.Assert(cc.IVal == 101);
Test.Assert(cc.IVal2 == 102);
ClassB cb2 = cc;
Test.Assert(cb2.IVal == 1);
Test.Assert(cb2.IVal2 == 102);
2021-01-19 10:40:38 -08:00
ClassE ce = scope .();
MethodC(ce);
Test.Assert(ce.Val == 999);
Test.Assert(MethodD(ce) == 999);
2022-03-31 08:26:23 -07:00
StructA.IncAutoProp();
int ap = ++StructA.sAutoProp;
Test.Assert(ap == 3);
int ap2 = StructA.sAutoProp++;
Test.Assert(ap2 == 3);
Test.Assert(StructA.sAutoProp == 4);
2020-04-10 07:53:56 -07:00
}
}
}