From 6cae0e5eb9cba6936251f6636073dd4179614c67 Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Thu, 2 May 2002 12:52:13 +0000 Subject: [PATCH] adding test for formula parser git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352583 13f79535-47bb-0310-9956-ffa450edef68 --- .../record/formula/TestFormulaParser.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/testcases/org/apache/poi/hssf/record/formula/TestFormulaParser.java diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/record/formula/TestFormulaParser.java new file mode 100644 index 0000000000..112ee9f4ba --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestFormulaParser.java @@ -0,0 +1,64 @@ +package org.apache.poi.hssf.record.formula; + +import junit.framework.TestCase; + +/** + * Test the low level formula parser functionality. High level tests are to + * be done via usermodel/HSSFCell.setFormulaValue() . + */ +public class TestFormulaParser extends TestCase { + + public TestFormulaParser(String name) { + super(name); + } + public void setUp(){ + + } + + public void tearDown() { + + } + + public void testSimpleFormula() { + FormulaParser fp = new FormulaParser("2+2;"); + fp.parse(); + Ptg[] ptgs = fp.getRPNPtg(); + assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); + } + public void testFormulaWithSpace1() { + FormulaParser fp = new FormulaParser(" 2 + 2 ;"); + fp.parse(); + Ptg[] ptgs = fp.getRPNPtg(); + assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3); + assertTrue("",(ptgs[0] instanceof IntPtg)); + assertTrue("",(ptgs[1] instanceof IntPtg)); + assertTrue("",(ptgs[2] instanceof AddPtg)); + + } + + public void testFormulaWithSpace2() { + Ptg[] ptgs; + FormulaParser fp; + fp = new FormulaParser("2+ sum( 3 , 4) ;"); + fp.parse(); + ptgs = fp.getRPNPtg(); + assertTrue("five tokens expected, got "+ptgs.length,ptgs.length == 5); + } + + public void testFormulaWithSpaceNRef() { + Ptg[] ptgs; + FormulaParser fp; + fp = new FormulaParser("sum( A2:A3 );"); + fp.parse(); + ptgs = fp.getRPNPtg(); + assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2); + } + + public static void main(String [] args) { + System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser"); + junit.textui.TestRunner.run(TestFormulaParser.class); + } +} + + +