1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-17 23:56:05 +02:00
Beef/IDEHelper/Tests/src/Mixins.bf

61 lines
787 B
Beef
Raw Normal View History

2019-08-23 11:56:54 -07:00
using System;
namespace Tests
{
class Mixins
{
class MixClass
{
public int mA = 100;
public mixin MixA(var addTo)
{
mA += addTo;
}
2019-12-11 12:55:01 -08:00
public mixin MixB(var addTo)
{
void AddIt()
{
mA += addTo;
}
AddIt();
}
2019-08-23 11:56:54 -07:00
}
[Test]
public static void TestBasics()
{
MixClass mc = scope MixClass();
mc.MixA!(10);
Test.Assert(mc.mA == 110);
2019-12-11 12:55:01 -08:00
mc.MixB!(10);
Test.Assert(mc.mA == 120);
2019-08-23 11:56:54 -07:00
}
[Test]
public static void TestLocalMixin()
{
mixin AppendAndNullify(String str)
{
int a = 1;
a++;
str.Append("B");
str = null;
}
int a = 2;
a++;
String str0 = scope String("A");
String str1 = str0;
AppendAndNullify!(str0);
Test.Assert(str0 == null);
Test.Assert(str1 == "AB");
}
2019-12-11 12:55:01 -08:00
2019-08-23 11:56:54 -07:00
}
}