View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.intl;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.htmlunit.junit.annotation.HtmlUnitNYI;
21  import org.junit.Test;
22  import org.junit.runner.RunWith;
23  
24  /**
25   * Tests for {@link NumberFormat}.
26   *
27   * @author Ronald Brill
28   */
29  @RunWith(BrowserRunner.class)
30  public class NumberFormatTest extends WebDriverTestCase {
31  
32      /**
33       * @throws Exception if the test fails
34       */
35      @Test
36      @Alerts({"zh-CN", "latn", "standard", "auto", "decimal", "1", "0", "3", "auto"})
37      @HtmlUnitNYI(CHROME = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
38                             "undefined", "undefined"},
39              EDGE = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
40                      "undefined", "undefined"},
41              FF = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
42                    "undefined", "undefined"},
43              FF_ESR = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
44                        "undefined", "undefined"})
45      public void resolvedOptionsValues() throws Exception {
46          final String html = DOCTYPE_HTML
47                  + "<html><head>\n"
48                  + "<script>\n"
49                  + LOG_TITLE_FUNCTION
50                  + "  function test() {\n"
51                  + "    var region1 = new Intl.NumberFormat('zh-CN');\n"
52                  + "    var options = region1.resolvedOptions();\n"
53                  + "    log(options.locale);\n"
54                  + "    log(options.numberingSystem);\n"
55                  + "    log(options.notation);\n"
56                  + "    log(options.signDisplay);\n"
57                  + "    log(options.style);\n"
58                  + "    log(options.minimumIntegerDigits);\n"
59                  + "    log(options.minimumFractionDigits);\n"
60                  + "    log(options.maximumFractionDigits);\n"
61                  + "    log(options.useGrouping);\n"
62                  + "  }\n"
63                  + "</script>\n"
64                  + "</head>\n"
65                  + "<body onload='test()'>\n"
66                  + "</body></html>";
67  
68          loadPageVerifyTitle2(html);
69      }
70  
71      /**
72       * @throws Exception if the test fails
73       */
74      @Test
75      @Alerts("[object Object]")
76      public void resolvedOptions() throws Exception {
77          final String html = DOCTYPE_HTML
78                  + "<html><head>\n"
79                  + "<script>\n"
80                  + LOG_TITLE_FUNCTION
81                  + "  function test() {\n"
82                  + "    var region1 = new Intl.NumberFormat('zh-CN');\n"
83                  + "    var options = region1.resolvedOptions();\n"
84                  + "    log(options);\n"
85                  + "  }\n"
86                  + "</script>\n"
87                  + "</head>\n"
88                  + "<body onload='test()'>\n"
89                  + "</body></html>";
90  
91          loadPageVerifyTitle2(html);
92      }
93  
94      /**
95       * @throws Exception if the test fails
96       */
97      @Test
98      @Alerts({"true", "42.247"})
99      public void numberFormat() throws Exception {
100         final String html = DOCTYPE_HTML
101                 + "<html><head>\n"
102                 + "<script>\n"
103                 + LOG_TITLE_FUNCTION
104                 + "  function test() {\n"
105                 + "    var numberFormat = Intl.NumberFormat('en');\n"
106                 + "    log(numberFormat instanceof Intl.NumberFormat);\n"
107 
108                 + "    log(numberFormat.format(42.2468));\n"
109                 + "  }\n"
110                 + "</script>\n"
111                 + "</head>\n"
112                 + "<body onload='test()'>\n"
113                 + "</body></html>";
114 
115         loadPageVerifyTitle2(html);
116     }
117 }