Search in sources :

Example 1 with Delta

use of cucumber.deps.difflib.Delta 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 Delta

use of cucumber.deps.difflib.Delta in project cucumber-jvm by cucumber.

the class TableDiffer method calculateDiffs.

public void calculateDiffs() throws TableDiffException {
    Patch patch = DiffUtils.diff(from.diffableRows(), to.diffableRows());
    List<Delta> deltas = patch.getDeltas();
    if (!deltas.isEmpty()) {
        Map<Integer, Delta> deltasByLine = createDeltasByLine(deltas);
        throw new TableDiffException(from, to, createTableDiff(deltasByLine));
    }
}
Also used : Delta(cucumber.deps.difflib.Delta) Patch(cucumber.deps.difflib.Patch)

Aggregations

Delta (cucumber.deps.difflib.Delta)2 DataTable (cucumber.api.DataTable)1 Patch (cucumber.deps.difflib.Patch)1 DataTableRow (gherkin.formatter.model.DataTableRow)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1