/// <summary> /// Executes the GET command. /// </summary> public void Execute() { if (!_runEnvironment.CurrentLine.LineNumber.HasValue) { throw new Exceptions.IllegalDirectException(); } var variableReference = _expressionEvaluator.GetLeftValue(); var newChar = _teletypeWithPosition.ReadChar(); Accumulator newValue; if (variableReference.IsString) { newValue = new Accumulator(newChar.ToString()); } else { if ("+-E.\0".Contains(newChar.ToString())) { newChar = '0'; } if (newChar < '0' || newChar > '9') { throw new Exceptions.SyntaxErrorException(); } newValue = new Accumulator((double)(newChar - '0')); } variableReference.SetValue(newValue); }
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); }