v8/test/mjsunit/harmony/numeric-separator.js
Taketoshi Aono f0946c1b71 Reland proposal-numeric-separator.
Revert "Revert "[parser] Implements proposal-numeric-separator.""

This reverts commit 782f6401ee.

Original CL is https://chromium-review.googlesource.com/c/v8/v8/+/923441

Bug: v8:7317
Change-Id: I6f541c038bad0cff625094ba84aebe582bdeb12f
Reviewed-on: https://chromium-review.googlesource.com/945034
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51749}
2018-03-06 01:25:06 +00:00

69 lines
1.5 KiB
JavaScript

// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-numeric-separator
{
const basic = 1_0_0_0;
assertEquals(basic, 1000);
}
{
const exponent = 1_0e+1;
assertEquals(exponent, 10e+1);
}
{
const exponent2 = 1_0e+1_0;
assertEquals(exponent2, 10e+10);
}
{
const hex = 0xF_F_FF;
assertEquals(hex, 0xFFFF);
}
{
const octal = 0o7_7_7;
assertEquals(octal, 0o777);
}
{
const implicitOctal = 07_7_7;
assertEquals(implicitOctal, 0o777);
}
{
let exception = false;
try {
const code = `"use strict" const implicitOctal = 07_7_7`;
eval(code);
} catch(e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
}
{
const binary = 0b0_1_0_1_0;
assertEquals(binary, 0b01010);
}
{
const leadingZeros = 09_1_3;
assertEquals(leadingZeros, 0913);
}
assertThrows('1_0_0_0_', SyntaxError);
assertThrows('1e_1', SyntaxError);
assertThrows('1e+_1', SyntaxError);
assertThrows('1_e+1', SyntaxError);
assertThrows('1__0', SyntaxError);
assertThrows('0x_1', SyntaxError);
assertThrows('0x1__1', SyntaxError);
assertThrows('0x1_', SyntaxError);
assertThrows('0b_0101', SyntaxError);
assertThrows('0b11_', SyntaxError);
assertThrows('0b1__1', SyntaxError);
assertThrows('0o777_', SyntaxError);
assertThrows('0o_777', SyntaxError);
assertThrows('0o7__77', SyntaxError);
assertThrows('0777_', SyntaxError);
assertThrows('07__77', SyntaxError);