Make print() script function changeable, defaults to Console.WriteLine

This commit is contained in:
2019-07-21 12:34:13 +02:00
parent 58da41852d
commit d452a740f0
4 changed files with 56 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using PorygonSharp;
@@ -122,11 +123,26 @@ namespace PorygonSharpTests
}
}
[Test]
public void TestPrint()
{
using (var script = new Script("print('test')"))
{
using (var sw = new StringWriter())
{
Console.SetOut(sw);
Assert.False(script.Diagnostics.HasErrors());
script.Evaluate();
var s = sw.ToString();
Assert.AreEqual("test\n", s);
}
}
}
[Test]
public void TestHash()
{
var hash = HashedString.ScriptHash("Foo");
var hash = "Foo".ScriptHash();
Assert.AreEqual(193501609, hash);
}
}