KeywordTests.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.PrintSingleLine("big guy 4 u", false), Moq.Times.Once);
  46. }
  47. [Test]
  48. public void PrintImg()
  49. {
  50. var console = new Mock<IConsole>();
  51. Common.Run("PRINT_IMG image", console.Object);
  52. console.Verify(x => x.PrintImg("image"), Moq.Times.Once);
  53. }
  54. [Test]
  55. public void PrintButton()
  56. {
  57. var console = new Mock<IConsole>();
  58. Common.Run("PRINTBUTTON \"button to press\", 50", console.Object);
  59. console.Verify(x => x.PrintButton("button to press", 50), Moq.Times.Once);
  60. }
  61. public void ClearLine(string keyword, string operand)
  62. {
  63. var console = new Mock<IConsole>();
  64. string code =
  65. @"PRINT something
  66. CLEARLINE 1";
  67. Common.Run(code, console.Object);
  68. console.Verify(x => x.Write("something"), Moq.Times.Once);
  69. console.Verify(x => x.deleteLine(1), Moq.Times.Once);
  70. }
  71. [Test]
  72. public void DrawLine()
  73. {
  74. var console = new Mock<IConsole>();
  75. Common.Run("DRAWLINE", console.Object);
  76. console.Verify(x => x.PrintBar(), Moq.Times.Once);
  77. }
  78. [TestCase("-")]
  79. [TestCase("=")]
  80. [TestCase("━")]
  81. public void DrawLineCustom(string character)
  82. {
  83. var console = new Mock<IConsole>();
  84. Common.Run($"CUSTOMDRAWLINE {character}", console.Object);
  85. console.Verify(x => x.printCustomBar(character), Moq.Times.Once);
  86. }
  87. #endregion
  88. #region Arithmetic
  89. [Test]
  90. public void Times()
  91. {
  92. string code =
  93. @"LOCAL = 5
  94. TIMES LOCAL, 1.5";
  95. var interpreter = Common.Run(code);
  96. Common.AssertLocal(interpreter, 7.5);
  97. }
  98. #endregion
  99. }
  100. }