use of pcgen.base.formula.visitor.SemanticsVisitor in project pcgen by PCGen.
the class LookupFunctionTest method testBadResultColumnFormat.
@Test
public void testBadResultColumnFormat() {
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("STRING", 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);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = getManagerFactory().generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
semanticsVisitor.visit(node, semantics);
if (semantics.isValid()) {
TestCase.fail("Expected Invalid Formula: " + formula);
}
}
use of pcgen.base.formula.visitor.SemanticsVisitor in project pcgen by PCGen.
the class AbstractFormulaTestCase method isValid.
public void isValid(String formula, SimpleNode node, FormatManager<?> formatManager, Class<?> assertedFormat) {
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(localSetup.getFormulaManager(), getGlobalScope(), assertedFormat);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
}
use of pcgen.base.formula.visitor.SemanticsVisitor in project pcgen by PCGen.
the class AbstractFormulaTestCase method isNotValid.
protected void isNotValid(String formula, SimpleNode node, FormatManager<?> formatManager, Class<?> assertedFormat) {
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(localSetup.getFormulaManager(), getGlobalScope(), assertedFormat);
semanticsVisitor.visit(node, semantics);
if (semantics.isValid()) {
TestCase.fail("Expected Invalid Formula: " + formula + " but was valid");
}
}
use of pcgen.base.formula.visitor.SemanticsVisitor in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testDynamic.
@Test
public void testDynamic() {
VariableLibrary vl = getVariableLibrary();
LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
LegalScope globalScope = getScopeLibrary().getScope("Global");
vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
vl.assertLegalVariableID("EquipVar", globalScope, stringManager);
String formula = "dropIntoContext(\"EQUIPMENT\",EquipVar,LocalVar)";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
isStatic(formula, node, false);
Equipment equip = new Equipment();
equip.setName("EquipKey");
Equipment equipalt = new Equipment();
equipalt.setName("EquipAlt");
ScopeInstance scopeInste = getInstanceFactory().get("EQUIPMENT", equip);
VariableID varIDe = vl.getVariableID(scopeInste, "LocalVar");
getVariableStore().put(varIDe, 2);
ScopeInstance scopeInsta = getInstanceFactory().get("EQUIPMENT", equipalt);
VariableID varIDa = vl.getVariableID(scopeInsta, "LocalVar");
getVariableStore().put(varIDa, 3);
ScopeInstance globalInst = getInstanceFactory().getGlobalInstance("Global");
VariableID varIDq = vl.getVariableID(globalInst, "EquipVar");
getVariableStore().put(varIDq, "EquipKey");
LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
context.getReferenceContext().importObject(equip);
context.getReferenceContext().importObject(equipalt);
evaluatesTo(formula, node, 2, context);
Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
assertEquals(rv.toString(), formula);
getVariableStore().put(varIDq, "EquipAlt");
evaluatesTo(formula, node, 3, context);
}
use of pcgen.base.formula.visitor.SemanticsVisitor in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testBasic.
@Test
public void testBasic() {
VariableLibrary vl = getVariableLibrary();
LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
String formula = "dropIntoContext(\"EQUIPMENT\",\"EquipKey\",LocalVar)";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
isStatic(formula, node, false);
Equipment equip = new Equipment();
equip.setName("EquipKey");
ScopeInstance scopeInst = getInstanceFactory().get("EQUIPMENT", equip);
VariableID varID = vl.getVariableID(scopeInst, "LocalVar");
getVariableStore().put(varID, 2);
LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
context.getReferenceContext().importObject(equip);
evaluatesTo(formula, node, 2, context);
Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
assertEquals(rv.toString(), formula);
}
Aggregations