Skip to content
Snippets Groups Projects
Commit c273e302 authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for BinaryIntegerLiterals

parent a1437652
No related branches found
No related tags found
No related merge requests found
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.1.1.1
description: Invalid binary literals yield NaN
info: >
BinaryIntegerLiteral ::
0b BinaryDigits
0B BinaryDigits
BinaryDigits ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigit :: one of
0 1
---*/
assert.sameValue(Number('0b2'), NaN, 'invalid digit');
assert.sameValue(Number('00b0'), NaN, 'leading zero');
assert.sameValue(Number('0b'), NaN, 'omitted digits');
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.1.1.1
description: Mathematical value of valid binary integer literals
info: >
20.1.1.1 Number ( [ value ] )
When Number is called with argument number, the following steps are taken:
1. If no arguments were passed to this function invocation, let n be +0.
2. Else, let n be ToNumber(value).
[...]
7.1.3.1 ToNumber Applied to the String Type
All grammar symbols not explicitly defined above have the definitions used
in the Lexical Grammar for numeric literals (11.8.3)
[...]
The MV of BinaryIntegerLiteral :: 0b BinaryDigits is the MV of
BinaryDigits.
The MV of BinaryIntegerLiteral :: 0B BinaryDigits is the MV of
BinaryDigits.
The MV of BinaryDigits :: BinaryDigit is the MV of BinaryDigit.
The MV of BinaryDigits :: BinaryDigits BinaryDigit is (the MV of
BinaryDigits × 2) plus the MV of BinaryDigit.
---*/
assert.sameValue(Number('0b0'), 0, 'lower-case head');
assert.sameValue(Number('0B0'), 0, 'upper-case head');
assert.sameValue(Number('0b00'), 0, 'lower-case head with leading zeros');
assert.sameValue(Number('0B00'), 0, 'upper-case head with leading zeros');
assert.sameValue(Number('0b1'), 1, 'lower-case head');
assert.sameValue(Number('0B1'), 1, 'upper-case head');
assert.sameValue(Number('0b01'), 1, 'lower-case head with leading zeros');
assert.sameValue(Number('0B01'), 1, 'upper-case head with leading zeros');
assert.sameValue(Number('0b10'), 2, 'lower-case head');
assert.sameValue(Number('0B10'), 2, 'upper-case head');
assert.sameValue(Number('0b010'), 2, 'lower-case head with leading zeros');
assert.sameValue(Number('0B010'), 2, 'upper-case head with leading zeros');
assert.sameValue(Number('0b11'), 3, 'lower-case head');
assert.sameValue(Number('0B11'), 3, 'upper-case head');
assert.sameValue(Number('0b011'), 3, 'lower-case head with leading zeros');
assert.sameValue(Number('0B011'), 3, 'upper-case head with leading zeros');
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 11.8.3
description: Binary-integer-literal-like sequence containing an invalid digit
info: >
BinaryIntegerLiteral ::
0b BinaryDigits
0B BinaryDigits
BinaryDigits ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigit :: one of
0 1
negative: SyntaxError
---*/
0b2;
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 11.8.3
description: Binary-integer-literal-like sequence with a leading 0
info: >
BinaryIntegerLiteral ::
0b BinaryDigits
0B BinaryDigits
BinaryDigits ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigit :: one of
0 1
negative: SyntaxError
---*/
00b0;
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 11.8.3
description: Binary-integer-literal-like sequence without any digits
info: >
BinaryIntegerLiteral ::
0b BinaryDigits
0B BinaryDigits
BinaryDigits ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigit :: one of
0 1
negative: SyntaxError
---*/
0b;
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 11.8.3
description: Binary-integer-literal-like sequence expressed with unicode escape sequence
info: >
BinaryIntegerLiteral ::
0b BinaryDigits
0B BinaryDigits
BinaryDigits ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigit :: one of
0 1
negative: SyntaxError
---*/
0\u00620;
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 11.8.3.1
description: Mathematical value of valid binary integer literals
info: >
The MV of BinaryIntegerLiteral :: 0b BinaryDigits is the MV of
BinaryDigits.
The MV of BinaryIntegerLiteral :: 0B BinaryDigits is the MV of
BinaryDigits.
The MV of BinaryDigits :: BinaryDigit is the MV of BinaryDigit.
The MV of BinaryDigits :: BinaryDigits BinaryDigit is (the MV of
BinaryDigits × 2) plus the MV of BinaryDigit.
---*/
assert.sameValue(0b0, 0, 'lower-case head');
assert.sameValue(0B0, 0, 'upper-case head');
assert.sameValue(0b00, 0, 'lower-case head with leading zeros');
assert.sameValue(0B00, 0, 'upper-case head with leading zeros');
assert.sameValue(0b1, 1, 'lower-case head');
assert.sameValue(0B1, 1, 'upper-case head');
assert.sameValue(0b01, 1, 'lower-case head with leading zeros');
assert.sameValue(0B01, 1, 'upper-case head with leading zeros');
assert.sameValue(0b10, 2, 'lower-case head');
assert.sameValue(0B10, 2, 'upper-case head');
assert.sameValue(0b010, 2, 'lower-case head with leading zeros');
assert.sameValue(0B010, 2, 'upper-case head with leading zeros');
assert.sameValue(0b11, 3, 'lower-case head');
assert.sameValue(0B11, 3, 'upper-case head');
assert.sameValue(0b011, 3, 'lower-case head with leading zeros');
assert.sameValue(0B011, 3, 'upper-case head with leading zeros');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment