2005-08-16 Marek Safar <marek.safar@seznam.cz>
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma / TypeConversion / 9.4-1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\r
2 /* ***** BEGIN LICENSE BLOCK *****\r
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
4  *\r
5  * The contents of this file are subject to the Mozilla Public License Version\r
6  * 1.1 (the "License"); you may not use this file except in compliance with\r
7  * the License. You may obtain a copy of the License at\r
8  * http://www.mozilla.org/MPL/\r
9  *\r
10  * Software distributed under the License is distributed on an "AS IS" basis,\r
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
12  * for the specific language governing rights and limitations under the\r
13  * License.\r
14  *\r
15  * The Original Code is Mozilla Communicator client code, released\r
16  * March 31, 1998.\r
17  *\r
18  * The Initial Developer of the Original Code is\r
19  * Netscape Communications Corporation.\r
20  * Portions created by the Initial Developer are Copyright (C) 1998\r
21  * the Initial Developer. All Rights Reserved.\r
22  *\r
23  * Contributor(s):\r
24  *\r
25  * Alternatively, the contents of this file may be used under the terms of\r
26  * either the GNU General Public License Version 2 or later (the "GPL"), or\r
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
28  * in which case the provisions of the GPL or the LGPL are applicable instead\r
29  * of those above. If you wish to allow use of your version of this file only\r
30  * under the terms of either the GPL or the LGPL, and not to allow others to\r
31  * use your version of this file under the terms of the MPL, indicate your\r
32  * decision by deleting the provisions above and replace them with the notice\r
33  * and other provisions required by the GPL or the LGPL. If you do not delete\r
34  * the provisions above, a recipient may use your version of this file under\r
35  * the terms of any one of the MPL, the GPL or the LGPL.\r
36  *\r
37  * ***** END LICENSE BLOCK ***** */\r
38 \r
39 /**\r
40    File Name:          9.4-1.js\r
41    ECMA Section:       9.4 ToInteger\r
42    Description:        1.  Call ToNumber on the input argument\r
43    2.  If Result(1) is NaN, return +0\r
44    3.  If Result(1) is +0, -0, Infinity, or -Infinity,\r
45    return Result(1).\r
46    4.  Compute sign(Result(1)) * floor(abs(Result(1))).\r
47    5.  Return Result(4).\r
48 \r
49    To test ToInteger, this test uses new Date(value),\r
50    15.9.3.7.  The Date constructor sets the [[Value]]\r
51    property of the new object to TimeClip(value), which\r
52    uses the rules:\r
53 \r
54    TimeClip(time)\r
55    1. If time is not finite, return NaN\r
56    2. If abs(Result(1)) > 8.64e15, return NaN\r
57    3. Return an implementation dependent choice of either\r
58    ToInteger(Result(2)) or ToInteger(Result(2)) + (+0)\r
59    (Adding a positive 0 converts -0 to +0).\r
60 \r
61    This tests ToInteger for values -8.64e15 > value > 8.64e15,\r
62    not including -0 and +0.\r
63 \r
64    For additional special cases (0, +0, Infinity, -Infinity,\r
65    and NaN, see 9.4-2.js).  For value is String, see 9.4-3.js.\r
66 \r
67    Author:             christine@netscape.com\r
68    Date:               10 july 1997\r
69 \r
70 */\r
71 var SECTION = "9.4-1";\r
72 var VERSION = "ECMA_1";\r
73 startTest();\r
74 var TITLE   = "ToInteger";\r
75 \r
76 writeHeaderToLog( SECTION + " "+ TITLE);\r
77 \r
78 // some special cases\r
79 \r
80 new TestCase( SECTION,  "td = new Date(Number.NaN); td.valueOf()",  Number.NaN, eval("td = new Date(Number.NaN); td.valueOf()") );\r
81 new TestCase( SECTION,  "td = new Date(Infinity); td.valueOf()",    Number.NaN, eval("td = new Date(Number.POSITIVE_INFINITY); td.valueOf()") );\r
82 new TestCase( SECTION,  "td = new Date(-Infinity); td.valueOf()",   Number.NaN, eval("td = new Date(Number.NEGATIVE_INFINITY); td.valueOf()") );\r
83 new TestCase( SECTION,  "td = new Date(-0); td.valueOf()",          -0,         eval("td = new Date(-0); td.valueOf()" ) );\r
84 new TestCase( SECTION,  "td = new Date(0); td.valueOf()",           0,          eval("td = new Date(0); td.valueOf()") );\r
85 \r
86 // value is not an integer\r
87 \r
88 new TestCase( SECTION,  "td = new Date(3.14159); td.valueOf()",     3,          eval("td = new Date(3.14159); td.valueOf()") );\r
89 new TestCase( SECTION,  "td = new Date(Math.PI); td.valueOf()",     3,          eval("td = new Date(Math.PI); td.valueOf()") );\r
90 new TestCase( SECTION,  "td = new Date(-Math.PI);td.valueOf()",     -3,         eval("td = new Date(-Math.PI);td.valueOf()") );\r
91 new TestCase( SECTION,  "td = new Date(3.14159e2); td.valueOf()",   314,        eval("td = new Date(3.14159e2); td.valueOf()") );\r
92 \r
93 new TestCase( SECTION,  "td = new Date(.692147e1); td.valueOf()",   6,          eval("td = new Date(.692147e1);td.valueOf()") );\r
94 new TestCase( SECTION,  "td = new Date(-.692147e1);td.valueOf()",   -6,         eval("td = new Date(-.692147e1);td.valueOf()") );\r
95 \r
96 // value is not a number\r
97 \r
98 new TestCase( SECTION,  "td = new Date(true); td.valueOf()",        1,          eval("td = new Date(true); td.valueOf()" ) );\r
99 new TestCase( SECTION,  "td = new Date(false); td.valueOf()",       0,          eval("td = new Date(false); td.valueOf()") );\r
100 \r
101 new TestCase( SECTION,  "td = new Date(new Number(Math.PI)); td.valueOf()",  3, eval("td = new Date(new Number(Math.PI)); td.valueOf()") );\r
102 new TestCase( SECTION,  "td = new Date(new Number(Math.PI)); td.valueOf()",  3, eval("td = new Date(new Number(Math.PI)); td.valueOf()") );\r
103 \r
104 // edge cases\r
105 new TestCase( SECTION,  "td = new Date(8.64e15); td.valueOf()",     8.64e15,    eval("td = new Date(8.64e15); td.valueOf()") );\r
106 new TestCase( SECTION,  "td = new Date(-8.64e15); td.valueOf()",    -8.64e15,   eval("td = new Date(-8.64e15); td.valueOf()") );\r
107 new TestCase( SECTION,  "td = new Date(8.64e-15); td.valueOf()",    0,          eval("td = new Date(8.64e-15); td.valueOf()") );\r
108 new TestCase( SECTION,  "td = new Date(-8.64e-15); td.valueOf()",   0,          eval("td = new Date(-8.64e-15); td.valueOf()") );\r
109 \r
110 test();\r