示例#1
0
        public void DefDefinesFunctionAndDoesntEatColon()
        {
            var tokens = new List <IToken>
            {
                new Token("FN", TokenClass.Statement, TokenType.Fn),
                new Token("NAME"),
                new Token("(", TokenClass.Seperator, TokenType.OpenBracket),
                new Token("A"),
                new Token(")", TokenClass.Seperator, TokenType.CloseBracket),
                new Token("=", TokenClass.Seperator, TokenType.Equal),
                new Token("A"),
                new Token("*", TokenClass.Seperator, TokenType.Multiply),
                new Token("A"),
                new Token(":", TokenClass.Seperator, TokenType.Colon)
            };

            _runEnvironment      = new RunEnvironment();
            _variableRepository  = new VariableRepository();
            _expressionEvaluator = new ExpressionEvaluator(_variableRepository, _runEnvironment);
            var programLine = new ProgramLine(10, tokens);

            _runEnvironment.CurrentLine = programLine;

            var sut = new Def(_runEnvironment, _expressionEvaluator);

            sut.Execute();

            Assert.AreEqual(TokenType.Colon, _runEnvironment.CurrentLine.NextToken().Seperator);
            var definition = _runEnvironment.DefinedFunctions["NAME"];

            Assert.AreEqual("NAME", definition.FunctionName);
            Assert.AreEqual("A", definition.VariableName);
            Assert.AreEqual(6, definition.LineToken);
            Assert.AreEqual(programLine, definition.Line);
        }