Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Number/string-binary-literal.js

raw
1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 es6id: 20.1.1.1
6 description: Mathematical value of valid binary integer literals
7 info: |
8 20.1.1.1 Number ( [ value ] )
9
10 When Number is called with argument number, the following steps are taken:
11
12 1. If no arguments were passed to this function invocation, let n be +0.
13 2. Else, let n be ToNumber(value).
14
15 [...]
16
17 7.1.3.1 ToNumber Applied to the String Type
18
19 All grammar symbols not explicitly defined above have the definitions used
20 in the Lexical Grammar for numeric literals (11.8.3)
21
22 [...]
23
24 The MV of BinaryIntegerLiteral :: 0b BinaryDigits is the MV of
25 BinaryDigits.
26 The MV of BinaryIntegerLiteral :: 0B BinaryDigits is the MV of
27 BinaryDigits.
28 The MV of BinaryDigits :: BinaryDigit is the MV of BinaryDigit.
29 The MV of BinaryDigits :: BinaryDigits BinaryDigit is (the MV of
30 BinaryDigits × 2) plus the MV of BinaryDigit.
31 ---*/
32
33 assert.sameValue(Number('0b0'), 0, 'lower-case head');
34 assert.sameValue(Number('0B0'), 0, 'upper-case head');
35 assert.sameValue(Number('0b00'), 0, 'lower-case head with leading zeros');
36 assert.sameValue(Number('0B00'), 0, 'upper-case head with leading zeros');
37
38 assert.sameValue(Number('0b1'), 1, 'lower-case head');
39 assert.sameValue(Number('0B1'), 1, 'upper-case head');
40 assert.sameValue(Number('0b01'), 1, 'lower-case head with leading zeros');
41 assert.sameValue(Number('0B01'), 1, 'upper-case head with leading zeros');
42
43 assert.sameValue(Number('0b10'), 2, 'lower-case head');
44 assert.sameValue(Number('0B10'), 2, 'upper-case head');
45 assert.sameValue(Number('0b010'), 2, 'lower-case head with leading zeros');
46 assert.sameValue(Number('0B010'), 2, 'upper-case head with leading zeros');
47
48 assert.sameValue(Number('0b11'), 3, 'lower-case head');
49 assert.sameValue(Number('0B11'), 3, 'upper-case head');
50 assert.sameValue(Number('0b011'), 3, 'lower-case head with leading zeros');
51 assert.sameValue(Number('0B011'), 3, 'upper-case head with leading zeros');