Search in sources :

Example 21 with DataTableRow

use of gherkin.formatter.model.DataTableRow in project allure-cucumberjvm by allure-framework.

the class AllureReporter method createDataTableAttachment.

private void createDataTableAttachment(final List<DataTableRow> dataTableRows) {
    if (dataTableRows != null && !dataTableRows.isEmpty()) {
        final StringBuilder dataTableCsv = new StringBuilder();
        for (DataTableRow row : dataTableRows) {
            dataTableCsv.append(StringUtils.join(row.getCells().toArray(), "\t"));
            dataTableCsv.append('\n');
        }
        ALLURE_LIFECYCLE.fire(new MakeAttachmentEvent(dataTableCsv.toString().getBytes(), "Data table", "text/tab-separated-values"));
    }
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow)

Example 22 with DataTableRow

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

the class TableDiffer method calculateUnorderedDiffs.

public void calculateUnorderedDiffs() throws TableDiffException {
    boolean isDifferent = false;
    List<DataTableRow> diffTableRows = new ArrayList<DataTableRow>();
    List<List<String>> missingRow = new ArrayList<List<String>>();
    ArrayList<List<String>> extraRows = new ArrayList<List<String>>();
    // 1. add all "to" row in extra table
    // 2. iterate over "from", when a common row occurs, remove it from extraRows
    // finally, only extra rows are kept and in same order that in "to".
    extraRows.addAll(to.raw());
    int i = 1;
    for (DataTableRow r : from.getGherkinRows()) {
        if (!to.raw().contains(r.getCells())) {
            missingRow.add(r.getCells());
            diffTableRows.add(new DataTableRow(r.getComments(), r.getCells(), i, Row.DiffType.DELETE));
            isDifferent = true;
        } else {
            diffTableRows.add(new DataTableRow(r.getComments(), r.getCells(), i++));
            extraRows.remove(r.getCells());
        }
    }
    for (List<String> e : extraRows) {
        diffTableRows.add(new DataTableRow(Collections.EMPTY_LIST, e, i++, Row.DiffType.INSERT));
        isDifferent = true;
    }
    if (isDifferent) {
        throw new TableDiffException(from, to, new DataTable(diffTableRows, from.getTableConverter()));
    }
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 23 with DataTableRow

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

the class CucumberScenarioOutline method rowsWithTokensReplaced.

private static List<DataTableRow> rowsWithTokensReplaced(List<DataTableRow> rows, List<String> headerCells, List<String> exampleCells, Set<Integer> matchedColumns) {
    if (rows != null) {
        List<DataTableRow> newRows = new ArrayList<DataTableRow>(rows.size());
        for (Row row : rows) {
            List<String> newCells = new ArrayList<String>(row.getCells().size());
            for (String cell : row.getCells()) {
                newCells.add(replaceTokens(matchedColumns, headerCells, exampleCells, cell));
            }
            newRows.add(new DataTableRow(row.getComments(), newCells, row.getLine()));
        }
        return newRows;
    } else {
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) Row(gherkin.formatter.model.Row) ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) DataTableRow(gherkin.formatter.model.DataTableRow) DocString(gherkin.formatter.model.DocString) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 24 with DataTableRow

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

the class JythonSnippetTest method generatesSnippetWithDataTable.

@Test
public void generatesSnippetWithDataTable() {
    String expected = "" + "@Given('^I have:$')\n" + "def i_have(self, arg1):\n" + "  # Write code here that turns the phrase above into concrete actions\n" + "  # The last argument is a List of List of String\n" + "  raise(PendingException())\n" + "";
    List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
    assertEquals(expected, snippetForDataTable("I have:", dataTable));
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 25 with DataTableRow

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

the class FromDataTableTest method listOfDatesWithHeader.

private List<DataTableRow> listOfDatesWithHeader() {
    List<DataTableRow> rows = new ArrayList<DataTableRow>();
    rows.add(new DataTableRow(NO_COMMENTS, asList("Birth Date"), 1));
    rows.add(new DataTableRow(NO_COMMENTS, asList("1957-05-10"), 2));
    return rows;
}
Also used : ArrayList(java.util.ArrayList) DataTableRow(gherkin.formatter.model.DataTableRow)

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