1 /* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://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
16 #include "ecma-globals.h"
17 #include "ecma-helpers.h"
18 #include "jerryscript.h"
19
20 #include "test-common.h"
21
22 /**
23 * Unit test's main function.
24 */
25 int
main(void)26 main (void)
27 {
28 TEST_INIT ();
29
30 const jerry_char_t *strings[] =
31 {
32 (const jerry_char_t *) "1",
33 (const jerry_char_t *) "0.5",
34 (const jerry_char_t *) "12345",
35 (const jerry_char_t *) "1e-45",
36 (const jerry_char_t *) "-2.5e+38",
37 (const jerry_char_t *) "-2.5e38",
38 (const jerry_char_t *) "- 2.5e+38",
39 (const jerry_char_t *) "-2 .5e+38",
40 (const jerry_char_t *) "-2. 5e+38",
41 (const jerry_char_t *) "-2.5e+ 38",
42 (const jerry_char_t *) "-2.5 e+38",
43 (const jerry_char_t *) "-2.5e +38",
44 (const jerry_char_t *) "NaN",
45 (const jerry_char_t *) "abc",
46 (const jerry_char_t *) " Infinity ",
47 (const jerry_char_t *) "-Infinity",
48 (const jerry_char_t *) "0",
49 (const jerry_char_t *) "0",
50 };
51
52 const ecma_number_t nums[] =
53 {
54 (ecma_number_t) 1.0,
55 (ecma_number_t) 0.5,
56 (ecma_number_t) 12345.0,
57 (ecma_number_t) 1.0e-45,
58 (ecma_number_t) -2.5e+38,
59 (ecma_number_t) -2.5e+38,
60 (ecma_number_t) NAN,
61 (ecma_number_t) NAN,
62 (ecma_number_t) NAN,
63 (ecma_number_t) NAN,
64 (ecma_number_t) NAN,
65 (ecma_number_t) NAN,
66 (ecma_number_t) NAN,
67 (ecma_number_t) NAN,
68 (ecma_number_t) INFINITY,
69 (ecma_number_t) -INFINITY,
70 (ecma_number_t) +0.0,
71 (ecma_number_t) -0.0
72 };
73
74 for (uint32_t i = 0;
75 i < sizeof (nums) / sizeof (nums[0]);
76 i++)
77 {
78 ecma_number_t num = ecma_utf8_string_to_number (strings[i], lit_zt_utf8_string_size (strings[i]));
79
80 if (num != nums[i]
81 && (!ecma_number_is_nan (num)
82 || !ecma_number_is_nan (nums[i])))
83 {
84 return 1;
85 }
86 }
87
88 return 0;
89 } /* main */
90