PorygonSharp/PorygonSharpTests/EnumUserdataTest.cs

54 lines
1.6 KiB
C#

using System;
using NUnit.Framework;
using PorygonSharp;
using PorygonSharp.UserData;
namespace PorygonSharpTests
{
public class EnumUserdataTest
{
private enum testEnum
{
One, Two, Three, Foo, Bar
}
[Test]
public void AbleToAccessStaticEnumVariable()
{
UserDataHandler.RegisterEnumType("testEnum", typeof(testEnum));
StaticScope.RegisterStaticVariable("testEnum", testEnum.One);
using (var script = new Script(@"
return type(testEnum)
"))
{
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
var result = script.Evaluate();
Assert.AreEqual("userdata", result.EvaluateString());
}
}
[Test]
public void AbleToUseStaticEnumVariable()
{
UserDataHandler.RegisterEnumType("testEnum", typeof(testEnum));
StaticScope.RegisterStaticVariable("testEnum", testEnum.One);
using (var script = new Script(@"
return testEnum.Three + 2
"))
{
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
var result = script.Evaluate();
Assert.AreEqual(4, result.EvaluateInteger());
}
}
}
}