1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
// © 2024 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef _TESTMESSAGEFORMAT2
#define _TESTMESSAGEFORMAT2
#include "unicode/rep.h"
#include "unicode/utypes.h"
#if !UCONFIG_NO_NORMALIZATION
#if !UCONFIG_NO_FORMATTING
#if !UCONFIG_NO_MF2
#include "messageformat2test_utils.h"
#include "unicode/unistr.h"
#include "unicode/messageformat2_formattable.h"
#include "unicode/parseerr.h"
#include "intltest.h"
/**
* TestMessageFormat2 tests MessageFormat2
*/
struct TestResult {
const UnicodeString pattern;
const UnicodeString output;
};
struct TestResultError {
const UnicodeString pattern;
const UnicodeString output;
UErrorCode expected;
};
class TestMessageFormat2: public IntlTest {
public:
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ) override;
/**
* test MessageFormat2 with various given patterns
**/
void dataDrivenTests(void);
void testAPICustomFunctions(void);
// Test custom functions
void testCustomFunctions(void);
// Test the data model API
void testDataModelAPI(void);
// Test the formatting API
void testFormatterAPI(void);
void testAPI(void);
void testAPISimple(void);
private:
void jsonTestsFromFiles(IcuTestErrorCode&);
// Built-in function testing
void testNumbers(IcuTestErrorCode&);
// Custom function testing
void testPersonFormatter(IcuTestErrorCode&);
void testCustomFunctionsComplexMessage(IcuTestErrorCode&);
void testGrammarCasesFormatter(IcuTestErrorCode&);
void testListFormatter(IcuTestErrorCode&);
void testMessageRefFormatter(IcuTestErrorCode&);
// Feature tests
void testEmptyMessage(message2::TestCase::Builder&, IcuTestErrorCode&);
void testPlainText(message2::TestCase::Builder&, IcuTestErrorCode&);
void testPlaceholders(message2::TestCase::Builder&, IcuTestErrorCode&);
void testArgumentMissing(message2::TestCase::Builder&, IcuTestErrorCode&);
void testDefaultLocale(message2::TestCase::Builder&, IcuTestErrorCode&);
void testSpecialPluralWithDecimals(message2::TestCase::Builder&, IcuTestErrorCode&);
void testDefaultFunctionAndOptions(message2::TestCase::Builder&, IcuTestErrorCode&);
void testSimpleSelection(message2::TestCase::Builder&, IcuTestErrorCode&);
void testComplexSelection(message2::TestCase::Builder&, IcuTestErrorCode&);
void testSimpleLocalVariable(message2::TestCase::Builder&, IcuTestErrorCode&);
void testLocalVariableWithSelect(message2::TestCase::Builder&, IcuTestErrorCode&);
void testDateFormat(message2::TestCase::Builder&, IcuTestErrorCode&);
void testPlural(message2::TestCase::Builder&, IcuTestErrorCode&);
void testPluralOrdinal(message2::TestCase::Builder&, IcuTestErrorCode&);
void testDeclareBeforeUse(message2::TestCase::Builder&, IcuTestErrorCode&);
// MessageFormat 1 tests
void testSample(message2::TestCase::Builder&, IcuTestErrorCode&);
void testStaticFormat(message2::TestCase::Builder&, IcuTestErrorCode&);
void testSimpleFormat(message2::TestCase::Builder&, IcuTestErrorCode&);
void testSelectFormatToPattern(message2::TestCase::Builder&, IcuTestErrorCode&);
void testMessageFormatDateTimeSkeleton(message2::TestCase::Builder&, IcuTestErrorCode&);
void testMf1Behavior(message2::TestCase::Builder&, IcuTestErrorCode&);
void testHighLoneSurrogate(void);
void testLowLoneSurrogate(void);
void testLoneSurrogateInQuotedLiteral(void);
}; // class TestMessageFormat2
U_NAMESPACE_BEGIN
namespace message2 {
// Custom function classes
class PersonNameFormatterFactory : public FormatterFactory {
public:
Formatter* createFormatter(const Locale&, UErrorCode&) override;
};
class Person : public FormattableObject {
public:
UnicodeString title;
UnicodeString firstName;
UnicodeString lastName;
Person(UnicodeString t, UnicodeString f, UnicodeString l) : title(t), firstName(f), lastName(l), tagName("person") {}
~Person();
const UnicodeString& tag() const override { return tagName; }
private:
const UnicodeString tagName;
};
class PersonNameFormatter : public Formatter {
public:
FormattedPlaceholder format(FormattedPlaceholder&&, FunctionOptions&& opts, UErrorCode& errorCode) const override;
};
class FormattableProperties : public FormattableObject {
public:
const UnicodeString& tag() const override { return tagName; }
FormattableProperties(Hashtable* hash) : properties(hash), tagName("properties") {
U_ASSERT(hash != nullptr);
}
~FormattableProperties();
LocalPointer<Hashtable> properties;
private:
const UnicodeString tagName;
};
class GrammarCasesFormatterFactory : public FormatterFactory {
public:
Formatter* createFormatter(const Locale&, UErrorCode&) override;
};
class GrammarCasesFormatter : public Formatter {
public:
FormattedPlaceholder format(FormattedPlaceholder&&, FunctionOptions&& opts, UErrorCode& errorCode) const override;
static MFFunctionRegistry customRegistry(UErrorCode&);
private:
void getDativeAndGenitive(const UnicodeString&, UnicodeString& result) const;
};
class ListFormatterFactory : public FormatterFactory {
public:
Formatter* createFormatter(const Locale&, UErrorCode&) override;
};
class ListFormatter : public Formatter {
public:
FormattedPlaceholder format(FormattedPlaceholder&&, FunctionOptions&& opts, UErrorCode& errorCode) const override;
static MFFunctionRegistry customRegistry(UErrorCode&);
private:
friend class ListFormatterFactory;
const Locale& locale;
ListFormatter(const Locale& loc) : locale(loc) {}
};
class ResourceManagerFactory : public FormatterFactory {
public:
Formatter* createFormatter(const Locale&, UErrorCode&) override;
};
class ResourceManager : public Formatter {
public:
FormattedPlaceholder format(FormattedPlaceholder&&, FunctionOptions&& opts, UErrorCode& errorCode) const override;
static MFFunctionRegistry customRegistry(UErrorCode&);
static Hashtable* properties(UErrorCode&);
static UnicodeString propertiesAsString(const Hashtable&);
static Hashtable* parseProperties(const UnicodeString&, UErrorCode&);
private:
friend class ResourceManagerFactory;
ResourceManager(const Locale& loc) : locale(loc) {}
const Locale& locale;
};
} // namespace message2
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_MF2 */
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* #if !UCONFIG_NO_NORMALIZATION */
#endif
|