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

Unable to use CaseDescription when param contains reserved regexp character #177

Closed
nikowitt opened this issue Dec 22, 2015 · 3 comments
Closed
Assignees
Milestone

Comments

@nikowitt
Copy link
Contributor

Hi Jan,

    @Test
    @DataProvider(splitBy = __, value = {
            "Test/Project # Name " + __ + "Test Project Name",
            "\r\nTest/  %Project% # Name *" + __ + "Test Project Name",
            "Test Project Name in C$ash" + __ + "Test Project Name"
    })
    @CaseDescription("Input '$0'")
    public void strip_invalid_imap_folder_name_characters(String input, String output) throws Exception {
        assert_that().assert_expression(JAFStringUtils.stripInvalidIMAPFolderNameCharacters(input), is(output),
                "via 'stripInvalidIMAPFolderNameCharacters(String name)'");
    }

returns an error:

java.lang.IllegalArgumentException: Illegal group reference
    at java.util.regex.Matcher.appendReplacement(Unknown Source)
    at com.tngtech.jgiven.impl.params.DefaultCaseDescriptionProvider.description(DefaultCaseDescriptionProvider.java:42)
    at com.tngtech.jgiven.impl.ScenarioModelBuilder.setCaseDescription(ScenarioModelBuilder.java:306)
    at com.tngtech.jgiven.impl.ScenarioModelBuilder.scenarioStarted(ScenarioModelBuilder.java:292)
    at com.tngtech.jgiven.impl.StandaloneScenarioExecutor.startScenario(StandaloneScenarioExecutor.java:440)
    at com.tngtech.jgiven.impl.ScenarioBase.startScenario(ScenarioBase.java:75)
    at com.tngtech.jgiven.junit.ScenarioExecutionRule.starting(ScenarioExecutionRule.java:110)
    at com.tngtech.jgiven.junit.ScenarioExecutionRule$1.evaluate(ScenarioExecutionRule.java:72)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

So an additional escape for params is required.

@janschaefer
Copy link
Contributor

Ah, this is a classic. I fall into this trap already. I forgot to call quoteReplacement on the argument.

@janschaefer janschaefer added this to the v0.10.2 milestone Dec 22, 2015
@janschaefer janschaefer self-assigned this Dec 22, 2015
@nikowitt
Copy link
Contributor Author

Hehe, so did I :)

@janschaefer
Copy link
Contributor

This is an ideal use case to try out property based testing :-)

@janschaefer janschaefer modified the milestones: v0.11.0, v0.10.2 Dec 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants