diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.formatRangeToParts.js | 20 |
2 files changed, 25 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index f7879d8491..d955a6fcfd 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Tim Flynn <trflynn89@serenityos.org> + * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -1744,9 +1744,20 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat auto raw_end_result = partition_number_pattern(vm, number_format, move(end)); auto end_result = PatternPartitionWithSource::create_from_parent_list(move(raw_end_result)); - // 5. If xResult is equal to yResult, return FormatApproximately(numberFormat, xResult). - if (start_result == end_result) - return format_approximately(number_format, move(start_result)); + // 5. If xResult is equal to yResult, then + if (start_result == end_result) { + // a. Let appxResult be ? FormatApproximately(numberFormat, xResult). + auto approximate_result = format_approximately(number_format, move(start_result)); + + // b. For each r in appxResult, do + for (auto& result : approximate_result) { + // i. Set r.[[Source]] to "shared". + result.source = "shared"sv; + } + + // c. Return appxResult. + return approximate_result; + } // 6. For each r in xResult, do for (auto& part : start_result) { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.formatRangeToParts.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.formatRangeToParts.js index 3032d6ec7b..6c8271bffb 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.formatRangeToParts.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.formatRangeToParts.js @@ -56,8 +56,8 @@ describe("correct behavior", () => { test("approximately formatting", () => { const en1 = new Intl.NumberFormat("en", { maximumFractionDigits: 0 }); expect(en1.formatRangeToParts(2.9, 3.1)).toEqual([ - { type: "approximatelySign", value: "~", source: "" }, - { type: "integer", value: "3", source: "" }, + { type: "approximatelySign", value: "~", source: "shared" }, + { type: "integer", value: "3", source: "shared" }, ]); const en2 = new Intl.NumberFormat("en", { @@ -66,15 +66,15 @@ describe("correct behavior", () => { maximumFractionDigits: 0, }); expect(en2.formatRangeToParts(2.9, 3.1)).toEqual([ - { type: "approximatelySign", value: "~", source: "" }, - { type: "currency", value: "$", source: "" }, - { type: "integer", value: "3", source: "" }, + { type: "approximatelySign", value: "~", source: "shared" }, + { type: "currency", value: "$", source: "shared" }, + { type: "integer", value: "3", source: "shared" }, ]); const ja1 = new Intl.NumberFormat("ja", { maximumFractionDigits: 0 }); expect(ja1.formatRangeToParts(2.9, 3.1)).toEqual([ - { type: "approximatelySign", value: "約", source: "" }, - { type: "integer", value: "3", source: "" }, + { type: "approximatelySign", value: "約", source: "shared" }, + { type: "integer", value: "3", source: "shared" }, ]); const ja2 = new Intl.NumberFormat("ja", { @@ -83,9 +83,9 @@ describe("correct behavior", () => { maximumFractionDigits: 0, }); expect(ja2.formatRangeToParts(2.9, 3.1)).toEqual([ - { type: "approximatelySign", value: "約", source: "" }, - { type: "currency", value: "¥", source: "" }, - { type: "integer", value: "3", source: "" }, + { type: "approximatelySign", value: "約", source: "shared" }, + { type: "currency", value: "¥", source: "shared" }, + { type: "integer", value: "3", source: "shared" }, ]); }); |