use of pcgen.base.formula.parse.SimpleNode 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);
}
use of pcgen.base.formula.parse.SimpleNode in project pcgen by PCGen.
the class LookupFunctionTest method testInvalidWrongFormat1.
@Test
public void testInvalidWrongFormat1() {
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(3,\"That\",ResultColumn)";
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 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);
}
use of pcgen.base.formula.parse.SimpleNode in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testInvalidWrongFormat3.
@Test
public void testInvalidWrongFormat3() {
String formula = "dropIntoContext(\"EQUIPMENT\", \"EquipKey\",\"Stuff\")";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
Object result = semanticsVisitor.visit(node, semantics);
if (semantics.isValid() && (result instanceof Number)) {
TestCase.fail("Expected Invalid Formula: " + formula + " but was valid");
}
}
Aggregations