]> source.dussan.org Git - poi.git/commitdiff
annotate purpose of each PROPER() function test case, add a few more test cases,...
authorJaven O'Neal <onealj@apache.org>
Fri, 15 Jul 2016 07:25:16 +0000 (07:25 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 15 Jul 2016 07:25:16 +0000 (07:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752786 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/functions/TextFunction.java
src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java

index 82082bb9c3236ac90e7eff63f60028c5deec7299..f9562ef857a93c44e7e4bf42367f65e0820b7a0a 100644 (file)
@@ -112,18 +112,18 @@ public abstract class TextFunction implements Function {
         * Implementation of the PROPER function:
      * Normalizes all words (separated by non-word characters) by
      * making the first letter upper and the rest lower case.
+     * 
+     * This is nearly equivalent to toTitleCase if the Java language had it
         */
        public static final Function PROPER = new SingleArgTextFunc() {
                protected ValueEval evaluate(String text) {
                        StringBuilder sb = new StringBuilder();
                        boolean shouldMakeUppercase = true;
-                       final int length = text.length();
-                       for(int i = 0; i < length; ++i) {
-                               final char ch = text.charAt(i);
+                       for(final char ch : text.toCharArray()) {
 
                                // Note: we are using String.toUpperCase() here on purpose as it handles certain things
                                // better than Character.toUpperCase(), e.g. German "scharfes s" is translated
-                               // to "SS" (i.e. two characters), if upercased properly!
+                               // to "SS" (i.e. two characters), if uppercased properly!
                                if (shouldMakeUppercase) {
                                        sb.append(String.valueOf(ch).toUpperCase(Locale.ROOT));
                                }
index cb0be00e3444a3073ef656b7958aa0029ac54922..a9095982c4889398968976dc6e31215bb8ff099d 100644 (file)
@@ -54,14 +54,25 @@ public final class TestProper extends TestCase {
         cell11 = sheet.createRow(0).createCell(0);
         cell11.setCellType(CellType.FORMULA);
 
-        confirm("PROPER(\"hi there\")", "Hi There");
-        confirm("PROPER(\"what's up\")", "What'S Up");
-        confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!");
+        confirm("PROPER(\"hi there\")", "Hi There"); //simple case
+        confirm("PROPER(\"what's up\")", "What'S Up"); //apostrophes are treated as word breaks
+        confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!"); //capitalization is ignored, special punctuation is treated as a word break
         confirm("PROPER(\"dr\u00dcb\u00f6'\u00e4 \u00e9lo\u015f|\u00eb\u00e8 \")", "Dr\u00fcb\u00f6'\u00c4 \u00c9lo\u015f|\u00cb\u00e8 ");
-        confirm("PROPER(\"hi123 the123re\")", "Hi123 The123Re");
-        confirm("PROPER(\"-\")", "-");
-        confirm("PROPER(\"!\u00a7$\")", "!\u00a7$");
-        confirm("PROPER(\"/&%\")", "/&%");
+        confirm("PROPER(\"hi123 the123re\")", "Hi123 The123Re"); //numbers are treated as word breaks
+        confirm("PROPER(\"-\")", "-"); //nothing happens with ascii punctuation that is not upper or lower case
+        confirm("PROPER(\"!\u00a7$\")", "!\u00a7$"); //nothing happens with unicode punctuation (section sign) that is not upper or lower case
+        confirm("PROPER(\"/&%\")", "/&%"); //nothing happens with ascii punctuation that is not upper or lower case
+        confirm("PROPER(\"Apache POI\")", "Apache Poi"); //acronyms are not special
+        confirm("PROPER(\"  hello world\")", "  Hello World"); //leading whitespace is ignored
+        
+        final String scharfes = "\u00df$"; //German lowercase eszett, scharfes s, sharp s
+        // CURRENTLY FAILS: result: "Stra"+scharfes+"E"
+        // confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e");
+        
+        // CURRENTLY FAILS: result: "SSUnd"+scharfes
+        // LibreOffice 5.0.3.2 behavior: "Sund"+scharfes
+        // Excel 2013 behavior: ???
+        //confirm("PROPER(\""+scharfes+"und"+scharfes+"\")", "SSund"+scharfes);
         
         // also test longer string
         StringBuilder builder = new StringBuilder("A");