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());
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations