Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Concatenate work with negative page number parsers #4

Open
canro91 opened this issue Jul 20, 2021 · 0 comments
Open

Make Concatenate work with negative page number parsers #4

canro91 opened this issue Jul 20, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@canro91
Copy link
Owner

canro91 commented Jul 20, 2021

Now, Concatenates only works if given parsers are in the same page or have positive page numbers.

Instead of using a property for PageNumber, create a method to pass the current page and the relative page Parsinator is currently trying to parse. Maybe introduce a method in the base class?

[Test]
public void Parse_ConcatenateTwoPagedParsersANegativeAndPositivePageNumber_ParsersValueFromBothParsersInGivenPages()
{
    var p = new Dictionary<String, IList<IParse>>
    {
        {
            "Key",
            new List<IParse>
            {
                new Concatenate(key: "Value", separator: "|", new List<IParse>
                {
                    new ParseFromRegex(key: "Result", pageNumber: -1, pattern: new Regex(@"Result:\s*(\w+)")),
                    new ParseFromRegex(key: "Value", pageNumber: 2, pattern: new Regex(@"Value:\s*(\d+)"))
                })
            }
        }
    };

    var lines = FromPagesText(
@"Page1 This is a dummy page    Page-3",
@"Page2 Value: 123456           Page-2",
@"Page3 Result: Foo             Page-1");

    var parser = new Parser(p);
    var ds = parser.Parse(lines);

    Assert.AreEqual("Foo|123456", ds["Key"]["Value"]);
}
@canro91 canro91 added the enhancement New feature or request label Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant