datalust / superpower

A C# parser construction toolkit with high-quality error reporting
Apache License 2.0
1.05k stars 98 forks source link

Added optional error message to the Where combinator #131

Closed AndrewSav closed 3 years ago

AndrewSav commented 3 years ago

Resolves https://github.com/datalust/superpower/issues/117

nblumhardt commented 3 years ago

Would it be possible to tack a test on with this one?

AndrewSav commented 3 years ago

@nblumhardt the current Where does not have a test. IMO, the change is trivial enough, so if the method did not have the test before the change itself does not warrant it now. What do you think?

nblumhardt commented 3 years ago

Thanks for the reply!

Originally, this codebase evolved pretty quickly, and test coverage is lower than it should be. I'm trying to bump it up a little with each change :-)

How about:

    public class WhereCombinatorTests
    {
        [Fact]
        public void WhereFailsIfPrecedingParserFails()
        {
            AssertParser.Fails(Character.EqualTo('a').Where(_ => true), "b");
        }

        [Fact]
        public void WhereSucceedsWhenPredicateMatches()
        {
            AssertParser.SucceedsWith(Character.EqualTo('a').Where(a => a == 'a'), "a", 'a');
        }

        [Fact]
        public void WhereFailsWhenPredicateDoesNotMatch()
        {
            AssertParser.FailsWithMessage(
                Character.EqualTo('a').Where(a => a != 'a', "character should be an A"), 
                "a",
                "Syntax error (line 1, column 1): character should be an A");
        }
    }
AndrewSav commented 3 years ago

@nblumhardt thank you for this, I have added it.

nblumhardt commented 3 years ago

Great, thanks 👍