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()); }
/// <summary> /// Executes the interpreter. /// </summary> public void Execute() { bool quit = false; while (!quit) { _teletypeWithPosition.NewLine(); _teletypeWithPosition.Write(">"); var command = _teletypeWithPosition.Read(); if (command == null) { _runEnvironment.KeyboardBreak = false; continue; } try { var parsedLine = _tokeniser.Tokenise(command); if (parsedLine.LineNumber.HasValue) { _programRepository.SetProgramLine(parsedLine); } else { _runEnvironment.CurrentLine = parsedLine; quit = _executor.ExecuteLine(); } } catch (Exceptions.BreakException endError) { if (endError.ErrorMessage != string.Empty) { WriteErrorToTeletype( _runEnvironment.CurrentLine.LineNumber, endError.ErrorMessage); } } catch (Exceptions.BasicException basicError) { WriteErrorToTeletype( _runEnvironment.DataErrorLine ?? _runEnvironment.CurrentLine?.LineNumber, "?" + basicError.ErrorMessage + " ERROR"); } } }