mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
More tests for generic constraints and mixins
This commit is contained in:
parent
c90db82b52
commit
f6f94ed40c
2 changed files with 50 additions and 0 deletions
42
IDEHelper/Tests/src/Constraints.bf
Normal file
42
IDEHelper/Tests/src/Constraints.bf
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
class Constraints
|
||||||
|
{
|
||||||
|
class Dicto : Dictionary<int, float>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Method1<T>(IEnumerator<T> param1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Method2<TEnumerator, TElement>(TEnumerator param1) where TEnumerator : IEnumerator<TElement>
|
||||||
|
{
|
||||||
|
for (let val in param1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool Method3<K, V>(Dictionary<K, V> param1) where K : IHashable
|
||||||
|
{
|
||||||
|
Method1(param1.GetEnumerator());
|
||||||
|
Method1((IEnumerator<(K key, V value)>)param1.GetEnumerator());
|
||||||
|
return Method2<Dictionary<K, V>.Enumerator, (K key, V value)>(param1.GetEnumerator());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public static void TestBasics()
|
||||||
|
{
|
||||||
|
Dicto dicto = scope .();
|
||||||
|
Method3(dicto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,13 @@ namespace Tests
|
||||||
{
|
{
|
||||||
class Mixins
|
class Mixins
|
||||||
{
|
{
|
||||||
|
static mixin MixNums(int a, int b)
|
||||||
|
{
|
||||||
|
(a << 8) | b
|
||||||
|
}
|
||||||
|
|
||||||
|
const int cVal = MixNums!(3, 5);
|
||||||
|
|
||||||
class MixClass
|
class MixClass
|
||||||
{
|
{
|
||||||
public int mA = 100;
|
public int mA = 100;
|
||||||
|
@ -39,6 +46,7 @@ namespace Tests
|
||||||
mc.MixB!(10);
|
mc.MixB!(10);
|
||||||
Test.Assert(mc.mA == 120);
|
Test.Assert(mc.mA == 120);
|
||||||
Test.Assert(MixClass.MixC!(30) == 230);
|
Test.Assert(MixClass.MixC!(30) == 230);
|
||||||
|
Test.Assert(cVal == 0x305);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue