use of pcgen.base.formula.parse.SimpleNode 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.base.formula.parse.SimpleNode 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.base.formula.parse.SimpleNode in project pcgen by PCGen.
the class LookupFunctionTest method testInvalidWrongArg.
@Test
public void testInvalidWrongArg() {
String formula = "lookup(2)";
SimpleNode node = TestUtilities.doParse(formula);
isNotValid(formula, node, numberManager, null);
formula = "lookup(2, 3, 4, 5)";
node = TestUtilities.doParse(formula);
isNotValid(formula, node, numberManager, null);
}
use of pcgen.base.formula.parse.SimpleNode in project pcgen by PCGen.
the class InputFunctionTest method testInvalidNotString.
@Test
public void testInvalidNotString() {
String formula = "input(2)";
SimpleNode node = TestUtilities.doParse(formula);
isNotValid(formula, node, numberManager, null);
}
use of pcgen.base.formula.parse.SimpleNode in project pcgen by PCGen.
the class LookupFunctionTest method testInvalidBadSemantics1.
@Test
public void testInvalidBadSemantics1() {
Finder finder = new Finder();
finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
finder.map.put(TableColumn.class, "Result", buildColumn("Result", stringManager));
VariableLibrary vl = getVariableLibrary();
WriteableVariableStore vs = getVariableStore();
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(badf(),\"That\",ResultColumn)";
SimpleNode node = TestUtilities.doParse(formula);
isNotValid(formula, node, numberManager, null);
}
Aggregations