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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:bbd6b641bc4a
1 // Any copyright is dedicated to the Public Domain.
2 // http://creativecommons.org/licenses/publicdomain/
3
4 //-----------------------------------------------------------------------------
5 var BUGNUMBER = 894026;
6 var summary = "Implement ES6 octal literals";
7
8 print(BUGNUMBER + ": " + summary);
9
10 /**************
11 * BEGIN TEST *
12 **************/
13
14 var chars = ['o', 'O'];
15
16 for (var i = 0; i < 8; i++)
17 {
18 if (i === 8)
19 {
20 chars.forEach(function(v)
21 {
22 try
23 {
24 eval('0' + v + i);
25 throw "didn't throw";
26 }
27 catch (e)
28 {
29 assertEq(e instanceof SyntaxError, true,
30 "no syntax error evaluating 0" + v + i + ", " +
31 "got " + e);
32 }
33 });
34 continue;
35 }
36
37 for (var j = 0; j < 8; j++)
38 {
39 if (j === 8)
40 {
41 chars.forEach(function(v)
42 {
43 try
44 {
45 eval('0' + v + i + j);
46 throw "didn't throw";
47 }
48 catch (e)
49 {
50 assertEq(e instanceof SyntaxError, true,
51 "no syntax error evaluating 0" + v + i + j + ", " +
52 "got " + e);
53 }
54 });
55 continue;
56 }
57
58 for (var k = 0; k < 8; k++)
59 {
60 if (k === 8)
61 {
62 chars.forEach(function(v)
63 {
64 try
65 {
66 eval('0' + v + i + j + k);
67 throw "didn't throw";
68 }
69 catch (e)
70 {
71 assertEq(e instanceof SyntaxError, true,
72 "no syntax error evaluating 0" + v + i + j + k + ", " +
73 "got " + e);
74 }
75 });
76 continue;
77 }
78
79 chars.forEach(function(v)
80 {
81 assertEq(eval('0' + v + i + j + k), i * 64 + j * 8 + k);
82 });
83 }
84 }
85 }
86
87 // Off-by-one check: '/' immediately precedes '0'.
88 assertEq(0o110/2, 36);
89 assertEq(0O644/2, 210);
90
91 function strict()
92 {
93 "use strict";
94 return 0o755;
95 }
96 assertEq(strict(), 7 * 64 + 5 * 8 + 5);
97
98 /******************************************************************************/
99
100 if (typeof reportCompare === "function")
101 reportCompare(true, true);
102
103 print("Tests complete");

mercurial