97 lines
2.7 KiB
C#
97 lines
2.7 KiB
C#
|
using System;
|
||
|
using NUnit.Framework;
|
||
|
using PorygonSharp;
|
||
|
|
||
|
namespace PorygonSharpTests
|
||
|
{
|
||
|
public class Tests
|
||
|
{
|
||
|
[Test]
|
||
|
public void Test1()
|
||
|
{
|
||
|
using (var script = new Script("true"))
|
||
|
{
|
||
|
var diags = script.Diagnostics.GetDiagnostics();
|
||
|
foreach (var diag in diags)
|
||
|
{
|
||
|
throw new Exception(diag.GetCode().ToString());
|
||
|
}
|
||
|
Assert.False(script.Diagnostics.HasErrors());
|
||
|
}
|
||
|
}
|
||
|
[Test]
|
||
|
public void Test2()
|
||
|
{
|
||
|
using (var script = new Script("1+true"))
|
||
|
{
|
||
|
Assert.True(script.Diagnostics.HasErrors());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Test3()
|
||
|
{
|
||
|
using (var script = new Script("1+10"))
|
||
|
{
|
||
|
script.Evaluate();
|
||
|
var lastVal = script.GetLastValue();
|
||
|
Assert.AreEqual(TypeClass.Number, lastVal.GetTypeClass());
|
||
|
var val = lastVal.EvaluateInteger();
|
||
|
Assert.AreEqual(11, val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Test4()
|
||
|
{
|
||
|
using (var script = new Script("1+10.24"))
|
||
|
{
|
||
|
script.Evaluate();
|
||
|
var lastVal = script.GetLastValue();
|
||
|
Assert.AreEqual(TypeClass.Number, lastVal.GetTypeClass());
|
||
|
var val = lastVal.EvaluateFloat();
|
||
|
Assert.AreEqual(11.24d, val, 5);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Test5()
|
||
|
{
|
||
|
using (var script = new Script("true and true"))
|
||
|
{
|
||
|
script.Evaluate();
|
||
|
var lastVal = script.GetLastValue();
|
||
|
Assert.AreEqual(TypeClass.Bool, lastVal.GetTypeClass());
|
||
|
var val = lastVal.EvaluateBool();
|
||
|
Assert.AreEqual(true, val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Test6()
|
||
|
{
|
||
|
using (var script = new Script("'foo' + 'bar'"))
|
||
|
{
|
||
|
script.Evaluate();
|
||
|
var lastVal = script.GetLastValue();
|
||
|
Assert.AreEqual(TypeClass.String, lastVal.GetTypeClass());
|
||
|
var val = lastVal.EvaluateString();
|
||
|
Assert.AreEqual("foobar", val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Test7()
|
||
|
{
|
||
|
using (var script = new Script("a = 100 + 50"))
|
||
|
{
|
||
|
script.Evaluate();
|
||
|
var variable = script.GetVariable("a");
|
||
|
Assert.AreEqual(TypeClass.Number, variable.GetTypeClass());
|
||
|
var val = variable.EvaluateInteger();
|
||
|
Assert.AreEqual(150, val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|