mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
More generics tests
This commit is contained in:
parent
7434885d07
commit
2510c16389
2 changed files with 67 additions and 1 deletions
|
@ -1,8 +1,31 @@
|
||||||
using System;
|
using System;
|
||||||
namespace LibA
|
namespace LibA
|
||||||
{
|
{
|
||||||
|
interface IVal
|
||||||
|
{
|
||||||
|
int Val
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class LibA0
|
class LibA0
|
||||||
{
|
{
|
||||||
|
public static int GetVal<T>(T val) where T : IVal
|
||||||
|
{
|
||||||
|
return val.Val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Dispose<T>(mut T val) where T : IDisposable
|
||||||
|
{
|
||||||
|
val.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Alloc<T>() where T : new, delete
|
||||||
|
{
|
||||||
|
let t = new T();
|
||||||
|
delete t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,42 @@ namespace Tests
|
||||||
{
|
{
|
||||||
class Generics
|
class Generics
|
||||||
{
|
{
|
||||||
class ClassA : IDisposable
|
class ClassA : IDisposable, LibA.IVal
|
||||||
{
|
{
|
||||||
|
int LibA.IVal.Val
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDisposable.Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ClassB : IDisposable, LibA.IVal
|
||||||
|
{
|
||||||
|
public int Val
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 234;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -55,7 +89,16 @@ namespace Tests
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
ClassA ca = scope .();
|
||||||
|
ClassB cb = scope .();
|
||||||
|
Test.Assert(LibA.LibA0.GetVal(ca) == 123);
|
||||||
|
Test.Assert(LibA.LibA0.GetVal(cb) == 234);
|
||||||
|
|
||||||
|
LibA.LibA0.Dispose(ca);
|
||||||
|
LibA.LibA0.Dispose(cb);
|
||||||
|
|
||||||
|
LibA.LibA0.Alloc<ClassA>();
|
||||||
|
LibA.LibA0.Alloc<ClassB>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue