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/cpp/examples/pluralrules/test.cpp | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 intl/icu_capi/cpp/examples/pluralrules/test.cpp (limited to 'intl/icu_capi/cpp/examples/pluralrules/test.cpp') diff --git a/intl/icu_capi/cpp/examples/pluralrules/test.cpp b/intl/icu_capi/cpp/examples/pluralrules/test.cpp new file mode 100644 index 0000000000..254e96ecef --- /dev/null +++ b/intl/icu_capi/cpp/examples/pluralrules/test.cpp @@ -0,0 +1,38 @@ +// 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 ). + +#include "../../include/ICU4XPluralRules.hpp" +#include "../../include/ICU4XLogger.hpp" + +#include + +const std::string_view path = "../../../../../provider/datagen/tests/data/json/"; + +int main() { + ICU4XLogger::init_simple_logger(); + ICU4XLocale locale = ICU4XLocale::create_from_string("ar").ok().value(); + std::cout << "Running test for locale " << locale.to_string().ok().value() << std::endl; + ICU4XDataProvider dp = ICU4XDataProvider::create_fs(path).ok().value(); + ICU4XPluralRules pr = ICU4XPluralRules::create_cardinal(dp, locale).ok().value(); + + ICU4XPluralOperands op = ICU4XPluralOperands::create_from_string("3").ok().value(); + ICU4XPluralCategory cat = pr.category_for(op); + + std::cout << "Category is " << static_cast(cat) + << " (should be " << static_cast(ICU4XPluralCategory::Few) << ")" + << std::endl; + if (cat != ICU4XPluralCategory::Few) { + return 1; + } + + op = ICU4XPluralOperands::create_from_string("1011.0").ok().value(); + cat = pr.category_for(op); + std::cout << "Category is " << static_cast(cat) + << " (should be " << static_cast(ICU4XPluralCategory::Many) << ")" + << std::endl; + if (cat != ICU4XPluralCategory::Many) { + return 1; + } + return 0; +} -- cgit v1.2.3