コード例 #1
0
        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();
        }
コード例 #2
0
        public void Constructor_LexicalRule_Same()
        {
            var lexicalRule = MockRepository.GenerateStub<ILexicalRule>();
            lexicalRule.Stub(x => x.Pattern).Return("pattern");
            var compiledLexicalRule = new CompiledLexicalRule(lexicalRule);

            Assert.That(compiledLexicalRule.LexicalRule, Is.SameAs(lexicalRule));
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void IsMatch_IdentifierAndIdentifierPattern_True()
        {
            const string text = "  a1vd ";

            var lexicalRule = MockRepository.GenerateMock<ILexicalRule>();
            lexicalRule.Expect(r => r.Pattern).Return(IdentifierExpression);
            var compiledLexicalRule = new CompiledLexicalRule(lexicalRule);

            Assert.That(compiledLexicalRule.IsMatch(text), Is.True);
            lexicalRule.VerifyAllExpectations();
        }
コード例 #5
0
        public void IsWrongRule_WrongPattern_True()
        {
            const string pattern = @"^(?<e>[\s\S]*)$";
            const string text = "  a1vd bu ";

            var lexicalRule = MockRepository.GenerateMock<ILexicalRule>();
            lexicalRule.Expect(r => r.Pattern).Return(pattern);
            var compiledLexicalRule = new CompiledLexicalRule(lexicalRule);

            Assert.That(compiledLexicalRule.IsMatch(text), Is.True);
            Assert.That(compiledLexicalRule.IsWrongRule(text), Is.True);
            lexicalRule.VerifyAllExpectations();
        }