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); }
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); }
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); }
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); }
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); }
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); }