Skip to content

Commit

Permalink
Got constrained callvirt working.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Mar 6, 2016
1 parent 559ee85 commit c12022c
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 315 deletions.
72 changes: 72 additions & 0 deletions Tests/SimpleStructsAndArraysTest/ConstrainedTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cosmos.TestRunner;

namespace SimpleStructsAndArraysTest
{
public interface ITestMutate
{
void Mutate();
}

public struct MyStruct1 : ITestMutate
{
public int a;

public void Mutate()
{
a++;
}
}

public struct MyStruct2
{
public int b;

public override string ToString()
{
b++;
return b.ToString();
}
}

internal struct MyStruct3
{
public int c;

public override string ToString()
{
c = 1;
return c.ToString();
}
}

public static class ConstrainedTest
{
public static void DoMutate<T>(ref T a) where T : ITestMutate
{
a.Mutate();
}

public static void MutateStructTest()
{
var xS1 = new MyStruct1();
Assert.IsTrue(xS1.a == 0, "xS1.a == 0");
DoMutate(ref xS1);
Assert.IsTrue(xS1.a == 1, "xS1.a == 1");

var xS2 = new MyStruct2();
Assert.IsTrue(xS2.b == 0, "xS2.b == 0");
Assert.IsTrue(xS2.ToString() == "1", "xS2.ToString() == '1'");
Assert.IsTrue(xS2.b == 1, "xS2.b == 1");

var xS3 = new MyStruct3();
Assert.IsTrue(xS3.c == 0, "xS3.b == 0");
Assert.IsTrue(xS3.ToString() == "1", "xS3.ToString() == '1'");
Assert.IsTrue(xS3.c == 1, "xS3.b == 1");
}
}
}
Loading

0 comments on commit c12022c

Please sign in to comment.