Пример #1
0
        public void TestThatAfterSuccessParsingStreamCursorHasRightPosition()
        {
            // Arrange

            var symbol1 = 'a';
            var symbol2 = 'c';

            var additionRule = $"\'{symbol2}\'";
            var str          = $"{DisjunctionRuleParser.Symbol}\'{symbol2}\'{additionRule}";

            var stream = new MemoryStream().FromString(str);
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);
            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            parser.Parse(context);

            // Assert

            Assert.AreEqual(str.Length - additionRule.Length, context.CurrentStream.Position);
        }
Пример #2
0
        public void TestThatSuccessParsingGroup()
        {
            // Arrange

            var symbol1 = 'a';
            var symbol2 = 'b';

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}(\'{symbol2}\'\'{symbol2}\')");
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);


            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var canParsed = parser.IsCurrentRule(context);

            // Assert

            Assert.IsTrue(canParsed);
        }
Пример #3
0
        public void TestThatFailedParsingWithoutArguments()
        {
            // Arrange

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}");
            var parser = new DisjunctionRuleParser();

            var context = new DefaultParserContext(stream: stream);

            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var action = new Action(() => parser.Parse(context));

            // Assert

            Assert.ThrowsException <RuleParserNotExistedLeftArgumentException>(action);
        }
Пример #4
0
        public void TestThatFailedChekingWithoutArguments()
        {
            // Arrange

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}");
            var parser = new DisjunctionRuleParser();

            var context = new DefaultParserContext(stream: stream);

            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var canParsed = parser.IsCurrentRule(context);

            // Assert

            Assert.IsFalse(canParsed);
        }
Пример #5
0
        public void TestThatSuccessParsing()
        {
            // Arrange

            var symbol1 = 'a';
            var symbol2 = 'c';

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}\'{symbol2}\'");
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);
            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var parsed = parser.Parse(context);

            // Assert

            Assert.IsInstanceOfType(parsed, typeof(DisjunctionRule));
            var converted = (DisjunctionRule)parsed;

            Assert.IsNotNull(converted.LeftArgumentRule);
            Assert.IsNotNull(converted.RightArgumentRule);

            var leftConverted  = (SymbolRule)converted.LeftArgumentRule;
            var rightConverted = (SymbolRule)converted.RightArgumentRule;

            Assert.AreSame(leftArgument, leftConverted);

            Assert.AreEqual(leftConverted.Symbol, symbol1);
            Assert.AreEqual(rightConverted.Symbol, symbol2);

            Assert.IsNotNull(converted.LeftArgumentRule);
        }
Пример #6
0
        public void TestThatFailedParsingWithoutLastSymbol()
        {
            // Arrange

            var symbol1 = 'a';

            var stream = new MemoryStream().FromString($"{DisjunctionRuleParser.Symbol}");
            var parser = new DisjunctionRuleParser();

            var context      = new DefaultParserContext(stream: stream);
            var leftArgument = new SymbolRule(symbol1);

            context.ParsedRules.Push(leftArgument);
            context.LexerBuilder = new LexerBuilder(new SimpleParserInjector());

            // Act

            var action = new Action(() => parser.Parse(context));

            // Assert

            Assert.ThrowsException <CantParseRightArgumentException>(action);
        }