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

More tests for generic constraints and mixins

This commit is contained in:
Brian Fiete 2020-06-03 12:08:37 -07:00
parent c90db82b52
commit f6f94ed40c
2 changed files with 50 additions and 0 deletions

View 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);
}
}
}

View file

@ -4,6 +4,13 @@ namespace Tests
{
class Mixins
{
static mixin MixNums(int a, int b)
{
(a << 8) | b
}
const int cVal = MixNums!(3, 5);
class MixClass
{
public int mA = 100;
@ -39,6 +46,7 @@ namespace Tests
mc.MixB!(10);
Test.Assert(mc.mA == 120);
Test.Assert(MixClass.MixC!(30) == 230);
Test.Assert(cVal == 0x305);
}
[Test]