• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function checkSyntaxError (str) {
17  try {
18    eval(str);
19    assert(false);
20  } catch (e) {
21    assert(e instanceof SyntaxError);
22  }
23}
24
25// Test with invalid literals
26checkSyntaxError("0c");
27checkSyntaxError("0b");
28checkSyntaxError("0b0123456");
29checkSyntaxError("0b2");
30
31checkSyntaxError("0C");
32checkSyntaxError("0B");
33checkSyntaxError("0B2");
34
35checkSyntaxError("000b01010101");
36checkSyntaxError("010b01010101");
37checkSyntaxError("11 0b01010101");
38
39// Test with valid literals
40assert(0b111 === 7);
41assert(0b111110111 === 503);
42assert(0b111101010101 === 3925);
43assert(0b00000000000001 === 1);
44assert(0b00000000000000 === 0);
45assert(0b1101001 === parseInt ("1101001", 2));
46
47assert(0B111 === 7);
48assert(0B111110111 === 503);
49assert(0B111101010101 === 3925);
50assert(0B00000000000001 === 1);
51assert(0B00000000000000 === 0);
52assert(0B1101001 === parseInt ("1101001", 2));
53