/// <summary> /// Initializes a new instance of the <see cref="Print"/> class. /// </summary> /// <param name="runEnvironment">Run time environment.</param> /// <param name="expressionEvaluator">Expression evaluator.</param> /// <param name="teletype">Output teletype to use.</param> public Print(IRunEnvironment runEnvironment, IExpressionEvaluator expressionEvaluator, ITeletypeWithPosition teletype) : base("PRINT", TokenClass.Statement, TokenType.Print) { _runEnvironment = runEnvironment; _expressionEvaluator = expressionEvaluator; _teletype = teletype; }
/// <summary> /// Initializes a new instance of the <see cref="Get"/> class. /// </summary> /// <param name="runEnvironment">Run time environment.</param> /// <param name="expressionEvaluator">Expression evaluator.</param> /// <param name="teletypeWithPosition">Teletype.</param> public Get( IRunEnvironment runEnvironment, IExpressionEvaluator expressionEvaluator, ITeletypeWithPosition teletypeWithPosition) : base("GET", TokenClass.Statement) { _runEnvironment = runEnvironment; _expressionEvaluator = expressionEvaluator; _teletypeWithPosition = teletypeWithPosition; }
public void TeletypeWithPositionForwardsReadChar() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.ReadChar()).Returns('A'); _sut = new TeletypeWithPosition(_mockTeletype.Object); var readChar = _sut.ReadChar(); _mockTeletype.Verify(mt => mt.ReadChar(), Times.Once); Assert.AreEqual('A', readChar); }
public void TeletypeWithPositionForwardsWrites() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.Write("HELLO"); _mockTeletype.Verify(mt => mt.Write("HELLO"), Times.Once); Assert.AreEqual(6, _sut.Position()); }
public void TeletypeWithPositionWritesEnvironmentNewLine() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.NewLine(); _mockTeletype.Verify(mt => mt.Write(Environment.NewLine), Times.Once); Assert.AreEqual(1, _sut.Position()); }
/// <summary> /// Initializes a new instance of the <see cref="Interpreter"/> class. /// </summary> /// <param name="teletypeWithPosition">Teletype to use for input output.</param> /// <param name="tokeniser">Tokeniser.</param> /// <param name="runEnvironment">Run time environment.</param> /// <param name="programRepository">Program repository.</param> /// <param name="executor">Executor class to run program lines.</param> public Interpreter( ITeletypeWithPosition teletypeWithPosition, ITokeniser tokeniser, IRunEnvironment runEnvironment, IProgramRepository programRepository, IExecutor executor) { _teletypeWithPosition = teletypeWithPosition; _tokeniser = tokeniser; _runEnvironment = runEnvironment; _programRepository = programRepository; _executor = executor; }
public void TeletypeWithPositionForwardsReads() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _mockTeletype.Setup(mt => mt.Read()).Returns("RUN"); _sut.Write(">"); Assert.AreNotEqual(1, _sut.Position()); var result = _sut.Read(); Assert.AreEqual("RUN", result); Assert.AreEqual(1, _sut.Position()); }
public void TestOutOfRangeParametersToTab(int parameter, bool throwsException) { bool exceptionThrown = false; _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); try { _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.Tab((short)parameter); } catch (ClassicBasic.Interpreter.Exceptions.IllegalQuantityException) { exceptionThrown = true; } Assert.AreEqual(throwsException, exceptionThrown); }
public void TeletypeWithPositionCommasInCorrectPlace( int beforeSpaceCount, string output, int expectedBefore, int expectedAfter) { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.Space((short)beforeSpaceCount); var actualBefore = _sut.Position(); _sut.Write(output); _sut.NextComma(); var actualAfter = _sut.Position(); Assert.AreEqual(expectedBefore, actualBefore); Assert.AreEqual(expectedAfter, actualAfter); }
/// <summary> /// Initializes a new instance of the <see cref="Pos"/> class. /// </summary> /// <param name="teletypeWithPosition">Teletype to get the cursor position for.</param> public Pos(ITeletypeWithPosition teletypeWithPosition) : base("POS", TokenClass.Function) { _teletypeWithPosition = teletypeWithPosition; }