initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / Statements / 12.5-2.js
1 /* The contents of this file are subject to the Netscape Public
2  * License Version 1.1 (the "License"); you may not use this file
3  * except in compliance with the License. You may obtain a copy of
4  * the License at http://www.mozilla.org/NPL/
5  *
6  * Software distributed under the License is distributed on an "AS
7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8  * implied. See the License for the specific language governing
9  * rights and limitations under the License.
10  *
11  * The Original Code is Mozilla Communicator client code, released March
12  * 31, 1998.
13  *
14  * The Initial Developer of the Original Code is Netscape Communications
15  * Corporation. Portions created by Netscape are
16  * Copyright (C) 1998 Netscape Communications Corporation. All
17  * Rights Reserved.
18  *
19  * Contributor(s): 
20  * 
21  */
22 /**
23     File Name:          12.5-2.js
24     ECMA Section:       The if statement
25     Description:
26
27     The production IfStatement : if ( Expression ) Statement else Statement
28     is evaluated as follows:
29
30     1.Evaluate Expression.
31     2.Call GetValue(Result(1)).
32     3.Call ToBoolean(Result(2)).
33     4.If Result(3) is false, go to step 7.
34     5.Evaluate the first Statement.
35     6.Return Result(5).
36     7.Evaluate the second Statement.
37     8.Return Result(7).
38
39     Author:             christine@netscape.com
40     Date:               12 november 1997
41 */
42
43     var SECTION = "12.5-2";
44     var VERSION = "ECMA_1";
45     startTest();
46     var TITLE = "The if statement" ;
47
48     writeHeaderToLog( SECTION + " "+ TITLE);
49
50     var testcases = new Array();
51
52     testcases[tc++] = new TestCase(   SECTION,
53                                     "var MYVAR; if ( true ) MYVAR='PASSED'; MYVAR",
54                                     "PASSED",
55                                     eval("var MYVAR; if ( true ) MYVAR='PASSED'; MYVAR") );
56
57     testcases[tc++] = new TestCase(  SECTION,
58                                     "var MYVAR; if ( false ) MYVAR='FAILED'; MYVAR;",
59                                     "PASSED",
60                                     eval("var MYVAR=\"PASSED\"; if ( false ) MYVAR='FAILED'; MYVAR;") );
61
62     testcases[tc++] = new TestCase(   SECTION,
63                                     "var MYVAR; if ( new Boolean(true) ) MYVAR='PASSED'; MYVAR",
64                                     "PASSED",
65                                     eval("var MYVAR; if ( new Boolean(true) ) MYVAR='PASSED'; MYVAR") );
66
67     testcases[tc++] = new TestCase(   SECTION,
68                                     "var MYVAR; if ( new Boolean(false) ) MYVAR='PASSED'; MYVAR",
69                                     "PASSED",
70                                     eval("var MYVAR; if ( new Boolean(false) ) MYVAR='PASSED'; MYVAR") );
71
72     testcases[tc++] = new TestCase(   SECTION,
73                                     "var MYVAR; if ( 1 ) MYVAR='PASSED'; MYVAR",
74                                     "PASSED",
75                                     eval("var MYVAR; if ( 1 ) MYVAR='PASSED'; MYVAR") );
76
77     testcases[tc++] = new TestCase(  SECTION,
78                                     "var MYVAR; if ( 0 ) MYVAR='FAILED'; MYVAR;",
79                                     "PASSED",
80                                     eval("var MYVAR=\"PASSED\"; if ( 0 ) MYVAR='FAILED'; MYVAR;") );
81
82     test();
83
84 function test() {
85     for ( tc=0; tc < testcases.length; tc++ ) {
86         testcases[tc].passed = writeTestCaseResult(
87                             testcases[tc].expect,
88                             testcases[tc].actual,
89                             testcases[tc].description +" = "+
90                             testcases[tc].actual );
91
92         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
93     }
94     stopTest();
95     return ( testcases );
96 }