123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 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<IConsole>();
- 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<IConsole>();
- 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<IConsole>();
- 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<IConsole>();
- 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<IConsole>();
- Common.Run("PRINT_IMG image", console.Object);
- console.Verify(x => x.PrintImg("image"), Moq.Times.Once);
- }
- [Test]
- public void PrintButton()
- {
- var console = new Mock<IConsole>();
- 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<IConsole>();
- 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<IConsole>();
- 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<IConsole>();
- 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
- }
- }
|