f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/java/io/protobase/f7/testutils/TestWithTSVExecution.java
-rw-r--r--
1755
 1package io.protobase.f7.testutils;
 2
 3import com.google.common.io.Resources;
 4import io.protobase.f7.models.ColumnRowKey;
 5import io.protobase.f7.spreadsheet.SpreadsheetExecutor;
 6import org.apache.commons.csv.CSVFormat;
 7import org.apache.commons.csv.CSVRecord;
 8
 9import java.io.FileReader;
10import java.io.IOException;
11import java.io.Reader;
12import java.util.HashMap;
13import java.util.Map;
14import java.util.Objects;
15
16import static com.google.common.truth.Truth.assertThat;
17
18public class TestWithTSVExecution {
19  private static final CSVFormat FORMAT = CSVFormat.TDF.withNullString("");
20
21  private static Map<ColumnRowKey, String> loadGrid(String file) throws IOException {
22    Reader in = new FileReader(Resources.getResource(file).getFile());
23    Iterable<CSVRecord> records = FORMAT.parse(in);
24    Map<ColumnRowKey, String> grid = new HashMap<>();
25    for (CSVRecord record : records) {
26      int row = new Long(record.getRecordNumber()).intValue() - 1;
27      int column = 0;
28      for (String value : record) {
29        if (Objects.nonNull(value)) {
30          grid.put(new ColumnRowKey(column, row), value);
31        }
32        column++;
33      }
34    }
35    return grid;
36  }
37
38  protected static void runTest(String testName) throws IOException {
39    Map<ColumnRowKey, String> values = loadGrid("sheets/" + testName + "_in.tsv");
40    SpreadsheetExecutor executor = SpreadsheetExecutor.builder()
41        .addGrid("Main", values)
42        .build();
43    executor.execute();
44    Map<ColumnRowKey, String> expected = loadGrid("sheets/" + testName + "_out.tsv");
45    for (Map.Entry<ColumnRowKey, String> entry : expected.entrySet()) {
46      assertThat(executor.getCell("Main", entry.getKey()).get().getComputedValue().toString()).isEqualTo(entry.getValue());
47    }
48  }
49}