Support for enums, and adding static variables
This commit is contained in:
54
PorygonSharpTests/EnumUserdataTest.cs
Normal file
54
PorygonSharpTests/EnumUserdataTest.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user