cucumber-attic / gherkin2

A fast Gherkin parser in Ragel (The parser behind Cucumber)
MIT License
382 stars 221 forks source link

PrettyFormatter can lead to Array Bound exceptions because indentation list is empty #259

Closed rmannibucau closed 11 years ago

aslakhellesoy commented 11 years ago

Looks like a dupe of #252. I'll reopen if you think it's not (and if the CI build passes)

rmannibucau commented 11 years ago

It is, just wanted to send a PR for it.

Well, not sure what i did but it seems my PR was wrong (it needs a single line so i'll not redo it excepted if you ask for it), the right fix is to call calculateLocationIndentations(); in match() method like in https://github.com/rmannibucau/gherkin/commit/cde0a4b2955cbd65ca69e69534c8236fa0c8ae29

rmannibucau commented 11 years ago

PS:

the following test (done in cucumber-core) will valid it:

    @Test
    public void without_background() throws IOException {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
        Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
        CucumberFeature feature = feature("test.feature", "" +
                "Feature:\n\n" +
                "  Scenario:\n\n" +
                "    Given s\n" +
                "    When s\n" +
                "    Then s\n");

        StringBuilder out = new StringBuilder();
        PrettyFormatter pretty = new PrettyFormatter(out, true, true);
        feature.run(pretty, pretty, runtime);
        String expectedOutput = "" +
                "Feature: \n" +
                "\n" +
                "  Scenario:  # test.feature:3\n" +
                "    Given s\n" +
                "    When s\n" +
                "    Then s\n";
        assertEquals(expectedOutput, out.toString());
    }