Search in sources :

Example 1 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.

the class TableDiffer method createTableDiff.

private DataTable createTableDiff(Map<Integer, Delta> deltasByLine) {
    List<DataTableRow> diffTableRows = new ArrayList<DataTableRow>();
    List<List<String>> rows = from.raw();
    for (int i = 0; i < rows.size(); i++) {
        Delta delta = deltasByLine.get(i);
        if (delta == null) {
            diffTableRows.add(from.getGherkinRows().get(i));
        } else {
            addRowsToTableDiff(diffTableRows, delta);
            // skipping lines involved in a delta
            if (delta.getType() == Delta.TYPE.CHANGE || delta.getType() == Delta.TYPE.DELETE) {
                i += delta.getOriginal().getLines().size() - 1;
            } else {
                diffTableRows.add(from.getGherkinRows().get(i));
            }
        }
    }
    // Can have new lines at end
    Delta remainingDelta = deltasByLine.get(rows.size());
    if (remainingDelta != null) {
        addRowsToTableDiff(diffTableRows, remainingDelta);
    }
    return new DataTable(diffTableRows, from.getTableConverter());
}
Also used : DataTable(cucumber.api.DataTable) Delta(cucumber.deps.difflib.Delta) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 2 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.

the class ClojureSnippetTest method generatesSnippetWithDataTable.

@Test
public void generatesSnippetWithDataTable() throws Exception {
    List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
    Step step = new Step(NO_COMMENTS, "Given ", "I have:", 0, dataTable, null);
    String snippet = (newBackend()).getSnippet(step, null);
    String expected = "" + "(Given #\"^I have:$\" [arg1]\n" + "  (comment  Write code here that turns the phrase above into concrete actions  )\n" + "  (throw (cucumber.api.PendingException.)))\n";
    assertEquals(expected, snippet);
}
Also used : Step(gherkin.formatter.model.Step) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 3 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.

the class StepDefinitionMatch method createArgumentsForErrorMessage.

private List<Argument> createArgumentsForErrorMessage(Step step) {
    List<Argument> arguments = new ArrayList<Argument>(getArguments());
    if (step.getDocString() != null) {
        arguments.add(new Argument(-1, "DocString:" + step.getDocString().getValue()));
    }
    if (step.getRows() != null) {
        List<List<String>> rows = map(step.getRows(), new Mapper<DataTableRow, List<String>>() {

            @Override
            public List<String> map(DataTableRow row) {
                return row.getCells();
            }
        });
        arguments.add(new Argument(-1, "Table:" + rows.toString()));
    }
    return arguments;
}
Also used : Argument(gherkin.formatter.Argument) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 4 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.

the class CucumberScenarioOutlineTest method replaces_tokens_in_data_tables.

@Test
public void replaces_tokens_in_data_tables() {
    List<DataTableRow> rows = asList(new DataTableRow(C, asList("I", "have <n> cukes"), 1));
    Step outlineStep = new Step(C, null, "I have <n> cukes", 0, rows, null);
    Step exampleStep = CucumberScenarioOutline.createExampleStep(outlineStep, new ExamplesTableRow(C, asList("n"), 1, ""), new ExamplesTableRow(C, asList("10"), 1, ""));
    assertEquals(asList("I", "have 10 cukes"), exampleStep.getRows().get(0).getCells());
}
Also used : ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) Step(gherkin.formatter.model.Step) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 5 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.

the class GroovySnippetTest method generatesSnippetWithDataTable.

@Test
public void generatesSnippetWithDataTable() {
    String expected = "" + "Given(~/^I have:$/) { DataTable arg1 ->\n" + "    // Write code here that turns the phrase above into concrete actions\n" + "    throw new PendingException()\n" + "}\n";
    List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
    assertEquals(expected, snippetForDataTable("I have:", dataTable));
}
Also used : DocString(gherkin.formatter.model.DocString) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Aggregations

DataTableRow (gherkin.formatter.model.DataTableRow)46 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)9 List (java.util.List)6 And (cucumber.api.java.en.And)5 DataTable (cucumber.api.DataTable)4 DocString (gherkin.formatter.model.DocString)4 Step (gherkin.formatter.model.Step)4 Given (cucumber.api.java.en.Given)3 Then (cucumber.api.java.en.Then)3 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)3 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)3 Argument (gherkin.formatter.Argument)2 Arrays.asList (java.util.Arrays.asList)2 Map (java.util.Map)2 Pair (org.activityinfo.model.util.Pair)2 Usage (alien4cloud.model.common.Usage)1 Delta (cucumber.deps.difflib.Delta)1 I18n (gherkin.I18n)1 Row (gherkin.formatter.model.Row)1