| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
info: | |
| 6 |
0, null, undefined, false, empty string, NaN in expression is evaluated |
| 7 |
to false |
| 8 |
es5id: 12.5_A1.1_T2 |
| 9 |
description: Using "if/else" construction |
| 10 |
---*/ |
| 11 |
|
| 12 |
var c=0; |
| 13 |
////////////////////////////////////////////////////////////////////////////// |
| 14 |
//CHECK#1 |
| 15 |
if(0) |
| 16 |
throw new Test262Error('#1.1: 0 in expression is evaluated to false '); |
| 17 |
else |
| 18 |
c++; |
| 19 |
if (c!=1) throw new Test262Error('#1.2: else branch don`t execute'); |
| 20 |
// |
| 21 |
////////////////////////////////////////////////////////////////////////////// |
| 22 |
|
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
//CHECK#2 |
| 25 |
if(false) |
| 26 |
throw new Test262Error('#2.1: false in expression is evaluated to false '); |
| 27 |
else |
| 28 |
c++; |
| 29 |
if (c!=2) throw new Test262Error('#2.2: else branch don`t execute'); |
| 30 |
// |
| 31 |
////////////////////////////////////////////////////////////////////////////// |
| 32 |
|
| 33 |
////////////////////////////////////////////////////////////////////////////// |
| 34 |
//CHECK#3 |
| 35 |
if(null) |
| 36 |
throw new Test262Error('#3.1: null in expression is evaluated to false '); |
| 37 |
else |
| 38 |
c++; |
| 39 |
if (c!=3) throw new Test262Error('#3.2: else branch don`t execute'); |
| 40 |
// |
| 41 |
////////////////////////////////////////////////////////////////////////////// |
| 42 |
|
| 43 |
////////////////////////////////////////////////////////////////////////////// |
| 44 |
//CHECK#4 |
| 45 |
if(undefined) |
| 46 |
throw new Test262Error('#4.1: undefined in expression is evaluated to false '); |
| 47 |
else |
| 48 |
c++; |
| 49 |
if (c!=4) throw new Test262Error('#4.2: else branch don`t execute'); |
| 50 |
// |
| 51 |
////////////////////////////////////////////////////////////////////////////// |
| 52 |
|
| 53 |
////////////////////////////////////////////////////////////////////////////// |
| 54 |
//CHECK#5 |
| 55 |
if("") |
| 56 |
throw new Test262Error('#5.1: empty string in expression is evaluated to false '); |
| 57 |
else |
| 58 |
c++; |
| 59 |
if (c!=5) throw new Test262Error('#5.2: else branch don`t execute'); |
| 60 |
// |
| 61 |
////////////////////////////////////////////////////////////////////////////// |
| 62 |
|
| 63 |
////////////////////////////////////////////////////////////////////////////// |
| 64 |
//CHECK#6 |
| 65 |
if(NaN) |
| 66 |
throw new Test262Error('#6.1: NaN in expression is evaluated to false '); |
| 67 |
else |
| 68 |
c++; |
| 69 |
if (c!=6) throw new Test262Error('#6.2: else branch don`t execute'); |
| 70 |
// |
| 71 |
////////////////////////////////////////////////////////////////////////////// |
| 72 |
|
| 73 |
reportCompare(0, 0); |