1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-17 07:44:09 +02:00
Beef/IDEHelper/Tests/src/Generics.bf
2020-02-13 07:53:11 -08:00

81 lines
1.2 KiB
Beef

using System;
namespace Tests
{
class Generics
{
class ClassA : IDisposable
{
public void Dispose()
{
}
}
static void DoDispose<T>(mut T val) where T : IDisposable
{
val.Dispose();
}
struct Disposer<T>
{
static void UseDispose(IDisposable disp)
{
}
static void DoDisposeA(mut T val) where T : IDisposable
{
val.Dispose();
UseDispose(val);
}
static void DoDisposeB(mut T val) where T : IDisposable
{
val.Dispose();
}
}
[Test]
public static void TestGenericDelegates()
{
delegate void(String v) dlg = scope => StrMethod;
CallGenericDelegate(dlg);
CallGenericDelegate<String>(scope => StrMethod);
}
public static void CallGenericDelegate<T>(delegate void(T v) dlg)
{
}
public static void StrMethod(String v)
{
}
[Test]
public static void TestBasics()
{
}
}
class ConstGenerics
{
public static float GetSum<TCount>(float[TCount] vals) where TCount : const int
{
float total = 0;
for (int i < vals.Count)
total += vals[i];
return total;
}
[Test]
public static void TestBasics()
{
float[5] fVals = .(10, 20, 30, 40, 50);
float totals = GetSum(fVals);
Test.Assert(totals == 10+20+30+40+50);
}
}
}