Search in sources :

Example 1 with TableColumn

use of org.apache.sis.util.collection.TableColumn in project sis by apache.

the class TreeTableFormatTest method testTreeTableParse.

/**
 * Tests the parsing of a tree table. This method parses and reformats a tree table,
 * and performs its check on the assumption that the tree table formatting is accurate.
 *
 * @throws ParseException if the parsing failed.
 */
@Test
@DependsOnMethod("testTreeTableFormat")
public void testTreeTableParse() throws ParseException {
    final TableColumn<Integer> valueA = new TableColumn<>(Integer.class, "value #1");
    final TableColumn<String> valueB = new TableColumn<>(String.class, "value #2");
    final TreeTableFormat tf = new TreeTableFormat(null, null);
    tf.setColumns(NAME, valueA, valueB);
    tf.setVerticalLinePosition(1);
    final String text = "Node #1………………………… 10…… Value #1B\n" + " ├──Node #2……………… 20\n" + " │   └──Node #4…… 40…… Value #4B\n" + " └──Node #3……………… ………… Value #3B\n";
    final TreeTable table = tf.parseObject(text);
    assertMultilinesEquals(text, tf.format(table));
}
Also used : DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) TableColumn(org.apache.sis.util.collection.TableColumn) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with TableColumn

use of org.apache.sis.util.collection.TableColumn in project sis by apache.

the class TreeTableFormatTest method testAlternativeColumnSeparatorPattern.

/**
 * Tests parsing and formatting using a different column separator.
 *
 * @throws ParseException if the parsing failed.
 */
@Test
@DependsOnMethod("testTreeTableParse")
public void testAlternativeColumnSeparatorPattern() throws ParseException {
    final TableColumn<Integer> valueA = new TableColumn<>(Integer.class, "value #1");
    final TableColumn<String> valueB = new TableColumn<>(String.class, "value #2");
    final TreeTableFormat tf = new TreeTableFormat(null, null);
    assertEquals("?……[…] ", tf.getColumnSeparatorPattern());
    tf.setColumns(NAME, valueA, valueB);
    tf.setVerticalLinePosition(1);
    /*
         * Test with all column separators.
         */
    tf.setColumnSeparatorPattern(" [ ]│ ");
    assertEquals(" [ ]│ ", tf.getColumnSeparatorPattern());
    final String text = "Node #1         │ 10 │ Value #1B\n" + " ├──Node #2     │ 20 │ \n" + " │   └──Node #4 │ 40 │ Value #4B\n" + " └──Node #3     │    │ Value #3B\n";
    final TreeTable table = tf.parseObject(text);
    assertMultilinesEquals(text, tf.format(table));
    /*
         * Test with omission of column separator for trailing null values.
         */
    tf.setColumnSeparatorPattern("? [ ]; ");
    assertMultilinesEquals("Node #1         ; 10 ; Value #1B\n" + // Column separator omitted here.
    " ├──Node #2     ; 20\n" + " │   └──Node #4 ; 40 ; Value #4B\n" + " └──Node #3     ;    ; Value #3B\n", tf.format(table));
    /*
         * Test with regular expression at parsing time.
         */
    tf.setColumnSeparatorPattern("?……[…] /\\w*│+\\w*");
    assertEquals("?……[…] /\\w*│+\\w*", tf.getColumnSeparatorPattern());
    assertEquals(table, tf.parseObject(text));
}
Also used : DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) TableColumn(org.apache.sis.util.collection.TableColumn) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 TableColumn (org.apache.sis.util.collection.TableColumn)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 Test (org.junit.Test)2