Search in sources :

Example 11 with DataTable

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

the class TableLoaderTest method testIndependence.

@Test
public void testIndependence() {
    try {
        loader.loadLstString(context, uri, "STARTTABLE:A\n\n,,,\n" + "Name,Value,\n\n,,,\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "This,1\n\n" + "\"That\",\"2\"\n" + "ENDTABLE:A\n" + "#What comments?\n,,,\n" + "STARTTABLE:B\n\n,,,\n" + "Name,Value,\n\n,,,\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "\"The \"\"Other\"\"\",\"3\"\n,,,\n\n" + "ENDTABLE:B\n");
        DataTable a = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "A");
        DataTable b = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "B");
        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\"", b.get("Name", 0));
        assertEquals(1, a.get("Value", 0));
        assertEquals(2, a.get("Value", 1));
        assertEquals(3, b.get("Value", 0));
    } 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 12 with DataTable

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

the class TableLoaderTest method testDuplicateIndependence.

@Test
public void testDuplicateIndependence() {
    try {
        loader.loadLstString(context, uri, "STARTTABLE:A\n\n,,,\n" + "Name,Value,\n\n,,,\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "This,1\n\n" + "\"That\",\"2\"\n" + "ENDTABLE:A\n" + "#What comments?\n,,,\n" + "STARTTABLE:A\n\n,,,\n" + "Name,Value,\n\n,,,\n" + "STRING,NUMBER,,\n\n,,,\n\n" + "\"The \"\"Other\"\"\",\"3\"\n,,,\n\n" + "ENDTABLE:A\n");
        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(1, a.get("Value", 0));
        assertEquals(2, a.get("Value", 1));
        context.getReferenceContext().forget(a);
        DataTable b = context.getReferenceContext().silentlyGetConstructedCDOMObject(DataTable.class, "A");
        assertEquals("The \"Other\"", b.get("Name", 0));
        assertEquals(3, b.get("Value", 0));
    } 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 13 with DataTable

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

the class LookupFunctionTest method testInvalidBadSemantics2.

@Test
public void testInvalidBadSemantics2() {
    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,badf(),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