js/src/tests/ecma_3/Expressions/11.9.6-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Expressions/11.9.6-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,179 @@
     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 + * Date:    20 Feb 2002
    1.12 + * SUMMARY: Testing the comparison |undefined === null|
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=126722
    1.14 + *
    1.15 + */
    1.16 +//-----------------------------------------------------------------------------
    1.17 +var UBound = 0;
    1.18 +var BUGNUMBER = 126722;
    1.19 +var summary = 'Testing the comparison |undefined === null|';
    1.20 +var status = '';
    1.21 +var statusitems = [];
    1.22 +var actual = '';
    1.23 +var actualvalues = [];
    1.24 +var expect= '';
    1.25 +var expectedvalues = [];
    1.26 +
    1.27 +
    1.28 +status = inSection(1);
    1.29 +if (undefined === null)
    1.30 +  actual = true;
    1.31 +else
    1.32 +  actual = false;
    1.33 +expect = false;
    1.34 +addThis();
    1.35 +
    1.36 +
    1.37 +
    1.38 +status = inSection(2);
    1.39 +switch(true)
    1.40 +{
    1.41 +case (undefined === null) :
    1.42 +  actual = true;
    1.43 +  break;
    1.44 +
    1.45 +default:
    1.46 +  actual = false;
    1.47 +}
    1.48 +expect = false;
    1.49 +addThis();
    1.50 +
    1.51 +
    1.52 +
    1.53 +status = inSection(3);
    1.54 +function f3(x)
    1.55 +{
    1.56 +  var res = false;
    1.57 +
    1.58 +  switch(true)
    1.59 +  {
    1.60 +  case (x === null) :
    1.61 +    res = true;
    1.62 +    break;
    1.63 +
    1.64 +  default:
    1.65 +    // do nothing
    1.66 +  }
    1.67 +
    1.68 +  return res;
    1.69 +}
    1.70 +
    1.71 +actual = f3(undefined);
    1.72 +expect = false;
    1.73 +addThis();
    1.74 +
    1.75 +
    1.76 +
    1.77 +status = inSection(4);
    1.78 +function f4(arr)
    1.79 +{
    1.80 +  var elt = '';
    1.81 +  var res = false;
    1.82 +
    1.83 +  for (i=0; i<arr.length; i++)
    1.84 +  {
    1.85 +    elt = arr[i];
    1.86 +
    1.87 +    switch(true)
    1.88 +    {
    1.89 +    case (elt === null) :
    1.90 +      res = true;
    1.91 +      break;
    1.92 +
    1.93 +    default:
    1.94 +      // do nothing
    1.95 +    }
    1.96 +  }
    1.97 +
    1.98 +  return res;
    1.99 +}
   1.100 +
   1.101 +var arr = Array('a', undefined);
   1.102 +actual = f4(arr);
   1.103 +expect = false;
   1.104 +addThis();
   1.105 +
   1.106 +
   1.107 +
   1.108 +status = inSection(5);
   1.109 +function f5(arr)
   1.110 +{
   1.111 +  var len = arr.length;
   1.112 +
   1.113 +  for(var i=0; (arr[i]===undefined) && (i<len); i++)
   1.114 +    ; //do nothing
   1.115 + 
   1.116 +  return i;
   1.117 +}
   1.118 +
   1.119 +/*
   1.120 + * An array of 5 undefined elements. Note:
   1.121 + *
   1.122 + * The return value of eval(a STATEMENT) is undefined.
   1.123 + * A non-existent PROPERTY is undefined, not a ReferenceError.
   1.124 + * No undefined element exists AFTER trailing comma at end.
   1.125 + *
   1.126 + */
   1.127 +var arrUndef = [ , undefined, eval('var x = 0'), this.NOT_A_PROPERTY, , ];
   1.128 +actual = f5(arrUndef);
   1.129 +expect = 5;
   1.130 +addThis();
   1.131 +
   1.132 +
   1.133 +
   1.134 +status = inSection(6);
   1.135 +function f6(arr)
   1.136 +{
   1.137 +  var len = arr.length;
   1.138 +
   1.139 +  for(var i=0; (arr[i]===null) && (i<len); i++)
   1.140 +    ; //do nothing
   1.141 +
   1.142 +  return i;
   1.143 +}
   1.144 +
   1.145 +/*
   1.146 + * Use same array as above. This time we're comparing to |null|, so we expect 0
   1.147 + */
   1.148 +actual = f6(arrUndef);
   1.149 +expect = 0;
   1.150 +addThis();
   1.151 +
   1.152 +
   1.153 +
   1.154 +
   1.155 +//-----------------------------------------------------------------------------
   1.156 +test();
   1.157 +//-----------------------------------------------------------------------------
   1.158 +
   1.159 +
   1.160 +
   1.161 +function addThis()
   1.162 +{
   1.163 +  statusitems[UBound] = status;
   1.164 +  actualvalues[UBound] = actual;
   1.165 +  expectedvalues[UBound] = expect;
   1.166 +  UBound++;
   1.167 +}
   1.168 +
   1.169 +
   1.170 +function test()
   1.171 +{
   1.172 +  enterFunc('test');
   1.173 +  printBugNumber(BUGNUMBER);
   1.174 +  printStatus(summary);
   1.175 +
   1.176 +  for (var i=0; i<UBound; i++)
   1.177 +  {
   1.178 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.179 +  }
   1.180 +
   1.181 +  exitFunc ('test');
   1.182 +}

mercurial