2019-08-18 13:54:39 +00:00
|
|
|
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()
|
|
|
|
{
|
2019-09-19 13:44:39 +00:00
|
|
|
StaticScope.RegisterStaticEnum("testEnum", typeof(testEnum));
|
2019-08-18 13:54:39 +00:00
|
|
|
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()
|
|
|
|
{
|
2019-09-19 13:44:39 +00:00
|
|
|
StaticScope.RegisterStaticEnum("testEnum", typeof(testEnum));
|
2019-08-18 13:54:39 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|