Skip to content

Commit

Permalink
unit tests (after stryker analysis)
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Dec 13, 2024
1 parent bced830 commit 868473b
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion tests/ParserTests/EBNFTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,36 @@ public string B(List<Token<TokenType>> bstr)

return "B()";
}

[Production("Ba : b* a")]
public string Ba(List<Token<TokenType>> bstr, Token<TokenType> 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<Token<TokenType>> 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;
}



Expand Down Expand Up @@ -1060,7 +1090,7 @@ public void TestParseBuild()
Check.That(buildResult.IsError).IsFalse();
Parser = buildResult.Result;
Check.That(Parser.SyntaxParser).IsInstanceOf<EBNFRecursiveDescentSyntaxParser<TokenType, string>>();
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);
Expand All @@ -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()
Expand Down

0 comments on commit 868473b

Please sign in to comment.