2025-01-02 11:42:33 -08:00
|
|
|
using System;
|
2025-01-08 07:16:02 -08:00
|
|
|
using System.Collections;
|
2025-01-02 11:42:33 -08:00
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
class Anonymous
|
|
|
|
{
|
|
|
|
struct StructA
|
|
|
|
{
|
|
|
|
public [Union] struct { public int mX, mY; } mVals;
|
|
|
|
|
|
|
|
[CRepr, SkipCall] struct { public int mA, mB; } GetVals()
|
|
|
|
{
|
|
|
|
decltype(GetVals()) retVals;
|
|
|
|
retVals.mA = 1;
|
|
|
|
retVals.mB = 2;
|
|
|
|
return retVals;
|
|
|
|
}
|
2025-01-02 16:19:26 -08:00
|
|
|
|
|
|
|
public enum { Left, Right } GetDirection() => .Right;
|
|
|
|
|
|
|
|
public enum : int { A, B, C } Val => .C;
|
2025-01-02 11:42:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct StructB
|
|
|
|
{
|
|
|
|
[Union]
|
2025-01-05 08:55:17 -08:00
|
|
|
public struct
|
2025-01-02 11:42:33 -08:00
|
|
|
{
|
|
|
|
public int mX;
|
|
|
|
public int mY;
|
2025-01-05 08:55:17 -08:00
|
|
|
};
|
2025-01-02 11:42:33 -08:00
|
|
|
}
|
|
|
|
|
2025-01-04 10:57:37 -08:00
|
|
|
struct StructC
|
|
|
|
{
|
|
|
|
public int mA;
|
|
|
|
|
|
|
|
public this(int a)
|
|
|
|
{
|
|
|
|
mA = a;
|
|
|
|
}
|
2025-01-08 07:16:02 -08:00
|
|
|
|
|
|
|
public Self Clone() => this;
|
2025-01-04 10:57:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
class ClassA
|
|
|
|
{
|
|
|
|
public int Val = 123;
|
|
|
|
}
|
|
|
|
|
2025-01-04 12:47:45 -08:00
|
|
|
public static class : this(int x, int y) sValA = new .(3, 4) ~ delete _;
|
|
|
|
|
2025-01-02 11:42:33 -08:00
|
|
|
[Test]
|
|
|
|
public static void TestBasics()
|
|
|
|
{
|
|
|
|
StructA sa = default;
|
|
|
|
sa.mVals.mX = 123;
|
|
|
|
Test.Assert(sa.mVals.mY == 123);
|
|
|
|
|
|
|
|
var val = sa.[Friend]GetVals();
|
|
|
|
Test.Assert(val.mA == 0);
|
|
|
|
Test.Assert(val.mB == 0);
|
|
|
|
|
2025-01-02 16:19:26 -08:00
|
|
|
Test.Assert(sa.GetDirection() == .Right);
|
|
|
|
Test.Assert(sa.Val == .C);
|
|
|
|
|
2025-01-02 11:42:33 -08:00
|
|
|
StructB sb = default;
|
|
|
|
sb.mX = 345;
|
|
|
|
Test.Assert(sb.mY == 345);
|
2025-01-04 10:57:37 -08:00
|
|
|
|
|
|
|
var sc = StructC(456)
|
|
|
|
{
|
|
|
|
public int mB = 567;
|
|
|
|
|
|
|
|
{
|
|
|
|
_.mB += 1000;
|
|
|
|
},
|
|
|
|
mB += 10000
|
|
|
|
};
|
|
|
|
Test.Assert(sc.mA == 456);
|
|
|
|
Test.Assert(sc.mB == 11567);
|
|
|
|
|
2025-01-08 07:16:02 -08:00
|
|
|
List<StructC> scList = scope .() { sc };
|
|
|
|
List<StructC> scList2 = scope List<StructC>()
|
|
|
|
{
|
|
|
|
(int, float) GetTuple() => default;
|
|
|
|
int this[float f] => 99;
|
|
|
|
|
|
|
|
scList[0].Clone(),
|
|
|
|
(scList[0].Clone()),
|
|
|
|
(.)(scList[0].Clone())
|
|
|
|
};
|
|
|
|
Test.Assert(scList2.Count == 3);
|
|
|
|
|
2025-01-04 10:57:37 -08:00
|
|
|
var ca = scope ClassA()
|
|
|
|
{
|
|
|
|
public override void ToString(String strBuffer)
|
|
|
|
{
|
|
|
|
strBuffer.Append("ClassA override");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var str = ca.ToString(.. scope .());
|
|
|
|
Test.Assert(str == "ClassA override");
|
2025-01-04 12:47:45 -08:00
|
|
|
|
|
|
|
Test.Assert(sValA.x == 3);
|
|
|
|
Test.Assert(sValA.y == 4);
|
2025-01-02 11:42:33 -08:00
|
|
|
}
|
2025-01-05 08:55:17 -08:00
|
|
|
}
|