Search in sources :

Example 6 with DataTable

use of pcgen.cdom.format.table.DataTable in project pcgen by PCGen.

the class TableLoaderTest method testBasic.

//TODO Blank Data in middle of Row?
//TODO Blank Data at end of row?
@Test
public void testBasic() {
    try {
        loader.loadLstString(context, uri, "#Let me tell you about this table\n\n,,,\n" + "STARTTABLE:A\n\n,,,\n" + "#It's the story of a parsing test\n" + "Name,Value,\n\n,,,\n" + "\"#And testing tolerance\",For lots of things\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "#Because really....\n" + "This,1\n\n" + "#Why call the comments?\n,,,\n" + "\"That\",\"2\"\n" + "\"The \"\"Other\"\"\",\"3\"\n,,,\n\n" + "ENDTABLE:A\n" + "#They seem to just take up a lot of space");
        DataTable a = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "A");
        assertEquals(2, a.getColumnCount());
        assertEquals(new StringManager(), a.getFormat(0));
        assertEquals(new NumberManager(), a.getFormat(1));
        assertEquals("This", a.get("Name", 0));
        assertEquals("That", a.get("Name", 1));
        assertEquals("The \"Other\"", a.get("Name", 2));
        assertEquals(1, a.get("Value", 0));
        assertEquals(2, a.get("Value", 1));
        assertEquals(3, a.get("Value", 2));
        assertEquals(2, a.lookupExact("That", "Value"));
    } catch (PersistenceLayerException e) {
        fail("Did not Expect Failure: " + e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) DataTable(pcgen.cdom.format.table.DataTable) NumberManager(pcgen.base.format.NumberManager) StringManager(pcgen.base.format.StringManager) Test(org.junit.Test)

Example 7 with DataTable

use of pcgen.cdom.format.table.DataTable in project pcgen by PCGen.

the class LookupFunctionTest method testNoColumn.

@Test
public void testNoColumn() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Name", buildColumn("Name", stringManager));
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Result", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    ColumnFormatFactory cfac = new ColumnFormatFactory(finder);
    FormatManager<?> columnMgr = cfac.build("NUMBER", formatLibrary);
    vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    VariableID columnID = vl.getVariableID(getGlobalScopeInst(), "ResultColumn");
    vs.put(columnID, columnMgr.convert("Result"));
    String formula = "lookup(TableA,\"That\",ResultColumn)";
    SimpleNode node = TestUtilities.doParse(formula);
    isValid(formula, node, numberManager, null);
    isStatic(formula, node, false);
    EvaluationManager manager = generateManager();
    Object result = new EvaluateVisitor().visit(node, manager);
    if (result instanceof Number) {
        TestCase.fail("Expected Invalid result, should have been a string due to invalid column: " + result);
    }
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) EvaluateVisitor(pcgen.base.formula.visitor.EvaluateVisitor) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) ColumnFormatFactory(pcgen.cdom.format.table.ColumnFormatFactory) EvaluationManager(pcgen.base.formula.base.EvaluationManager) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) VariableID(pcgen.base.formula.base.VariableID) Test(org.junit.Test)

Example 8 with DataTable

use of pcgen.cdom.format.table.DataTable in project pcgen by PCGen.

the class LookupFunctionTest method doTableSetup.

public DataTable doTableSetup() {
    DataTable dt = new DataTable();
    dt.setName("A");
    TableColumn c1 = new TableColumn();
    c1.setName("Name");
    c1.setFormatManager(stringManager);
    TableColumn c2 = new TableColumn();
    c2.setName("Value");
    c2.setFormatManager(numberManager);
    dt.addColumn(c1);
    dt.addColumn(c2);
    List<Object> row = new ArrayList<>();
    row.add("This");
    row.add(1);
    dt.addRow(row);
    row.clear();
    row.add("That");
    row.add(2);
    dt.addRow(row);
    row.clear();
    row.add("The \"Other\"");
    row.add(3);
    dt.addRow(row);
    row.clear();
    return dt;
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) ArrayList(java.util.ArrayList) TableColumn(pcgen.cdom.format.table.TableColumn)

Example 9 with DataTable

use of pcgen.cdom.format.table.DataTable in project pcgen by PCGen.

the class LookupFunctionTest method testInvalidBadSemantics3.

@Test
public void testInvalidBadSemantics3() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Value", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    String formula = "lookup(TableA,\"That\",badf())";
    SimpleNode node = TestUtilities.doParse(formula);
    isNotValid(formula, node, numberManager, null);
}
Also used : TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) DataTable(pcgen.cdom.format.table.DataTable) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) VariableID(pcgen.base.formula.base.VariableID) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) Test(org.junit.Test)

Example 10 with DataTable

use of pcgen.cdom.format.table.DataTable in project pcgen by PCGen.

the class LookupFunctionTest method testInvalidWrongFormat2.

@Test
public void testInvalidWrongFormat2() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Result", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    ColumnFormatFactory cfac = new ColumnFormatFactory(finder);
    FormatManager<?> columnMgr = cfac.build("STRING", formatLibrary);
    vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr);
    VariableID columnID = vl.getVariableID(getGlobalScopeInst(), "ResultColumn");
    vs.put(columnID, columnMgr.convert("Value"));
    String formula = "lookup(TableA,3,ResultColumn)";
    SimpleNode node = TestUtilities.doParse(formula);
    isNotValid(formula, node, numberManager, null);
}
Also used : TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) DataTable(pcgen.cdom.format.table.DataTable) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) VariableID(pcgen.base.formula.base.VariableID) ColumnFormatFactory(pcgen.cdom.format.table.ColumnFormatFactory) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) Test(org.junit.Test)

Aggregations

DataTable (pcgen.cdom.format.table.DataTable)13 Test (org.junit.Test)11 VariableID (pcgen.base.formula.base.VariableID)8 VariableLibrary (pcgen.base.formula.base.VariableLibrary)8 WriteableVariableStore (pcgen.base.formula.base.WriteableVariableStore)8 SimpleNode (pcgen.base.formula.parse.SimpleNode)8 TableFormatFactory (pcgen.cdom.format.table.TableFormatFactory)8 ColumnFormatFactory (pcgen.cdom.format.table.ColumnFormatFactory)6 NumberManager (pcgen.base.format.NumberManager)3 StringManager (pcgen.base.format.StringManager)3 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)3 EvaluationManager (pcgen.base.formula.base.EvaluationManager)2 EvaluateVisitor (pcgen.base.formula.visitor.EvaluateVisitor)2 TableColumn (pcgen.cdom.format.table.TableColumn)2 ArrayList (java.util.ArrayList)1 FormulaManager (pcgen.base.formula.base.FormulaManager)1 FormulaSemantics (pcgen.base.formula.base.FormulaSemantics)1 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)1 SemanticsVisitor (pcgen.base.formula.visitor.SemanticsVisitor)1