QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / parserstress / tests / ecma / TypeConversion / 9.2.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s): christine@netscape.com
24  *                 Jesse Ruderman
25  *
26  * Alternatively, the contents of this file may be used under the terms of
27  * either the GNU General Public License Version 2 or later (the "GPL"), or
28  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29  * in which case the provisions of the GPL or the LGPL are applicable instead
30  * of those above. If you wish to allow use of your version of this file only
31  * under the terms of either the GPL or the LGPL, and not to allow others to
32  * use your version of this file under the terms of the MPL, indicate your
33  * decision by deleting the provisions above and replace them with the notice
34  * and other provisions required by the GPL or the LGPL. If you do not delete
35  * the provisions above, a recipient may use your version of this file under
36  * the terms of any one of the MPL, the GPL or the LGPL.
37  *
38  * ***** END LICENSE BLOCK ***** */
39
40 gTestfile = '9.2.js';
41
42 /**
43    File Name:          9.2.js
44    ECMA Section:       9.2  Type Conversion:  ToBoolean
45    Description:        rules for converting an argument to a boolean.
46    undefined           false
47    Null                false
48    Boolean             input argument( no conversion )
49    Number              returns false for 0, -0, and NaN
50    otherwise return true
51    String              return false if the string is empty
52    (length is 0) otherwise the result is
53    true
54    Object              all return true
55
56    Author:             christine@netscape.com
57    Date:               14 july 1997
58 */
59 var SECTION = "9.2";
60 var VERSION = "ECMA_1";
61 startTest();
62 var TITLE   = "ToBoolean";
63
64 writeHeaderToLog( SECTION + " "+ TITLE);
65
66 // special cases here
67
68 new TestCase( SECTION,   "Boolean()",                     false,  Boolean() );
69 new TestCase( SECTION,   "Boolean(var x)",                false,  Boolean(eval("var x")) );
70 new TestCase( SECTION,   "Boolean(void 0)",               false,  Boolean(void 0) );
71 new TestCase( SECTION,   "Boolean(null)",                 false,  Boolean(null) );
72 new TestCase( SECTION,   "Boolean(false)",                false,  Boolean(false) );
73 new TestCase( SECTION,   "Boolean(true)",                 true,   Boolean(true) );
74 new TestCase( SECTION,   "Boolean(0)",                    false,  Boolean(0) );
75 new TestCase( SECTION,   "Boolean(-0)",                   false,  Boolean(-0) );
76 new TestCase( SECTION,   "Boolean(NaN)",                  false,  Boolean(Number.NaN) );
77 new TestCase( SECTION,   "Boolean('')",                   false,  Boolean("") );
78
79 // normal test cases here
80
81 new TestCase( SECTION,   "Boolean(Infinity)",             true,   Boolean(Number.POSITIVE_INFINITY) );
82 new TestCase( SECTION,   "Boolean(-Infinity)",            true,   Boolean(Number.NEGATIVE_INFINITY) );
83 new TestCase( SECTION,   "Boolean(Math.PI)",              true,   Boolean(Math.PI) );
84 new TestCase( SECTION,   "Boolean(1)",                    true,   Boolean(1) );
85 new TestCase( SECTION,   "Boolean(-1)",                   true,   Boolean(-1) );
86 new TestCase( SECTION,   "Boolean([tab])",                true,   Boolean("\t") );
87 new TestCase( SECTION,   "Boolean('0')",                  true,   Boolean("0") );
88 new TestCase( SECTION,   "Boolean('string')",             true,   Boolean("string") );
89
90 // ToBoolean (object) should always return true.
91 new TestCase( SECTION,   "Boolean(new String() )",        true,   Boolean(new String()) );
92 new TestCase( SECTION,   "Boolean(new String('') )",      true,   Boolean(new String("")) );
93
94 new TestCase( SECTION,   "Boolean(new Boolean(true))",    true,   Boolean(new Boolean(true)) );
95 new TestCase( SECTION,   "Boolean(new Boolean(false))",   true,   Boolean(new Boolean(false)) );
96 new TestCase( SECTION,   "Boolean(new Boolean() )",       true,   Boolean(new Boolean()) );
97
98 new TestCase( SECTION,   "Boolean(new Array())",          true,   Boolean(new Array()) );
99
100 new TestCase( SECTION,   "Boolean(new Number())",         true,   Boolean(new Number()) );
101 new TestCase( SECTION,   "Boolean(new Number(-0))",       true,   Boolean(new Number(-0)) );
102 new TestCase( SECTION,   "Boolean(new Number(0))",        true,   Boolean(new Number(0)) );
103 new TestCase( SECTION,   "Boolean(new Number(NaN))",      true,   Boolean(new Number(Number.NaN)) );
104
105 new TestCase( SECTION,   "Boolean(new Number(-1))",       true,   Boolean(new Number(-1)) );
106 new TestCase( SECTION,   "Boolean(new Number(Infinity))", true,   Boolean(new Number(Number.POSITIVE_INFINITY)) );
107 new TestCase( SECTION,   "Boolean(new Number(-Infinity))",true,   Boolean(new Number(Number.NEGATIVE_INFINITY)) );
108
109 new TestCase( SECTION,    "Boolean(new Object())",       true,       Boolean(new Object()) );
110 new TestCase( SECTION,    "Boolean(new Function())",     true,       Boolean(new Function()) );
111 new TestCase( SECTION,    "Boolean(new Date())",         true,       Boolean(new Date()) );
112 new TestCase( SECTION,    "Boolean(new Date(0))",         true,       Boolean(new Date(0)) );
113 new TestCase( SECTION,    "Boolean(Math)",         true,       Boolean(Math) );
114
115 // bug 375793
116 new TestCase( SECTION,
117               "NaN ? true : false",
118               false,
119               (NaN ? true : false) );
120 new TestCase( SECTION,
121               "1000 % 0 ? true : false",
122               false,
123               (1000 % 0 ? true : false) );
124 new TestCase( SECTION,
125               "(function(a,b){ return a % b ? true : false })(1000, 0)",
126               false,
127               ((function(a,b){ return a % b ? true : false })(1000, 0)) );
128
129 new TestCase( SECTION,
130               "(function(x) { return !(x) })(0/0)",
131               true,
132               ((function(x) { return !(x) })(0/0)) );
133 new TestCase( SECTION,
134               "!(0/0)",
135               true,
136               (!(0/0)) );
137 test();
138