From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- intl/icu_capi/js/package/test/data-providers.mjs | 19 +++++++++++++ .../js/package/test/fixed-decimal-format.mjs | 32 ++++++++++++++++++++++ intl/icu_capi/js/package/test/fixed-decimal.mjs | 27 ++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 intl/icu_capi/js/package/test/data-providers.mjs create mode 100644 intl/icu_capi/js/package/test/fixed-decimal-format.mjs create mode 100644 intl/icu_capi/js/package/test/fixed-decimal.mjs (limited to 'intl/icu_capi/js/package/test') diff --git a/intl/icu_capi/js/package/test/data-providers.mjs b/intl/icu_capi/js/package/test/data-providers.mjs new file mode 100644 index 0000000000..9d1ba68350 --- /dev/null +++ b/intl/icu_capi/js/package/test/data-providers.mjs @@ -0,0 +1,19 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +import test from 'ava'; + +import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter } from "../index.js" + +test("use create_compiled to format a simple decimal", async t => { + const locale = ICU4XLocale.create_from_string("bn"); + const provider = ICU4XDataProvider.create_compiled(); + + const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); + + const decimal = ICU4XFixedDecimal.create_from_i32(1234); + decimal.multiply_pow10(-2); + + t.is(format.format(decimal), "১২.৩৪"); +}); diff --git a/intl/icu_capi/js/package/test/fixed-decimal-format.mjs b/intl/icu_capi/js/package/test/fixed-decimal-format.mjs new file mode 100644 index 0000000000..f49a0494cf --- /dev/null +++ b/intl/icu_capi/js/package/test/fixed-decimal-format.mjs @@ -0,0 +1,32 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +import test from 'ava'; + +import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter } from "../index.js" + +const locale = ICU4XLocale.create_from_string("bn"); +const provider = ICU4XDataProvider.create_compiled(); +const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); + +test("format a simple decimal", t => { + const decimal = ICU4XFixedDecimal.create_from_i32(1234); + decimal.multiply_pow10(-2); + + t.is(format.format(decimal), "১২.৩৪"); +}); + +test("format a long decimal", t => { + const decimal = ICU4XFixedDecimal.create_from_i32(1000007); + + t.is(format.format(decimal), "১০,০০,০০৭"); +}); + +test("format a negated, scaled decimal", t => { + const decimal = ICU4XFixedDecimal.create_from_i32(1000007); + decimal.multiply_pow10(2); + decimal.set_sign("Negative"); + + t.is(format.format(decimal), "-১০,০০,০০,৭০০"); +}); diff --git a/intl/icu_capi/js/package/test/fixed-decimal.mjs b/intl/icu_capi/js/package/test/fixed-decimal.mjs new file mode 100644 index 0000000000..1295d47c0e --- /dev/null +++ b/intl/icu_capi/js/package/test/fixed-decimal.mjs @@ -0,0 +1,27 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +import test from 'ava'; + +import { ICU4XFixedDecimal } from "../lib/index.js" + +test("convert a simple decimal to a string", t => { + const decimal = ICU4XFixedDecimal.create_from_i64(1234n); + + t.is(decimal.to_string(), "1234"); +}); + +test("multiply a decimal by a power of 10", t => { + const decimal = ICU4XFixedDecimal.create_from_i32(1234); + decimal.multiply_pow10(-2); + + t.is(decimal.to_string(), "12.34"); +}); + +test("negate a decimal", t => { + const decimal = ICU4XFixedDecimal.create_from_i32(1234); + decimal.set_sign("Negative"); + + t.is(decimal.to_string(), "-1234"); +}); -- cgit v1.2.3