js/src/tests/ecma_6/Expressions/binary-literals.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_6/Expressions/binary-literals.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +// Any copyright is dedicated to the Public Domain.
     1.5 +// http://creativecommons.org/licenses/publicdomain/
     1.6 +
     1.7 +//-----------------------------------------------------------------------------
     1.8 +var BUGNUMBER = 894026;
     1.9 +var summary = "Implement ES6 binary literals";
    1.10 +
    1.11 +print(BUGNUMBER + ": " + summary);
    1.12 +
    1.13 +/**************
    1.14 + * BEGIN TEST *
    1.15 + **************/
    1.16 +
    1.17 +var chars = ['b', 'B'];
    1.18 +
    1.19 +for (var i = 0; i < 2; i++)
    1.20 +{
    1.21 +  if (i === 2)
    1.22 +  {
    1.23 +    chars.forEach(function(v)
    1.24 +    {
    1.25 +      try
    1.26 +      {
    1.27 +        eval('0' + v + i);
    1.28 +        throw "didn't throw";
    1.29 +      }
    1.30 +      catch (e)
    1.31 +      {
    1.32 +        assertEq(e instanceof SyntaxError, true,
    1.33 +                 "no syntax error evaluating 0" + v + i + ", " +
    1.34 +                 "got " + e);
    1.35 +      }
    1.36 +    });
    1.37 +    continue;
    1.38 +  }
    1.39 +
    1.40 +  for (var j = 0; j < 2; j++)
    1.41 +  {
    1.42 +    if (j === 2)
    1.43 +    {
    1.44 +      chars.forEach(function(v)
    1.45 +      {
    1.46 +        try
    1.47 +        {
    1.48 +          eval('0' + v + i + j);
    1.49 +          throw "didn't throw";
    1.50 +        }
    1.51 +        catch (e)
    1.52 +        {
    1.53 +          assertEq(e instanceof SyntaxError, true,
    1.54 +                   "no syntax error evaluating 0" + v + i + j + ", " +
    1.55 +                   "got " + e);
    1.56 +        }
    1.57 +      });
    1.58 +      continue;
    1.59 +    }
    1.60 +
    1.61 +    for (var k = 0; k < 2; k++)
    1.62 +    {
    1.63 +      if (k === 2)
    1.64 +      {
    1.65 +        chars.forEach(function(v)
    1.66 +        {
    1.67 +          try
    1.68 +          {
    1.69 +            eval('0' + v + i + j + k);
    1.70 +            throw "didn't throw";
    1.71 +          }
    1.72 +          catch (e)
    1.73 +          {
    1.74 +            assertEq(e instanceof SyntaxError, true,
    1.75 +                     "no syntax error evaluating 0" + v + i + j + k + ", " +
    1.76 +                     "got " + e);
    1.77 +          }
    1.78 +        });
    1.79 +        continue;
    1.80 +      }
    1.81 +
    1.82 +      chars.forEach(function(v)
    1.83 +      {
    1.84 +        assertEq(eval('0' + v + i + j + k), i * 4 + j * 2 + k);
    1.85 +      });
    1.86 +    }
    1.87 +  }
    1.88 +}
    1.89 +
    1.90 +chars.forEach(function(v)
    1.91 +{
    1.92 +  try
    1.93 +  {
    1.94 +  }
    1.95 +  catch (e)
    1.96 +  {
    1.97 +    assertEq(e instanceof SyntaxError, true,
    1.98 +             "no syntax error evaluating 0" + v + ", got " + e);
    1.99 +  }
   1.100 +});
   1.101 +
   1.102 +// Off-by-one check: '/' immediately precedes '0'.
   1.103 +assertEq(0b110/1, 6);
   1.104 +assertEq(0B10110/1, 22);
   1.105 +
   1.106 +function strict()
   1.107 +{
   1.108 +  "use strict";
   1.109 +  return 0b11010101;
   1.110 +}
   1.111 +assertEq(strict(), 128 + 64 + 16 + 4 + 1);
   1.112 +
   1.113 +/******************************************************************************/
   1.114 +
   1.115 +if (typeof reportCompare === "function")
   1.116 +  reportCompare(true, true);
   1.117 +
   1.118 +print("Tests complete");

mercurial