use of org.apache.poi.ss.formula.ptg.IntPtg in project poi by apache.
the class TestFormulaParserIf method testIfSingleCondition.
public void testIfSingleCondition() {
Ptg[] ptgs = parseFormula("IF(1=1,10)");
assertEquals(7, ptgs.length);
assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
AttrPtg ifFunc = (AttrPtg) ptgs[3];
assertTrue("It is not an if", ifFunc.isOptimizedIf());
assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
IntPtg intPtg = (IntPtg) ptgs[4];
assertEquals("Result", (short) 10, intPtg.getValue());
assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
FuncVarPtg funcPtg = (FuncVarPtg) ptgs[6];
assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
}
use of org.apache.poi.ss.formula.ptg.IntPtg in project poi by apache.
the class TestFormulaParser method testSpaceAtStartOfFormula.
@Test
public void testSpaceAtStartOfFormula() {
// Simulating cell formula of "= 4" (note space)
// The same Ptg array can be observed if an excel file is saved with that exact formula
AttrPtg spacePtg = AttrPtg.createSpace(AttrPtg.SpaceType.SPACE_BEFORE, 1);
Ptg[] ptgs = { spacePtg, new IntPtg(4) };
String formulaString;
try {
formulaString = toFormulaString(ptgs);
} catch (IllegalStateException e) {
if (e.getMessage().equalsIgnoreCase("too much stuff left on the stack")) {
fail("Identified bug 44609");
}
// else some unexpected error
throw e;
}
// FormulaParser strips spaces anyway
assertEquals("4", formulaString);
ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, AddPtg.instance };
formulaString = toFormulaString(ptgs);
assertEquals("3+4", formulaString);
}
Aggregations