public void CreateToken_IdentifierPattern_Identifier()
        {
            const string text = "  a1vd ";

            var token = MockRepository.GenerateStub<IToken>();
            var lexicalRule = MockRepository.GenerateMock<ILexicalRule>();
            lexicalRule.Expect(r => r.Pattern).Return(IdentifierExpression);
            lexicalRule.Expect(r => r.TokenFactory).Return(
                builder =>
                {
                    token.Stub(t => t.Lexeme).Return(builder.Lexeme);
                    token.Stub(t => t.LeftTrivia).Return(builder.LeftTrivia);
                    token.Stub(t => t.RightTrivia).Return(builder.RightTrivia);
                    return token;
                });

            var compiledLexicalRule = new CompiledLexicalRule(lexicalRule);
            var actualToken = compiledLexicalRule.CreateToken(text);

            Assert.That(actualToken, Is.SameAs(token));
            Assert.That(token.Lexeme, Is.EqualTo("a1vd"));
            Assert.That(token.LeftTrivia, Is.EqualTo("  "));
            Assert.That(token.RightTrivia, Is.EqualTo(" "));
            lexicalRule.VerifyAllExpectations();
        }
        public void CreateToken_CustomText_UseTokenFactory()
        {
            const string patternt = "pattern";
            const string text = "a1vd";

            var token = MockRepository.GenerateStub<IToken>();
            var lexicalRule = MockRepository.GenerateStub<ILexicalRule>();
            lexicalRule.Stub(r => r.Pattern).Return(patternt);
            lexicalRule.Stub(r => r.TokenFactory).Return(builder => token);

            var compiledLexicalRule = new CompiledLexicalRule(lexicalRule);
            compiledLexicalRule.CreateToken(text);
            lexicalRule.VerifyAllExpectations();
        }