summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/cpp/examples/pluralrules/test.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /intl/icu_capi/cpp/examples/pluralrules/test.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu_capi/cpp/examples/pluralrules/test.cpp')
-rw-r--r--intl/icu_capi/cpp/examples/pluralrules/test.cpp38
1 files changed, 38 insertions, 0 deletions
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 <iostream>
+
+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<int32_t>(cat)
+ << " (should be " << static_cast<int32_t>(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<int32_t>(cat)
+ << " (should be " << static_cast<int32_t>(ICU4XPluralCategory::Many) << ")"
+ << std::endl;
+ if (cat != ICU4XPluralCategory::Many) {
+ return 1;
+ }
+ return 0;
+}