diff options
author | PJ Fanning <fanningpj@apache.org> | 2020-05-15 20:15:00 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2020-05-15 20:15:00 +0000 |
commit | af8137a6e4d7a9c26ad0c91ec6f0642fc1a196f3 (patch) | |
tree | f5d0a602b184f307114b3bba3183ab287916d13c /src/testcases/org/apache | |
parent | 9bddb8729eb517f18b47d4e9eb6ed5495631462d (diff) | |
download | poi-af8137a6e4d7a9c26ad0c91ec6f0642fc1a196f3.tar.gz poi-af8137a6e4d7a9c26ad0c91ec6f0642fc1a196f3.zip |
[github-180] Add DateValue function. Thanks to Milosz Rembisz. This closes #180
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877793 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java | 4 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java | 78 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 1a09c5596b..d0529220d2 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -2899,6 +2899,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void test64261() throws IOException { simpleTest("64261.xls"); } + @Test + public void test63819() throws IOException { + simpleTest("63819.xls"); + } // a simple test which rewrites the file once and evaluates its formulas private void simpleTest(String fileName) throws IOException { simpleTest(fileName, null); diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java b/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java new file mode 100644 index 0000000000..fb185cc7fb --- /dev/null +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestDateValue.java @@ -0,0 +1,78 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.formula.functions; + +import org.apache.poi.ss.formula.eval.BlankEval; +import org.apache.poi.ss.formula.eval.BoolEval; +import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.NumberEval; +import org.apache.poi.ss.formula.eval.StringEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for Excel function DATEVALUE() + * + * @author Milosz Rembisz + */ +public final class TestDateValue { + + @Test + public void testDateValue() { + confirmDateValue(new StringEval("2020-02-01"), 43862); + confirmDateValue(new StringEval("01-02-2020"), 43862); + confirmDateValue(new StringEval("2020-FEB-01"), 43862); + confirmDateValue(new StringEval("2020-Feb-01"), 43862); + confirmDateValue(new StringEval("2020-FEBRUARY-01"), 43862); + confirmDateValue(new StringEval("FEB-01"), 43862); + confirmDateValue(new StringEval("2/1/2020"), 43862); + confirmDateValue(new StringEval("2/1"), 43862); + confirmDateValue(new StringEval("2020/2/1"), 43862); + confirmDateValue(new StringEval("2020/FEB/1"), 43862); + confirmDateValue(new StringEval("FEB/1/2020"), 43862); + confirmDateValue(new StringEval("2020/02/01"), 43862); + + confirmDateValue(new StringEval(""), BlankEval.instance); + confirmDateValue(BlankEval.instance, BlankEval.instance); + + confirmDateValue(new StringEval("non-date text"), ErrorEval.VALUE_INVALID); + } + + private ValueEval invokeDateValue(ValueEval text) { + return new DateValue().evaluate(0, 0, text); + } + + private void confirmDateValue(ValueEval text, double expected) { + ValueEval result = invokeDateValue(text); + assertEquals(NumberEval.class, result.getClass()); + assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0001); + } + + private void confirmDateValue(ValueEval text, BlankEval expected) { + ValueEval result = invokeDateValue(text); + assertEquals(BlankEval.class, result.getClass()); + } + + private void confirmDateValue(ValueEval text, ErrorEval expected) { + ValueEval result = invokeDateValue(text); + assertEquals(ErrorEval.class, result.getClass()); + assertEquals(expected.getErrorCode(), ((ErrorEval) result).getErrorCode()); + } +}
\ No newline at end of file |