1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Merge branch 'master' into FuzzyAutoComplete

This commit is contained in:
Brian Fiete 2021-12-28 17:07:19 +01:00 committed by GitHub
commit 62c3998521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 2485 additions and 598 deletions

View file

@ -0,0 +1,2 @@
Test
0

View file

@ -183,7 +183,7 @@ namespace Tests
mStr.AppendF($"{name} {val}\n");
}
}
interface ISerializable
{
void Serialize(SerializationContext ctx);
@ -229,6 +229,43 @@ namespace Tests
GC.Mark!((*ptr));
}
}
[CheckEnum]
enum EnumA
{
case A(int64 aa);
case B(float bb);
}
[AttributeUsage(.All)]
public struct CheckEnumAttribute : Attribute, IComptimeTypeApply
{
public void ApplyToType(Type type)
{
int fieldIdx = 0;
for (var field in type.GetFields())
{
switch (fieldIdx)
{
case 0:
Test.Assert(field.Name == "$payload");
Test.Assert(field.MemberOffset == 0);
Test.Assert(field.FieldType == typeof(int64));
case 1:
Test.Assert(field.Name == "$discriminator");
Test.Assert(field.MemberOffset == 8);
Test.Assert(field.FieldType == typeof(int8));
}
fieldIdx++;
}
Test.Assert(fieldIdx == 4);
}
}
const String cTest0 = Compiler.ReadText("Test0.txt");
const String cTest1 = new String('A', 12);
const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt");
[Test]
public static void TestBasics()
{
@ -269,6 +306,11 @@ namespace Tests
SerializationContext serCtx = scope .();
iSer.Serialize(serCtx);
Test.Assert(serCtx.mStr == "x 10\ny 2\n");
Test.Assert(cTest0 == "Test\n0");
Test.Assert(cTest1 == "AAAAAAAAAAAA");
Test.Assert((Object)cTest1 == (Object)"AAAAAAAAAAAA");
Test.Assert((cTest0Binary[0] == (.)'T') && ((cTest0Binary.Count == 6) || (cTest0Binary.Count == 7)));
}
}
}

View file

@ -57,6 +57,65 @@ namespace Tests
return dlg(val[0]);
}
static void TestWrap<T>(T del, bool b = false) where T : delegate void()
{
Action ac = scope () => {
del();
};
ac();
}
struct Vector2 : this(float x, float y)
{
}
class Invoker
{
public int mA = 111;
public void Invoke()
{
mA += 222;
}
}
class TestA
{
Vector2 mVec = .(11, 22);
Event<Action> mEvt ~ _.Dispose();
Action mAct;
public Vector2 Vec
{
set
{
DoIt(() =>
{
Test.Assert(mVec.x == 11);
Test.Assert(mVec.y == 22);
Test.Assert(value.x == 33);
Test.Assert(value.y == 44);
});
Invoker invoker = scope .();
mEvt.Add(new => invoker);
DoIt(=> mEvt);
Test.Assert(invoker.mA == 333);
DoIt(=> invoker);
Test.Assert(invoker.mA == 555);
mAct = scope => invoker;
mAct();
Test.Assert(invoker.mA == 777);
DoIt(=> mAct);
Test.Assert(invoker.mA == 999);
}
}
public void DoIt<TDlg>(TDlg dlg) where TDlg : delegate void()
{
dlg();
}
}
[Test]
public static void TestBasics()
{
@ -78,6 +137,13 @@ namespace Tests
List<float> fList = scope .() { 1.2f, 2.3f };
Test.Assert(DoOnListA(fList, (val) => val + 100) == 101.2f);
Test.Assert(DoOnListB((val) => val + 200, fList) == 201.2f);
int a = 222;
TestWrap(() => { a += 100; });
Test.Assert(a == 322);
TestA ta = scope .();
ta.Vec = .(33, 44);
}
struct MethodRefHolder<T> where T : delegate int(int num)

View file

@ -23,6 +23,16 @@ namespace Tests
{
class Generics
{
struct StructA : IDisposable
{
int mA = 123;
public void Dispose()
{
}
}
class ClassA : IDisposable, LibA.IVal
{
int LibA.IVal.Val
@ -172,7 +182,7 @@ namespace Tests
delete val;
}
public static void Alloc2<T>() where T : new, delete, IDisposable, struct
public static void Alloc2<T>() where T : new, IDisposable, struct
{
alloctype(T) val = new T();
T* val2 = val;
@ -180,6 +190,14 @@ namespace Tests
delete val;
}
public static void Alloc3<T>() where T : new, IDisposable, struct*
{
T val2 = default;
if (val2 != null)
val2.Dispose();
delete val2;
}
public class ClassE
{
public static Self Instance = new ClassE() ~ delete _;
@ -311,6 +329,9 @@ namespace Tests
[Test]
public static void TestBasics()
{
Alloc2<StructA>();
Alloc3<StructA*>();
MethodD(scope => MethodC);
List<Entry> list = scope .();