Skip to content

Commit

Permalink
issue #527 unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jan 17, 2025
1 parent 0cbdad2 commit 7a7fa4c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/ParserTests/Issue527/Issue527Lexer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using sly.lexer;

namespace ParserTests.Issue527;

public enum Issue527Lexer
{
[Keyword("a")]
A = 1,

[Keyword("b")]
B = 2,

}
32 changes: 32 additions & 0 deletions tests/ParserTests/Issue527/Issue527Test.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
using NFluent;
using sly.parser;
using sly.parser.generator;
using Xunit;

namespace ParserTests.Issue527;

public class Issue527Test
{

private Parser<Issue527Lexer, string> BuildParser()
{
var builder = new ParserBuilder<Issue527Lexer, string>("en");
var result = builder.BuildParser(new Issue527Parser(), ParserType.EBNF_LL_RECURSIVE_DESCENT,"root");
Check.That(result).IsOk();
return result.Result;
}

[Fact]
public void Issue527Test_OK_with_ParseWithoutContext()
{
var parser = BuildParser();
var result = parser.Parse("a a b");
Check.That(result).IsOkParsing();
Check.That(result.Result).IsEqualTo("any(a,a) and boo(b)");
}

[Fact]
public void Issue527Test_KO_with_ParseWithContext()
{
var parser = BuildParser();
var lexed = parser.Lexer.Tokenize("a a b");
Check.That(lexed).IsOkLexing();
var result = parser.ParseWithContext(lexed.Tokens.MainTokens());
Check.That(result).IsOkParsing();
Check.That(result.Result).IsEqualTo("any(a,a) and boo(b)");
}
}

0 comments on commit 7a7fa4c

Please sign in to comment.