diff --git a/YesNt.Interpreter.Tests/CodeFowTests.cs b/YesNt.Interpreter.Tests/CodeFowTests.cs new file mode 100644 index 0000000..105b253 --- /dev/null +++ b/YesNt.Interpreter.Tests/CodeFowTests.cs @@ -0,0 +1,44 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using System.Collections.Generic; + +namespace YesNt.Interpreter.Tests; + +[TestClass] +public class CodeFlowTests +{ + [TestMethod] + public void FunctionTest() + { + List lines = new List() + { + "cal yes", + "fnc yes", + "!result" + }; + YesNtAssert.IsLastLineEqual(lines, "1"); + } + + [TestMethod] + public void LabelsTest() + { + List lines = new List() + { + "result" + }; + YesNtAssert.IsLastLineEqual(lines, "1"); + } + + [TestMethod] + public void CalculationsTest() + { + Assert.Inconclusive(); + YesNtAssert.IsLineEqual("10 * 10 !calc", (20).ToString()); + } +} \ No newline at end of file diff --git a/YesNt.Interpreter.Tests/YesNt.Interpreter.Tests.csproj b/YesNt.Interpreter.Tests/YesNt.Interpreter.Tests.csproj new file mode 100644 index 0000000..cf7cd15 --- /dev/null +++ b/YesNt.Interpreter.Tests/YesNt.Interpreter.Tests.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + + false + + + + + + + + + + + + + + diff --git a/YesNt.Interpreter.Tests/YesNtAssert.cs b/YesNt.Interpreter.Tests/YesNtAssert.cs new file mode 100644 index 0000000..e7ae5f7 --- /dev/null +++ b/YesNt.Interpreter.Tests/YesNtAssert.cs @@ -0,0 +1,63 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using System; +using System.Collections.Generic; +using System.Threading; + +using YesNt.Interpreter.Runtime; + +namespace YesNt.Interpreter.Tests; + +internal static class YesNtAssert +{ + private static readonly YesNtInterpreter yesNtInterpreter = new YesNtInterpreter(); + + static YesNtAssert() + { + yesNtInterpreter.Initialize(); + } + + public static void IsLastLineEqual(List lines, string expected, int timeout = 1000) + { + AutoResetEvent onDone = new AutoResetEvent(false); + + DebugEventArgs debugEventArgs = new DebugEventArgs(); + yesNtInterpreter.OnLineExecuted += (er) => + { + debugEventArgs = er ?? debugEventArgs; + + if (er is null) + { + onDone.Set(); + } + }; + + yesNtInterpreter.Execute(lines, true); + + _ = onDone.WaitOne(TimeSpan.FromSeconds(timeout)); + + Assert.AreEqual(expected, debugEventArgs.CurrentLine); + } + + public static void IsLineEqual(string line, string expected, int timeout = 1000) + { + AutoResetEvent onDone = new AutoResetEvent(false); + List lines = new List() + { + line + }; + + DebugEventArgs debugEventArgs = new DebugEventArgs(); + yesNtInterpreter.OnLineExecuted += (er) => + { + debugEventArgs = er ?? debugEventArgs; + onDone.Set(); + }; + + yesNtInterpreter.Execute(lines, true); + + _ = onDone.WaitOne(TimeSpan.FromMilliseconds(timeout)); + + Assert.AreEqual(expected, debugEventArgs.CurrentLine); + } +} \ No newline at end of file