Skip to content

Commit

Permalink
ICU-22707 test normalization quick check properties against ppucd
Browse files Browse the repository at this point in the history
  • Loading branch information
markusicu committed Apr 7, 2024
1 parent 3ac780f commit 41738ec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
64 changes: 40 additions & 24 deletions icu4c/source/test/intltest/ucdtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void UnicodeTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
TESTCASE_AUTO(TestPropertyNames);
TESTCASE_AUTO(TestIDSUnaryOperator);
TESTCASE_AUTO(TestIDCompatMath);
TESTCASE_AUTO(TestBinaryPropertyUsingPpucd);
TESTCASE_AUTO(TestPropertiesUsingPpucd);
TESTCASE_AUTO(TestIDStatus);
TESTCASE_AUTO(TestIDType);
TESTCASE_AUTO_END;
Expand Down Expand Up @@ -1047,8 +1047,8 @@ class BuiltInPropertyNames : public PropertyNames {

U_NAMESPACE_END

void UnicodeTest::TestBinaryPropertyUsingPpucd() {
IcuTestErrorCode errorCode(*this, "TestBinaryPropertyUsingPpucd()");
void UnicodeTest::TestPropertiesUsingPpucd() {
IcuTestErrorCode errorCode(*this, "TestPropertiesUsingPpucd()");

// Initialize PPUCD parsing object using file in repo and using
// property names present in built-in data in ICU
Expand All @@ -1070,15 +1070,27 @@ void UnicodeTest::TestBinaryPropertyUsingPpucd() {
BuiltInPropertyNames builtInPropNames;
ppucd.setPropertyNames(&builtInPropNames);

// Define which binary properties we want to compare
constexpr UProperty propsUnderTest[] = {
UCHAR_IDS_UNARY_OPERATOR,
UCHAR_ID_COMPAT_MATH_START,
UCHAR_ID_COMPAT_MATH_CONTINUE,
};
// Define which properties we want to compare
struct TestProp {
const UProperty prop;
const int32_t value = 1; // binary "Yes"
UnicodeSet set;

// Allocate & initialize UnicodeSets per binary property from PPUCD data
UnicodeSet ppucdPropSets[std::size(propsUnderTest)];
TestProp(UProperty binaryProp) : prop(binaryProp) {}
TestProp(UProperty intProp, int32_t v) : prop(intProp), value(v) {}
bool isBinary() const { return prop < UCHAR_BINARY_LIMIT; }
};
TestProp propsUnderTest[] = {
{ UCHAR_IDS_UNARY_OPERATOR },
{ UCHAR_ID_COMPAT_MATH_START },
{ UCHAR_ID_COMPAT_MATH_CONTINUE },
{ UCHAR_NFD_QUICK_CHECK, UNORM_NO },
{ UCHAR_NFKD_QUICK_CHECK, UNORM_NO },
{ UCHAR_NFC_QUICK_CHECK, UNORM_NO },
{ UCHAR_NFKC_QUICK_CHECK, UNORM_NO },
{ UCHAR_NFC_QUICK_CHECK, UNORM_MAYBE },
{ UCHAR_NFKC_QUICK_CHECK, UNORM_MAYBE },
};

// Iterate through PPUCD file, accumulating each line's data into each UnicodeSet per property
PreparsedUCD::LineType lineType;
Expand All @@ -1087,15 +1099,17 @@ void UnicodeTest::TestBinaryPropertyUsingPpucd() {
if(ppucd.lineHasPropertyValues()) {
const UniProps *lineProps=ppucd.getProps(newValues, errorCode);

for(uint32_t i = 0; i < std::size(propsUnderTest); i++) {
UProperty prop = propsUnderTest[i];
if (!newValues.contains(prop)) {
for (auto &tp : propsUnderTest) {
if (!newValues.contains(tp.prop)) {
continue;
}
if (lineProps->binProps[prop]) {
ppucdPropSets[i].add(lineProps->start, lineProps->end);
bool match = tp.isBinary() ?
lineProps->binProps[tp.prop] :
lineProps->getIntProp(tp.prop) == tp.value;
if (match) {
tp.set.add(lineProps->start, lineProps->end);
} else {
ppucdPropSets[i].remove(lineProps->start, lineProps->end);
tp.set.remove(lineProps->start, lineProps->end);
}
}
}
Expand All @@ -1107,15 +1121,17 @@ void UnicodeTest::TestBinaryPropertyUsingPpucd() {
}

// Assert that the PPUCD data and the ICU data are equivalent for all properties
for(uint32_t i = 0; i < std::size(propsUnderTest); i++) {
for (auto &tp : propsUnderTest) {
UnicodeSet icuPropSet;
UProperty prop = propsUnderTest[i];
icuPropSet.applyIntPropertyValue(prop, 1, errorCode);
std::string msg =
icuPropSet.applyIntPropertyValue(tp.prop, tp.value, errorCode);
std::string msg =
std::string()
+ "ICU & PPUCD versions of property "
+ u_getPropertyName(prop, U_LONG_PROPERTY_NAME);
assertTrue(msg.c_str(), ppucdPropSets[i] == icuPropSet);
+ "ICU & PPUCD versions of "
+ u_getPropertyName(tp.prop, U_LONG_PROPERTY_NAME);
if (!tp.isBinary()) {
msg = msg + "=" + u_getPropertyValueName(tp.prop, tp.value, U_LONG_PROPERTY_NAME);
}
assertTrue(msg.c_str(), tp.set == icuPropSet);
}
}

Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/test/intltest/ucdtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UnicodeTest: public IntlTest {
void TestPropertyNames();
void TestIDSUnaryOperator();
void TestIDCompatMath();
void TestBinaryPropertyUsingPpucd();
void TestPropertiesUsingPpucd();
void TestIDStatus();
void TestIDType();

Expand Down

0 comments on commit 41738ec

Please sign in to comment.