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.annotation.Alerts;
19  import org.htmlunit.junit.annotation.HtmlUnitNYI;
20  import org.junit.jupiter.api.Test;
21  
22  /**
23   * Tests for {@link NumberFormat}.
24   *
25   * @author Ronald Brill
26   */
27  public class NumberFormatTest extends WebDriverTestCase {
28  
29      /**
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts({"zh-CN", "latn", "standard", "auto", "decimal", "1", "0", "3", "auto"})
34      @HtmlUnitNYI(CHROME = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
35                             "undefined", "undefined"},
36              EDGE = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
37                      "undefined", "undefined"},
38              FF = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
39                    "undefined", "undefined"},
40              FF_ESR = {"undefined", "undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
41                        "undefined", "undefined"})
42      public void resolvedOptionsValues() throws Exception {
43          final String html = DOCTYPE_HTML
44                  + "<html><head>\n"
45                  + "<script>\n"
46                  + LOG_TITLE_FUNCTION
47                  + "  function test() {\n"
48                  + "    var region1 = new Intl.NumberFormat('zh-CN');\n"
49                  + "    var options = region1.resolvedOptions();\n"
50                  + "    log(options.locale);\n"
51                  + "    log(options.numberingSystem);\n"
52                  + "    log(options.notation);\n"
53                  + "    log(options.signDisplay);\n"
54                  + "    log(options.style);\n"
55                  + "    log(options.minimumIntegerDigits);\n"
56                  + "    log(options.minimumFractionDigits);\n"
57                  + "    log(options.maximumFractionDigits);\n"
58                  + "    log(options.useGrouping);\n"
59                  + "  }\n"
60                  + "</script>\n"
61                  + "</head>\n"
62                  + "<body onload='test()'>\n"
63                  + "</body></html>";
64  
65          loadPageVerifyTitle2(html);
66      }
67  
68      /**
69       * @throws Exception if the test fails
70       */
71      @Test
72      @Alerts("[object Object]")
73      public void resolvedOptions() throws Exception {
74          final String html = DOCTYPE_HTML
75                  + "<html><head>\n"
76                  + "<script>\n"
77                  + LOG_TITLE_FUNCTION
78                  + "  function test() {\n"
79                  + "    var region1 = new Intl.NumberFormat('zh-CN');\n"
80                  + "    var options = region1.resolvedOptions();\n"
81                  + "    log(options);\n"
82                  + "  }\n"
83                  + "</script>\n"
84                  + "</head>\n"
85                  + "<body onload='test()'>\n"
86                  + "</body></html>";
87  
88          loadPageVerifyTitle2(html);
89      }
90  
91      /**
92       * @throws Exception if the test fails
93       */
94      @Test
95      @Alerts({"true", "42.247"})
96      public void numberFormat() throws Exception {
97          final String html = DOCTYPE_HTML
98                  + "<html><head>\n"
99                  + "<script>\n"
100                 + LOG_TITLE_FUNCTION
101                 + "  function test() {\n"
102                 + "    var numberFormat = Intl.NumberFormat('en');\n"
103                 + "    log(numberFormat instanceof Intl.NumberFormat);\n"
104 
105                 + "    log(numberFormat.format(42.2468));\n"
106                 + "  }\n"
107                 + "</script>\n"
108                 + "</head>\n"
109                 + "<body onload='test()'>\n"
110                 + "</body></html>";
111 
112         loadPageVerifyTitle2(html);
113     }
114 }