예제 #1
0
        /// <summary>
        /// Executes the PRINT command.
        /// </summary>
        public void Execute()
        {
            bool newLine = true;

            while (true)
            {
                var token = _runEnvironment.CurrentLine.NextToken();
                if ((token.Seperator == TokenType.Colon) ||
                    (token.Statement == TokenType.Else) ||
                    (token.Seperator == TokenType.EndOfLine))
                {
                    if (newLine)
                    {
                        _teletype.NewLine();
                    }

                    _runEnvironment.CurrentLine.PushToken(token);
                    return;
                }

                if ((token.Statement == TokenType.Tab) || (token.Statement == TokenType.Space))
                {
                    short value = _expressionEvaluator.GetExpression().ValueAsShort();
                    if (_runEnvironment.CurrentLine.NextToken().Seperator != TokenType.CloseBracket)
                    {
                        throw new Exceptions.SyntaxErrorException();
                    }

                    if (token.Statement == TokenType.Tab)
                    {
                        _teletype.Tab(value);
                    }
                    else
                    {
                        _teletype.Space(value);
                    }
                }
                else if ((token.Seperator == TokenType.Semicolon) || (token.Seperator == TokenType.Comma))
                {
                    newLine = false;
                    if (token.Seperator == TokenType.Comma)
                    {
                        _teletype.NextComma();
                    }
                }
                else
                {
                    newLine = true;
                    _runEnvironment.CurrentLine.PushToken(token);
                    _teletype.Write(_expressionEvaluator.GetExpression().ToString());
                }
            }
        }
        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);
        }