using Moq; using NTERA.Core; using NUnit.Framework; namespace NTERA.Interpreter.Tests { [TestFixture] public class KeywordTests { #region Console [TestCase("PRINTV")] public void WriteV(string keyword) { var console = new Mock(); string code = $@"{keyword} 69"; Common.Run(code, console.Object); console.Verify(x => x.Write("69"), Moq.Times.Once); } [TestCase("PRINTFORM", "%LOCALS%")] public void WriteS(string keyword, string operand) { var console = new Mock(); string code = $@"LOCALS = big guy 4 u {keyword} {operand}"; Common.Run(code, console.Object); console.Verify(x => x.Write("big guy 4 u"), Moq.Times.Once); } [TestCase("PRINT", "{LOCALS}", "{LOCALS}")] [TestCase("PRINTFORMS", "\"TEXT\"", "TEXT")] public void WriteLiteral(string keyword, string input, string output) { var console = new Mock(); string code = $"{keyword} {input}"; Common.Run(code, console.Object); console.Verify(x => x.Write(output), Moq.Times.Once); } [TestCase("PRINTFORML", "{LOCALS}")] public void Print(string keyword, string operand) { var console = new Mock(); string code = $@"LOCALS = big guy 4 u {keyword} {operand}"; Common.Run(code, console.Object); console.Verify(x => x.PrintSingleLine("big guy 4 u", false), Moq.Times.Once); } [Test] public void PrintImg() { var console = new Mock(); Common.Run("PRINT_IMG image", console.Object); console.Verify(x => x.PrintImg("image"), Moq.Times.Once); } [Test] public void PrintButton() { var console = new Mock(); Common.Run("PRINTBUTTON \"button to press\", 50", console.Object); console.Verify(x => x.PrintButton("button to press", 50), Moq.Times.Once); } public void ClearLine(string keyword, string operand) { var console = new Mock(); string code = @"PRINT something CLEARLINE 1"; Common.Run(code, console.Object); console.Verify(x => x.Write("something"), Moq.Times.Once); console.Verify(x => x.deleteLine(1), Moq.Times.Once); } [Test] public void DrawLine() { var console = new Mock(); Common.Run("DRAWLINE", console.Object); console.Verify(x => x.PrintBar(), Moq.Times.Once); } [TestCase("-")] [TestCase("=")] [TestCase("━")] public void DrawLineCustom(string character) { var console = new Mock(); Common.Run($"CUSTOMDRAWLINE {character}", console.Object); console.Verify(x => x.printCustomBar(character), Moq.Times.Once); } #endregion #region Arithmetic [Test] public void Times() { string code = @"LOCAL = 5 TIMES LOCAL, 1.5"; var interpreter = Common.Run(code); Common.AssertLocal(interpreter, 7.5); } #endregion } }