use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.
the class TestFormulaParserIf method testYN.
public void testYN() {
Ptg[] ptgs = parseFormula("IF(TRUE,\"Y\",\"N\")");
assertEquals(7, ptgs.length);
BoolPtg flag = (BoolPtg) ptgs[0];
AttrPtg funif = (AttrPtg) ptgs[1];
StringPtg y = (StringPtg) ptgs[2];
AttrPtg goto1 = (AttrPtg) ptgs[3];
StringPtg n = (StringPtg) ptgs[4];
assertEquals(true, flag.getValue());
assertEquals("Y", y.getValue());
assertEquals("N", n.getValue());
assertEquals("IF", funif.toFormulaString());
assertTrue("tAttrSkip ptg exists", goto1.isSkip());
}
use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.
the class TestFormulaParser method testParseStringLiterals_bug28754.
@Test
public void testParseStringLiterals_bug28754() throws IOException {
StringPtg sp;
try {
sp = (StringPtg) parseSingleToken("\"test\"\"ing\"", StringPtg.class);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Cannot Parse")) {
fail("Identified bug 28754a");
}
throw e;
}
assertEquals("test\"ing", sp.getValue());
HSSFWorkbook wb = new HSSFWorkbook();
try {
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("right(\"test\"\"ing\", 3)");
String actualCellFormula = cell.getCellFormula();
if ("RIGHT(\"test\"ing\",3)".equals(actualCellFormula)) {
fail("Identified bug 28754b");
}
assertEquals("RIGHT(\"test\"\"ing\",3)", actualCellFormula);
} finally {
wb.close();
}
}
use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.
the class TestFormulaParser method testLeadingSpaceInString.
@Test
public void testLeadingSpaceInString() {
String value = " hi ";
Ptg[] ptgs = parseFormula("\"" + value + "\"");
confirmTokenClasses(ptgs, StringPtg.class);
assertTrue("ptg0 contains exact value", ((StringPtg) ptgs[0]).getValue().equals(value));
}
Aggregations