]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.13.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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
24 ECMA Section: 11.12 Conditional Operator
28 calORExpression ? AssignmentExpression : AssignmentExpression
32 The production ConditionalExpression :
33 LogicalORExpression ? AssignmentExpression : AssignmentExpression
34 is evaluated as follows:
36 1. Evaluate LogicalORExpression.
37 2. Call GetValue(Result(1)).
38 3. Call ToBoolean(Result(2)).
39 4. If Result(3) is false, go to step 8.
40 5. Evaluate the first AssignmentExpression.
41 6. Call GetValue(Result(5)).
43 8. Evaluate the second AssignmentExpression.
44 9. Call GetValue(Result(8)).
47 Author: christine@netscape.com
48 Date: 12 november 1997
50 var SECTION
= "11.12";
51 var VERSION
= "ECMA_1";
53 var testcases
= getTestCases();
55 writeHeaderToLog( SECTION
+ " Conditional operator( ? : )");
57 function getTestCases() {
58 var array
= new Array();
61 array
[item
++] = new TestCase( SECTION
, "true ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED"));
62 array
[item
++] = new TestCase( SECTION
, "false ? 'FAILED' : 'PASSED'", "PASSED", (false?"FAILED":"PASSED"));
64 array
[item
++] = new TestCase( SECTION
, "1 ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED"));
65 array
[item
++] = new TestCase( SECTION
, "0 ? 'FAILED' : 'PASSED'", "PASSED", (false?"FAILED":"PASSED"));
66 array
[item
++] = new TestCase( SECTION
, "-1 ? 'PASSED' : 'FAILED'", "PASSED", (true?"PASSED":"FAILED"));
68 array
[item
++] = new TestCase( SECTION
, "NaN ? 'FAILED' : 'PASSED'", "PASSED", (Number
.NaN
?"FAILED":"PASSED"));
70 array
[item
++] = new TestCase( SECTION
, "var VAR = true ? , : 'FAILED'", "PASSED", (VAR
= true ? "PASSED" : "FAILED") );
75 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
76 testcases
[tc
].passed
= writeTestCaseResult(
79 testcases
[tc
].description
+" = "+
80 testcases
[tc
].actual
);
82 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";