Skip to content

Commit a9302a9

Browse files
committed
Add test
1 parent 240f87a commit a9302a9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 Google Inc. All rights reserved.
3+
*/
4+
#include "catch2/catch_test_macros.hpp"
5+
6+
#include <inflection/message2/MF2Factory.hpp>
7+
#include <inflection/util/LocaleUtils.hpp>
8+
#include <inflection/npc.hpp>
9+
10+
#include "unicode/locid.h"
11+
#include "unicode/messageformat2.h"
12+
#include "unicode/messageformat2_function_registry.h"
13+
14+
15+
using icu::Locale;
16+
using icu::message2::data_model::FunctionName;
17+
using icu::message2::MFFunctionRegistry;
18+
using icu::message2::MessageFormatter;
19+
20+
21+
MFFunctionRegistry SetupCustomBuilder(UErrorCode& errorCode) {
22+
auto functionName = FunctionName("inflection");
23+
return MFFunctionRegistry::Builder(errorCode)
24+
.adoptFormatter(functionName, inflection::message2::createFormatterFactory(), errorCode)
25+
.adoptSelector(functionName, inflection::message2::createSelectorFactory(), errorCode)
26+
.build();
27+
}
28+
29+
TEST_CASE("MF2Factory#testBasic")
30+
{
31+
UErrorCode errorCode = U_ZERO_ERROR;
32+
auto customRegistry = SetupCustomBuilder(errorCode);
33+
REQUIRE(U_SUCCESS(errorCode));
34+
}
35+
36+
TEST_CASE("MF2Factory#testCreateFormatter")
37+
{
38+
UErrorCode errorCode = U_ZERO_ERROR;
39+
UParseError pe;
40+
MessageFormatter mf = MessageFormatter::Builder(errorCode)
41+
.setFunctionRegistry(SetupCustomBuilder(errorCode))
42+
.setLocale(Locale::forLanguageTag("es-MX", errorCode))
43+
.setPattern("Foo {$name :inflection hello=world definiteness=definite number=plural gender=feminine} Bar", pe, errorCode)
44+
.build(errorCode);
45+
REQUIRE(U_SUCCESS(errorCode));
46+
}

0 commit comments

Comments
 (0)