Skip to content

Commit

Permalink
Fix SkipAnd compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed May 2, 2021
1 parent 53a2ddf commit 0747ece
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Parlot/Fluent/SequenceSkipAnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CompilationResult Compile(CompilationContext context)
var result = new CompilationResult();

var success = context.DeclareSuccessVariable(result, false);
var value = context.DeclareValueVariable(result, Expression.Default(typeof(T1)));
var value = context.DeclareValueVariable(result, Expression.Default(typeof(T2)));

// T value;
//
Expand Down
18 changes: 4 additions & 14 deletions test/Parlot.Tests/CompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,29 +305,19 @@ public void ShouldCompileOneOfABT()
[Fact]
public void ShouldCompileAndSkip()
{
var code =
OneOf(
Terms.Text("hello").AndSkip(Terms.Text("world")),
Terms.Text("hello").AndSkip(Terms.Text("universe"))
).Compile();
var code = Terms.Text("hello").AndSkip(Terms.Integer()).Compile();

Assert.False(code.TryParse("hello country", out var result));
Assert.True(code.TryParse("hello universe", out result) && result == "hello");
Assert.True(code.TryParse("hello world", out result) && result == "hello");
Assert.True(code.TryParse("hello 1", out result) && result == "hello");
}

[Fact]
public void ShouldCompileSkipAnd()
{
var code =
OneOf(
Terms.Text("hello").SkipAnd(Terms.Text("world")),
Terms.Text("hello").SkipAnd(Terms.Text("universe"))
).Compile();
var code = Terms.Text("hello").SkipAnd(Terms.Integer()).Compile();

Assert.False(code.TryParse("hello country", out var result));
Assert.True(code.TryParse("hello universe", out result) && result == "universe");
Assert.True(code.TryParse("hello world", out result) && result == "world");
Assert.True(code.TryParse("hello 1", out result) && result == 1);
}

[Fact]
Expand Down

0 comments on commit 0747ece

Please sign in to comment.