1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 08:30:25 +02:00

Boxed struct ptr changes.

This commit is contained in:
Brian Fiete 2019-10-09 16:16:01 -07:00
parent ad2542eba6
commit 5af6428bf4
20 changed files with 573 additions and 327 deletions

View file

@ -9,10 +9,9 @@ namespace Tests
int Get() mut;
}
struct Struct : IFace
struct StructA : IFace
{
public int mA = 100;
public int mB = 200;
public int Get() mut
{
@ -21,20 +20,87 @@ namespace Tests
}
}
struct StructB : StructA, IHashable
{
public int mB = 200;
public int GetHashCode()
{
return mB;
}
}
struct StructC : StructB
{
public int mC = 300;
}
public static int GetFromIFace<T>(mut T val) where T : IFace
{
return val.Get();
}
[Test]
public static void TestBasics()
{
Struct val0 = .();
Object obj0 = val0;
StructA valA = .();
Object obj0 = valA;
IFace iface0 = (IFace)obj0;
Test.Assert(GetFromIFace(mut valA) == 1100);
Test.Assert(iface0.Get() == 1100);
Test.Assert(val0.mA == 100); // This should copy values
Test.Assert(GetFromIFace(iface0) == 2100);
Test.Assert(valA.mA == 1100); // This should copy values
/*Struct val1 = .();
Object obj1 = (Object)(ref val1);
IFace iface1 = (IFace)obj1;
StructB valB = .();
IFace iface1 = valB;
Test.Assert(GetFromIFace(mut valB) == 1100);
Test.Assert(iface1.Get() == 1100);
Test.Assert(val1.mA == 1100); // This should reference values*/
Test.Assert(GetFromIFace(iface1) == 2100);
Test.Assert(valB.mA == 1100); // This should copy values
}
[Test]
public static void TestPtr()
{
StructA* valA = scope .();
Object obj0 = valA;
IFace iface0 = (IFace)obj0;
Test.Assert(GetFromIFace(mut valA) == 1100);
Test.Assert(iface0.Get() == 2100);
Test.Assert(GetFromIFace(iface0) == 3100);
Test.Assert(valA.mA == 3100); // This should copy values
StructB* valB = scope .();
IFace iface1 = valB;
Test.Assert(GetFromIFace(mut valB) == 1100);
Test.Assert(iface1.Get() == 2100);
Test.Assert(GetFromIFace(iface1) == 3100);
Test.Assert(valB.mA == 3100); // This should copy values
}
public static int GetHash<T>(T val) where T : IHashable
{
return val.GetHashCode();
}
[Test]
public static void TestPtrHash()
{
StructA* valA = scope .();
StructB* valB = scope .();
StructC* valC = scope .();
IHashable ihA = valA;
IHashable ihB = valB;
IHashable ihC = valC;
Test.Assert(ihA.GetHashCode() == (int)valA);
Test.Assert(ihB.GetHashCode() == (int)valB);
Test.Assert(ihC.GetHashCode() == (int)valC);
Test.Assert(GetHash(ihA) == (int)valA);
Test.Assert(GetHash(ihB) == (int)valB);
Test.Assert(GetHash(ihC) == (int)valC);
}
}
}