v8/test/intl/regress-1336865.js
Frank Tang ba6db33e06 Fix unreachable code under --harmony-intl-number-format-v3
ICU 71 added new enum value UNUM_APPROXIMATELY_SIGN_FIELD
need to map to "approximatelySign"

We also discover a spec bug in
https://github.com/tc39/proposal-intl-numberformat-v3/issues/99

All the parts of formatRangeToParts should have a source "shared" for
the case that start and end are the same or very close.

Bug: chromium:1336865
Change-Id: I89142479989d3d2017d8cb89194db737710c38ed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3717278
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81286}
2022-06-22 02:57:57 +00:00

80 lines
3.2 KiB
JavaScript

// Copyright 2022 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-intl-number-format-v3
let nf = new Intl.NumberFormat();
let actual1 = nf.formatRangeToParts(1, 1);
/*
[{type: "approximatelySign", value: "~", source: "shared"},
{type: "integer", value: "1", source: "shared"}]
*/
assertEquals(2, actual1.length);
assertEquals("approximatelySign", actual1[0].type);
assertEquals("~", actual1[0].value);
assertEquals("shared", actual1[0].source);
assertEquals("integer", actual1[1].type);
assertEquals("1", actual1[1].value);
assertEquals("shared", actual1[1].source);
/*
[{type: "approximatelySign", value: "~", source: "shared"},
{type: "integer", value: "9", source: "shared"},
{type: "group", value: ",", source: "shared"},
{type: "integer", value: "223", source: "shared"},
{type: "group", value: ",", source: "shared"},
{type: "integer", value: "372", source: "shared"},
{type: "group", value: ",", source: "shared"},
{type: "integer", value: "036", source: "shared"},
{type: "group", value: ",", source: "shared"},
{type: "integer", value: "854", source: "shared"},
{type: "group", value: ",", source: "shared"},
{type: "integer", value: "775", source: "shared"},
{type: "group", value: ",, source: "shared""},
{type: "integer", value: "807", source: "shared"}]
*/
let bigint = 12345678901234567890n;
let actual2 = nf.formatRangeToParts(bigint, bigint);
assertEquals(14, actual2.length);
assertEquals("approximatelySign", actual2[0].type);
assertEquals("~", actual2[0].value);
assertEquals("shared", actual2[0].source);
assertEquals("integer", actual2[1].type);
assertEquals("12", actual2[1].value);
assertEquals("shared", actual2[1].source);
assertEquals("group", actual2[2].type);
assertEquals(",", actual2[2].value);
assertEquals("shared", actual2[2].source);
assertEquals("integer", actual2[3].type);
assertEquals("345", actual2[3].value);
assertEquals("shared", actual2[3].source);
assertEquals("group", actual2[4].type);
assertEquals(",", actual2[4].value);
assertEquals("shared", actual2[4].source);
assertEquals("integer", actual2[5].type);
assertEquals("678", actual2[5].value);
assertEquals("shared", actual2[5].source);
assertEquals("group", actual2[6].type);
assertEquals(",", actual2[6].value);
assertEquals("shared", actual2[6].source);
assertEquals("integer", actual2[7].type);
assertEquals("901", actual2[7].value);
assertEquals("shared", actual2[7].source);
assertEquals("group", actual2[8].type);
assertEquals(",", actual2[8].value);
assertEquals("shared", actual2[8].source);
assertEquals("integer", actual2[9].type);
assertEquals("234", actual2[9].value);
assertEquals("shared", actual2[9].source);
assertEquals("group", actual2[10].type);
assertEquals(",", actual2[10].value);
assertEquals("shared", actual2[10].source);
assertEquals("integer", actual2[11].type);
assertEquals("567", actual2[11].value);
assertEquals("shared", actual2[11].source);
assertEquals("group", actual2[12].type);
assertEquals(",", actual2[12].value);
assertEquals("shared", actual2[12].source);
assertEquals("integer", actual2[13].type);
assertEquals("890", actual2[13].value);
assertEquals("shared", actual2[13].source);