KeywordTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Moq;
  2. using NTERA.Core;
  3. using NUnit.Framework;
  4. namespace NTERA.Interpreter.Tests
  5. {
  6. [TestFixture]
  7. public class KeywordTests
  8. {
  9. #region Console
  10. [TestCase("PRINTV")]
  11. public void WriteV(string keyword)
  12. {
  13. var console = new Mock<IConsole>();
  14. string code = $@"{keyword} 69";
  15. Common.Run(code, console.Object);
  16. console.Verify(x => x.Write("69"), Moq.Times.Once);
  17. }
  18. [TestCase("PRINTFORM", "%LOCALS%")]
  19. public void WriteS(string keyword, string operand)
  20. {
  21. var console = new Mock<IConsole>();
  22. string code =
  23. $@"LOCALS = big guy 4 u
  24. {keyword} {operand}";
  25. Common.Run(code, console.Object);
  26. console.Verify(x => x.Write("big guy 4 u"), Moq.Times.Once);
  27. }
  28. [TestCase("PRINT", "{LOCALS}", "{LOCALS}")]
  29. [TestCase("PRINTFORMS", "\"TEXT\"", "TEXT")]
  30. public void WriteLiteral(string keyword, string input, string output)
  31. {
  32. var console = new Mock<IConsole>();
  33. string code = $"{keyword} {input}";
  34. Common.Run(code, console.Object);
  35. console.Verify(x => x.Write(output), Moq.Times.Once);
  36. }
  37. [TestCase("PRINTFORML", "{LOCALS}")]
  38. public void Print(string keyword, string operand)
  39. {
  40. var console = new Mock<IConsole>();
  41. string code =
  42. $@"LOCALS = big guy 4 u
  43. {keyword} {operand}";
  44. Common.Run(code, console.Object);
  45. console.Verify(x => x.Write("big guy 4 u"), Moq.Times.Once);
  46. console.Verify(x => x.NewLine(), Moq.Times.Once);
  47. }
  48. [Test]
  49. public void PrintImg()
  50. {
  51. var console = new Mock<IConsole>();
  52. Common.Run("PRINT_IMG image", console.Object);
  53. console.Verify(x => x.PrintImg("image"), Moq.Times.Once);
  54. }
  55. [Test]
  56. public void PrintButton()
  57. {
  58. var console = new Mock<IConsole>();
  59. Common.Run("PRINTBUTTON \"button to press\", 50", console.Object);
  60. console.Verify(x => x.PrintButton("button to press", 50), Moq.Times.Once);
  61. }
  62. public void ClearLine(string keyword, string operand)
  63. {
  64. var console = new Mock<IConsole>();
  65. string code =
  66. @"PRINT something
  67. CLEARLINE 1";
  68. Common.Run(code, console.Object);
  69. console.Verify(x => x.Write("something"), Moq.Times.Once);
  70. console.Verify(x => x.deleteLine(1), Moq.Times.Once);
  71. }
  72. [Test]
  73. public void DrawLine()
  74. {
  75. var console = new Mock<IConsole>();
  76. Common.Run("DRAWLINE", console.Object);
  77. console.Verify(x => x.PrintBar(), Moq.Times.Once);
  78. }
  79. [TestCase("-")]
  80. [TestCase("=")]
  81. [TestCase("━")]
  82. public void DrawLineCustom(string character)
  83. {
  84. var console = new Mock<IConsole>();
  85. Common.Run($"CUSTOMDRAWLINE {character}", console.Object);
  86. console.Verify(x => x.printCustomBar(character), Moq.Times.Once);
  87. }
  88. #endregion
  89. #region Arithmetic
  90. [Test]
  91. public void Times()
  92. {
  93. string code =
  94. @"LOCAL = 5
  95. TIMES LOCAL, 1.5";
  96. var interpreter = Common.Run(code);
  97. Common.AssertLocal(interpreter, 7.5);
  98. }
  99. #endregion
  100. }
  101. }