js/src/tests/ecma/Expressions/11.9.2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Expressions/11.9.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          11.9.2.js
    1.12 +   ECMA Section:       11.9.2 The equals operator ( == )
    1.13 +   Description:
    1.14 +
    1.15 +   The production EqualityExpression:
    1.16 +   EqualityExpression ==  RelationalExpression is evaluated as follows:
    1.17 +
    1.18 +   1.  Evaluate EqualityExpression.
    1.19 +   2.  Call GetValue(Result(1)).
    1.20 +   3.  Evaluate RelationalExpression.
    1.21 +   4.  Call GetValue(Result(3)).
    1.22 +   5.  Perform the comparison Result(4) == Result(2). (See section 11.9.3)
    1.23 +   6.  Return Result(5).
    1.24 +   Author:             christine@netscape.com
    1.25 +   Date:               12 november 1997
    1.26 +*/
    1.27 +var SECTION = "11.9.2";
    1.28 +var VERSION = "ECMA_1";
    1.29 +var BUGNUMBER="77391";
    1.30 +startTest();
    1.31 +
    1.32 +writeHeaderToLog( SECTION + " The equals operator ( == )");
    1.33 +
    1.34 +// type x and type y are the same.  if type x is undefined or null, return true
    1.35 +
    1.36 +new TestCase( SECTION,    "void 0 == void 0",        false,   void 0 != void 0 );
    1.37 +new TestCase( SECTION,    "null == null",           false,   null != null );
    1.38 +
    1.39 +//  if x is NaN, return false. if y is NaN, return false.
    1.40 +
    1.41 +new TestCase( SECTION,    "NaN != NaN",             true,  Number.NaN != Number.NaN );
    1.42 +new TestCase( SECTION,    "NaN != 0",               true,  Number.NaN != 0 );
    1.43 +new TestCase( SECTION,    "0 != NaN",               true,  0 != Number.NaN );
    1.44 +new TestCase( SECTION,    "NaN != Infinity",        true,  Number.NaN != Number.POSITIVE_INFINITY );
    1.45 +new TestCase( SECTION,    "Infinity != NaN",        true,  Number.POSITIVE_INFINITY != Number.NaN );
    1.46 +
    1.47 +// if x is the same number value as y, return true.
    1.48 +
    1.49 +new TestCase( SECTION,    "Number.MAX_VALUE != Number.MAX_VALUE",   false,   Number.MAX_VALUE != Number.MAX_VALUE );
    1.50 +new TestCase( SECTION,    "Number.MIN_VALUE != Number.MIN_VALUE",   false,   Number.MIN_VALUE != Number.MIN_VALUE );
    1.51 +new TestCase( SECTION,    "Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY",   false,   Number.POSITIVE_INFINITY != Number.POSITIVE_INFINITY );
    1.52 +new TestCase( SECTION,    "Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY",   false,   Number.NEGATIVE_INFINITY != Number.NEGATIVE_INFINITY );
    1.53 +
    1.54 +//  if xis 0 and y is -0, return true.   if x is -0 and y is 0, return true.
    1.55 +
    1.56 +new TestCase( SECTION,    "0 != 0",                 false,   0 != 0 );
    1.57 +new TestCase( SECTION,    "0 != -0",                false,   0 != -0 );
    1.58 +new TestCase( SECTION,    "-0 != 0",                false,   -0 != 0 );
    1.59 +new TestCase( SECTION,    "-0 != -0",               false,   -0 != -0 );
    1.60 +
    1.61 +// return false.
    1.62 +
    1.63 +new TestCase( SECTION,    "0.9 != 1",               true,  0.9 != 1 );
    1.64 +new TestCase( SECTION,    "0.999999 != 1",          true,  0.999999 != 1 );
    1.65 +new TestCase( SECTION,    "0.9999999999 != 1",      true,  0.9999999999 != 1 );
    1.66 +new TestCase( SECTION,    "0.9999999999999 != 1",   true,  0.9999999999999 != 1 );
    1.67 +
    1.68 +// type x and type y are the same type, but not numbers.
    1.69 +
    1.70 +
    1.71 +// x and y are strings.  return true if x and y are exactly the same sequence of characters.
    1.72 +// otherwise, return false.
    1.73 +
    1.74 +new TestCase( SECTION,    "'hello' != 'hello'",         false,   "hello" != "hello" );
    1.75 +
    1.76 +// x and y are booleans.  return true if both are true or both are false.
    1.77 +
    1.78 +new TestCase( SECTION,    "true != true",               false,   true != true );
    1.79 +new TestCase( SECTION,    "false != false",             false,   false != false );
    1.80 +new TestCase( SECTION,    "true != false",              true,  true != false );
    1.81 +new TestCase( SECTION,    "false != true",              true,  false != true );
    1.82 +
    1.83 +// return true if x and y refer to the same object.  otherwise return false.
    1.84 +
    1.85 +new TestCase( SECTION,    "new MyObject(true) != new MyObject(true)",   true,  new MyObject(true) != new MyObject(true) );
    1.86 +new TestCase( SECTION,    "new Boolean(true) != new Boolean(true)",     true,  new Boolean(true) != new Boolean(true) );
    1.87 +new TestCase( SECTION,    "new Boolean(false) != new Boolean(false)",   true,  new Boolean(false) != new Boolean(false) );
    1.88 +
    1.89 +
    1.90 +new TestCase( SECTION,    "x = new MyObject(true); y = x; z = x; z != y",   false,  eval("x = new MyObject(true); y = x; z = x; z != y") );
    1.91 +new TestCase( SECTION,    "x = new MyObject(false); y = x; z = x; z != y",  false,  eval("x = new MyObject(false); y = x; z = x; z != y") );
    1.92 +new TestCase( SECTION,    "x = new Boolean(true); y = x; z = x; z != y",   false,  eval("x = new Boolean(true); y = x; z = x; z != y") );
    1.93 +new TestCase( SECTION,    "x = new Boolean(false); y = x; z = x; z != y",   false,  eval("x = new Boolean(false); y = x; z = x; z != y") );
    1.94 +
    1.95 +new TestCase( SECTION,    "new Boolean(true) != new Boolean(true)",     true,  new Boolean(true) != new Boolean(true) );
    1.96 +new TestCase( SECTION,    "new Boolean(false) != new Boolean(false)",   true,  new Boolean(false) != new Boolean(false) );
    1.97 +
    1.98 +// if x is null and y is undefined, return true.  if x is undefined and y is null return true.
    1.99 +
   1.100 +new TestCase( SECTION,    "null != void 0",             false,   null != void 0 );
   1.101 +new TestCase( SECTION,    "void 0 != null",             false,   void 0 != null );
   1.102 +
   1.103 +// if type(x) is Number and type(y) is string, return the result of the comparison x != ToNumber(y).
   1.104 +
   1.105 +new TestCase( SECTION,    "1 != '1'",                   false,   1 != '1' );
   1.106 +new TestCase( SECTION,    "255 != '0xff'",               false,  255 != '0xff' );
   1.107 +new TestCase( SECTION,    "0 != '\r'",                  false,   0 != "\r" );
   1.108 +new TestCase( SECTION,    "1e19 != '1e19'",             false,   1e19 != "1e19" );
   1.109 +
   1.110 +
   1.111 +new TestCase( SECTION,    "new Boolean(true) != true",  false,   true != new Boolean(true) );
   1.112 +new TestCase( SECTION,    "new MyObject(true) != true", false,   true != new MyObject(true) );
   1.113 +
   1.114 +new TestCase( SECTION,    "new Boolean(false) != false",    false,   new Boolean(false) != false );
   1.115 +new TestCase( SECTION,    "new MyObject(false) != false",   false,   new MyObject(false) != false );
   1.116 +
   1.117 +new TestCase( SECTION,    "true != new Boolean(true)",      false,   true != new Boolean(true) );
   1.118 +new TestCase( SECTION,    "true != new MyObject(true)",     false,   true != new MyObject(true) );
   1.119 +
   1.120 +new TestCase( SECTION,    "false != new Boolean(false)",    false,   false != new Boolean(false) );
   1.121 +new TestCase( SECTION,    "false != new MyObject(false)",   false,   false != new MyObject(false) );
   1.122 +
   1.123 +test();
   1.124 +
   1.125 +function MyObject( value ) {
   1.126 +  this.value = value;
   1.127 +  this.valueOf = new Function( "return this.value" );
   1.128 +}

mercurial