From 425f468924b07844aeea197d39382349ca558dfa Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Thu, 1 Jan 2004 19:11:03 +0000 Subject: [PATCH] on head, missed the testcase for the formula parser changes git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353480 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/model/TestFormulaParser.java | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index ecce0635b..188ee52d8 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -55,7 +55,25 @@ package org.apache.poi.hssf.model; import junit.framework.TestCase; -import org.apache.poi.hssf.record.formula.*; +import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; +import org.apache.poi.hssf.record.formula.AddPtg; +import org.apache.poi.hssf.record.formula.AttrPtg; +import org.apache.poi.hssf.record.formula.BoolPtg; +import org.apache.poi.hssf.record.formula.EqualPtg; +import org.apache.poi.hssf.record.formula.FuncVarPtg; +import org.apache.poi.hssf.record.formula.IntPtg; +import org.apache.poi.hssf.record.formula.LessEqualPtg; +import org.apache.poi.hssf.record.formula.LessThanPtg; +import org.apache.poi.hssf.record.formula.NamePtg; +import org.apache.poi.hssf.record.formula.NotEqualPtg; +import org.apache.poi.hssf.record.formula.Ptg; +import org.apache.poi.hssf.record.formula.ReferencePtg; +import org.apache.poi.hssf.record.formula.StringPtg; +import org.apache.poi.hssf.record.formula.UnaryMinusPtg; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * Test the low level formula parser functionality. High level tests are to @@ -315,6 +333,63 @@ public class TestFormulaParser extends TestCase { assertTrue("second ptg is string",ptg[1] instanceof StringPtg); } + public void testWorksheetReferences() + { + HSSFWorkbook wb = new HSSFWorkbook(); + + wb.createSheet("NoQuotesNeeded"); + wb.createSheet("Quotes Needed Here &#$@"); + + HSSFSheet sheet = wb.createSheet("Test"); + HSSFRow row = sheet.createRow(0); + HSSFCell cell; + + cell = row.createCell((short)0); + cell.setCellFormula("NoQuotesNeeded!A1"); + + cell = row.createCell((short)1); + cell.setCellFormula("'Quotes Needed Here &#$@'!A1"); + } + + public void testUnaryMinus() + { + FormulaParser fp = new FormulaParser("-A1", null); + fp.parse(); + Ptg[] ptg = fp.getRPNPtg(); + assertTrue("got 2 ptgs", ptg.length == 2); + assertTrue("first ptg is reference",ptg[0] instanceof ReferencePtg); + assertTrue("second ptg is string",ptg[1] instanceof UnaryMinusPtg); + } + + public void testLeadingSpaceInString() + { + String value = " hi "; + FormulaParser fp = new FormulaParser("\"" + value + "\"", null); + fp.parse(); + Ptg[] ptg = fp.getRPNPtg(); + + assertTrue("got 1 ptg", ptg.length == 1); + assertTrue("ptg0 is a StringPtg", ptg[0] instanceof StringPtg); + assertTrue("ptg0 contains exact value", ((StringPtg)ptg[0]).getValue().equals(value)); + } + + public void testLookupAndMatchFunctionArgs() + { + FormulaParser fp = new FormulaParser("lookup(A1, A3:A52, B3:B52)", null); + fp.parse(); + Ptg[] ptg = fp.getRPNPtg(); + + assertTrue("got 4 ptg", ptg.length == 4); + assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE); + + fp = new FormulaParser("match(A1, A3:A52)", null); + fp.parse(); + ptg = fp.getRPNPtg(); + + assertTrue("got 3 ptg", ptg.length == 3); + assertTrue("ptg0 has Value class", ptg[0].getPtgClass() == Ptg.CLASS_VALUE); + } + public static void main(String [] args) { System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); junit.textui.TestRunner.run(TestFormulaParser.class);