1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_6/Expressions/octal-literals.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 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 octal literals"; 1.10 + 1.11 +print(BUGNUMBER + ": " + summary); 1.12 + 1.13 +/************** 1.14 + * BEGIN TEST * 1.15 + **************/ 1.16 + 1.17 +var chars = ['o', 'O']; 1.18 + 1.19 +for (var i = 0; i < 8; i++) 1.20 +{ 1.21 + if (i === 8) 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 < 8; j++) 1.41 + { 1.42 + if (j === 8) 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 < 8; k++) 1.62 + { 1.63 + if (k === 8) 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 * 64 + j * 8 + k); 1.85 + }); 1.86 + } 1.87 + } 1.88 +} 1.89 + 1.90 +// Off-by-one check: '/' immediately precedes '0'. 1.91 +assertEq(0o110/2, 36); 1.92 +assertEq(0O644/2, 210); 1.93 + 1.94 +function strict() 1.95 +{ 1.96 + "use strict"; 1.97 + return 0o755; 1.98 +} 1.99 +assertEq(strict(), 7 * 64 + 5 * 8 + 5); 1.100 + 1.101 +/******************************************************************************/ 1.102 + 1.103 +if (typeof reportCompare === "function") 1.104 + reportCompare(true, true); 1.105 + 1.106 +print("Tests complete");