diff --git a/tests/ParserTests/EBNFTests.cs b/tests/ParserTests/EBNFTests.cs index 21263724..9e3f489b 100644 --- a/tests/ParserTests/EBNFTests.cs +++ b/tests/ParserTests/EBNFTests.cs @@ -769,6 +769,36 @@ public string B(List> bstr) return "B()"; } + + [Production("Ba : b* a")] + public string Ba(List> bstr, Token a) { + var result = "Ba("; + if (bstr.Any()) + { + result += bstr + .Select(b => b.Value) + .Aggregate((b1, b2) => b1 + ", " + b2); + result += ", "; + } + + result += a.Value; + result += ")"; + return result; + } + [Production("BA : b* A")] + public string BA(List> bstr, string a) { + var result = "BA("; + if (bstr.Any()) + { + result += bstr + .Select(b => b.Value) + .Aggregate((b1, b2) => b1 + ", " + b2); + result += ", "; + } + result += a; + result += ")"; + return result; + } @@ -1060,7 +1090,7 @@ public void TestParseBuild() Check.That(buildResult.IsError).IsFalse(); Parser = buildResult.Result; Check.That(Parser.SyntaxParser).IsInstanceOf>(); - Check.That(Parser.Configuration.NonTerminals).CountIs(4); + Check.That(Parser.Configuration.NonTerminals).CountIs(6); var nt = Parser.Configuration.NonTerminals["R"]; Check.That(nt.Rules).CountIs(2); @@ -1087,6 +1117,34 @@ public void TestZeroOrMoreWithMany() Check.That(result.IsError).IsFalse(); Check.That(result.Result).IsEqualTo("R(A(a),B(b, b),c)"); } + + [Fact] + public void TestZeroOrMoreStarterFollowedByTerminal() + { + var buildResult = BuildParser(); + Check.That(buildResult.IsError).IsFalse(); + Parser = buildResult.Result; + var result = Parser.Parse("bbb a","Ba"); + Check.That(result.IsError).IsFalse(); + Check.That(result.Result).IsEqualTo("Ba(b, b, b, a)"); + result = Parser.Parse("a","Ba"); + Check.That(result.IsError).IsFalse(); + Check.That(result.Result).IsEqualTo("Ba(a)"); + } + + [Fact] + public void TestZeroOrMoreStarterFollowedByNonTerminal() + { + var buildResult = BuildParser(); + Check.That(buildResult.IsError).IsFalse(); + Parser = buildResult.Result; + var result = Parser.Parse("bbb a","BA"); + Check.That(result.IsError).IsFalse(); + Check.That(result.Result).IsEqualTo("BA(b, b, b, A(a))"); + result = Parser.Parse("a","BA"); + Check.That(result.IsError).IsFalse(); + Check.That(result.Result).IsEqualTo("BA(A(a))"); + } [Fact] public void TestZeroOrMoreWithNone()