jdk/test/java/text/Format/DateFormat/Bug8139572.java
author shurailine
Tue, 30 Aug 2016 14:30:32 -0700
changeset 40679 5378433ac23f
parent 34690 48ccec8b0e75
permissions -rw-r--r--
8164859: Fix module dependences in java/text tests Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34690
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     1
/*
40679
5378433ac23f 8164859: Fix module dependences in java/text tests
shurailine
parents: 34690
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
34690
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     4
 *
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     8
 *
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    13
 * accompanied this code).
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    14
 *
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    18
 *
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    21
 * questions.
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    22
 */
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    23
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    24
/*
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    25
 * @test
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    26
 * @bug 8139572
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    27
 * @summary SimpleDateFormat parse month stand-alone format bug
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    28
 * @compile -encoding utf-8 Bug8139572.java
40679
5378433ac23f 8164859: Fix module dependences in java/text tests
shurailine
parents: 34690
diff changeset
    29
 * @modules jdk.localedata
34690
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    30
 * @run main Bug8139572
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    31
 */
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    32
import java.text.ParseException;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    33
import java.text.SimpleDateFormat;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    34
import java.util.Calendar;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    35
import java.util.Date;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    36
import java.util.GregorianCalendar;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    37
import java.util.Locale;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    38
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    39
public class Bug8139572 {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    40
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    41
    private static final Locale RUSSIAN = new Locale("ru");
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    42
    private static final Date SEPT12 = new GregorianCalendar(2015, Calendar.SEPTEMBER, 12).getTime();
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    43
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    44
    private static final String[] PATTERNS = {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    45
        "L",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    46
        "dd L",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    47
        "dd L yy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    48
        "dd L yyyy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    49
        "LL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    50
        "dd LL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    51
        "dd LL yy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    52
        "dd LL yyyy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    53
        "LLL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    54
        "dd LLL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    55
        "dd LLL yy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    56
        "dd LLL yyyy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    57
        "LLLL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    58
        "dd LLLL",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    59
        "dd LLLL yy",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    60
        "dd LLLL yyyy"
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    61
    };
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    62
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    63
    private static final String[] APPLIED = {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    64
        "9",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    65
        "12 09",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    66
        "12 09 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    67
        "12 09 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    68
        "09",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    69
        "12 09",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    70
        "12 09 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    71
        "12 09 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    72
        "сентября",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    73
        "12 сентября",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    74
        "12 сентября 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    75
        "12 сентября 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    76
        "сентября",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    77
        "12 сентября",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    78
        "12 сентября 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    79
        "12 сентября 2015"
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    80
    };
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    81
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    82
    private static final String[] EXPECTED = {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    83
        "9",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    84
        "12 9",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    85
        "12 9 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    86
        "12 9 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    87
        "09",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    88
        "12 09",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    89
        "12 09 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    90
        "12 09 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    91
        "сент.",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    92
        "12 сент.",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    93
        "12 сент. 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    94
        "12 сент. 2015",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    95
        "сентябрь",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    96
        "12 сентябрь",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    97
        "12 сентябрь 15",
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    98
        "12 сентябрь 2015"
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
    99
    };
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   100
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   101
    public static void main(String[] args) throws ParseException {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   102
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   103
        for (int i = 0; i < PATTERNS.length; i++) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   104
            SimpleDateFormat fmt = new SimpleDateFormat(PATTERNS[i], RUSSIAN);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   105
            Date standAloneDate = fmt.parse(APPLIED[i]);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   106
            String str = fmt.format(standAloneDate);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   107
            if (!EXPECTED[i].equals(str)) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   108
                throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[i] + "'");
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   109
            }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   110
        }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   111
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   112
        SimpleDateFormat fmt = new SimpleDateFormat("", RUSSIAN);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   113
        for (int j = 0; j < PATTERNS.length; j++) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   114
            fmt.applyPattern(PATTERNS[j]);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   115
            String str = fmt.format(SEPT12);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   116
            if (!EXPECTED[j].equals(str)) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   117
                throw new RuntimeException("bad result: got '" + str + "', expected '" + EXPECTED[j] + "'");
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   118
            }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   119
        }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   120
    }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents:
diff changeset
   121
}