コード例 #1
0
        private IScanner CreateMockScanner(TokenList programTokens, bool createProgramBase = true)
        {
            Queue <KeyValuePair <TokenType, string> > tokens;

            if (createProgramBase)
            {
                tokens = new Queue <KeyValuePair <TokenType, string> >(new TokenList()
                {
                    { TokenType.KwProgram },
                    { TokenType.Identifier, "testprog" },
                    { TokenType.LineTerm },
                    { TokenType.KwBegin }
                });
                programTokens.ForEach(tokens.Enqueue);
                tokens.Enqueue(new KeyValuePair <TokenType, string>(TokenType.KwEnd, ""));
                tokens.Enqueue(new KeyValuePair <TokenType, string>(TokenType.OpDot, ""));
            }
            else
            {
                tokens = new Queue <KeyValuePair <TokenType, string> >(programTokens);
            }
            Func <Token> nextToken = () =>
            {
                if (tokens.Count > 0)
                {
                    var newToken = tokens.Dequeue();
                    return(new Token(newToken.Key, 0, 0, newToken.Value));
                }
                return(new Token(TokenType.EOF, 0, 0));
            };
            var mock = new Mock <IScanner>();

            mock.Setup(x => x.GetNextToken()).Returns(nextToken);
            return(mock.Object);
        }