diff options
author | Josh Micich <josh@apache.org> | 2009-12-25 23:26:47 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2009-12-25 23:26:47 +0000 |
commit | e39f7c367fc5d8f89422e9b100de7f91ba7b7782 (patch) | |
tree | 3937e47c083d0c2ea9dfe69c1651bfa711577785 /src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java | |
parent | e9d0f5aeb61fec5d9188b423f52a0de19fbe875d (diff) | |
download | poi-e39f7c367fc5d8f89422e9b100de7f91ba7b7782.tar.gz poi-e39f7c367fc5d8f89422e9b100de7f91ba7b7782.zip |
Fixed FormulaParser to allow negative elements in array literals.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893898 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index 5891831cba..2d2784c2da 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -871,6 +871,28 @@ public final class TestFormulaParser extends TestCase { confirmTokenClasses(ptgs2, ArrayPtg.class, IntPtg.class, FuncVarPtg.class); } + public void testParseArrayNegativeElement() { + Ptg[] ptgs; + try { + ptgs = parseFormula("{-42}"); + } catch (FormulaParseException e) { + if (e.getMessage().equals("Parse error near char 1 '-' in specified formula '{-42}'. Expected Integer")) { + throw new AssertionFailedError("Identified bug - failed to parse negative array element."); + } + throw e; + } + confirmTokenClasses(ptgs, ArrayPtg.class); + Object element = ((ArrayPtg)ptgs[0]).getTokenArrayValues()[0][0]; + + assertEquals(-42.0, ((Double)element).doubleValue(), 0.0); + + // Should be able to handle whitespace between unary minus and digits (Excel + // accepts this formula after presenting the user with a confirmation dialog). + ptgs = parseFormula("{- 5}"); + element = ((ArrayPtg)ptgs[0]).getTokenArrayValues()[0][0]; + assertEquals(-5.0, ((Double)element).doubleValue(), 0.0); + } + public void testRangeOperator() { HSSFWorkbook wb = new HSSFWorkbook(); |