Skip to content

Commit

Permalink
Merge branch 'unicode-org:main' into fsync_for_file_output
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly authored Sep 18, 2024
2 parents b119fd2 + f89ea86 commit 5cc9f73
Show file tree
Hide file tree
Showing 91 changed files with 12,668 additions and 796 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/run-nodejs.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ logrotate.state

# Maven
dependency-reduced-pom.xml

# Dart
executors/dart/.dart_tool/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,6 @@ package was delivered in October, 2022.

Copyright © 2022-2024 Unicode, Inc. Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the United States and other countries.

The project is released under [LICENSE](./LICENSE).

A CLA is required to contribute to this project - please refer to the [CONTRIBUTING.md](https://github.com/unicode-org/.github/blob/main/.github/CONTRIBUTING.md) file (or start a Pull Request) for more information.

The contents of this repository are governed by the Unicode [Terms of Use](https://www.unicode.org/copyright.html) and are released under [LICENSE](./LICENSE).
3 changes: 2 additions & 1 deletion executors/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
TARGET=executor

# All object files (C or C++)
OBJECTS=main.o coll.o datetime_fmt.o langnames.o likely_subtags.o list_fmt.o number_fmt.o plural_rules.o

OBJECTS=main.o coll.o datetime_fmt.o localedisplaynames.o likely_subtags.o list_fmt.o message_fmt2.o number_fmt.o plural_rules.o relativedatetime_fmt.o util.o

#### rules
# Load in standard makefile definitions
Expand Down
151 changes: 48 additions & 103 deletions executors/cpp/coll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <iostream>
#include <string>

#include "./util.h"

using std::cout;
using std::endl;
using std::string;
Expand All @@ -40,6 +42,8 @@ using icu::RuleBasedCollator;

const char error_message[] = "error";

bool debug = false;

/**
* TestCollator -- process JSON inputs, run comparator, return result
*/
Expand Down Expand Up @@ -124,43 +128,28 @@ const string TestCollator(json_object *json_in) {
json_object *return_json = json_object_new_object();
json_object_object_add(return_json, "label", label_obj);

bool no_error = true;
int uni_result;
// Create a C++ collator and try it.

Collator *uni_coll = nullptr;
RuleBasedCollator *rb_coll = nullptr;

if (rules_string != "") {
char uni_rules_out[1000] = "";
uni_rules.extract(uni_rules_out, 1000, nullptr, status); // ignore length
string uni_rules_string;
// TODO: Check if this is needed.
uni_rules.toUTF8String(uni_rules_string);

// Make sure normalization is consistent
rb_coll = new RuleBasedCollator(uni_rules, UCOL_ON, status);
if (U_FAILURE(status)) {
test_result = error_message;
// TODO: report the error in creating the instance
cout << "# Error in making RuleBasedCollator: " <<
label_string << " : " << test_result << endl;

json_object_object_add(
return_json,
"error", json_object_new_string("create rule based collator"));
no_error = false;
if (check_icu_error(status, return_json, "create RuleBasedCollator")) {
return json_object_to_json_string(return_json);
}

uni_result = rb_coll->compare(us1, us2, status);
if (U_FAILURE(status)) {
test_result = error_message;

json_object_object_add(
return_json,
"error", json_object_new_string("error in rb_coll->compare"));
no_error = false;
cout << "# Error in rb_coll->compare: " <<
label_string << " : " <<
test_result << endl;
if (check_icu_error(status, return_json, "rb_coll->compare")) {
return json_object_to_json_string(return_json);
}

// Don't need this anymore.
delete rb_coll;
} else {
Expand All @@ -171,29 +160,16 @@ const string TestCollator(json_object *json_in) {
uni_coll = Collator::createInstance(Locale(locale_string), status);
}

if (U_FAILURE(status)) {
test_result = error_message;
json_object_object_add(
return_json,
"error", json_object_new_string("error creating collator instance"));
no_error = false;
cout << "# Error in createInstance: " <<
label_string << " : " <<
test_result << endl;
if (check_icu_error(
status, return_json, "create collator instance")) {
return json_object_to_json_string(return_json);
}

// Make sure normalization is consistent
uni_coll->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
if (U_FAILURE(status)) {
test_result = error_message;
json_object_object_add(
return_json,
"error",
json_object_new_string("error setting normalization to UCOL_ON"));
no_error = false;
cout << "# Error in setAttribute: " <<
label_string << " : " <<
test_result << endl;
if (check_icu_error(
status, return_json, "error setting normalization to UCOL_ON")) {
return json_object_to_json_string(return_json);
}

if (strength_obj) {
Expand All @@ -204,89 +180,58 @@ const string TestCollator(json_object *json_in) {
const bool ignore_punctuation_bool = json_object_get_boolean(ignore_obj);
if (ignore_punctuation_bool) {
uni_coll->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status);
if (U_FAILURE(status)) {
test_result = error_message;
json_object_object_add(
return_json,
"error", json_object_new_string("error setAttribute"));
no_error = false;
cout << "# Error in setAttribute: " <<
label_string << " : " <<
test_result << endl;
if (check_icu_error(
status, return_json,
"set UCOL_ALTERNATE_HANDLING to UCOL_SHIFTED")) {
return json_object_to_json_string(return_json);
}
}
}

// Just to check the result.
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return
if (check_icu_error(
status, return_json,
"getet UCOL_ALTERNATE_HANDLING")) {
return json_object_to_json_string(return_json);
}

// Perform the string comparison
uni_result = uni_coll->compare(us1, us2, status);
if (U_FAILURE(status)) {
json_object_object_add(
return_json,
"error", json_object_new_string("error in uni_coll_compare"));
no_error = false;
cout << "## Error in uni_coll->compare: " <<
label_string << " : " <<
error_message << endl;
if (check_icu_error( status, return_json, "uni_coll_compare")) {
return json_object_to_json_string(return_json);
}

if (uni_coll) {
uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore result
}
delete uni_coll;
if (check_icu_error( status, return_json, "uni_coll->getATTRIBUTE")) {
return json_object_to_json_string(return_json);
}
}

if (no_error) {
if (uni_result == UCOL_GREATER) {
coll_result = false;

coll_result = (uni_result != UCOL_GREATER);
if (!coll_result) {
// Test did not succeed!
if (debug) {
cout << "# UNI_RESULT: " << label_string << " " << uni_result <<
" s1: " << string1 << " s2: " << string2 << endl;

// Check unescaped versions.
char char_out1[1000] = "";
char char_out2[1000] = "";
us1.extract(char_out1, 1000, nullptr, status); // ignore result
if (U_FAILURE(status)) {
test_result = error_message;
json_object_object_add(
return_json,
"error", json_object_new_string("error extracting us1"));
cout << "# Error in us1.extract: " <<
label_string << " : " <<
test_result << endl;
}

us2.extract(char_out2, 1000, nullptr, status); // ignore result
if (U_FAILURE(status)) {
test_result = error_message;
// TODO: report the error in creating the instance
test_result = error_message;
json_object_object_add(
return_json,
"error", json_object_new_string("error extracting us2"));
cout << "# Error in us2.extract: " <<
label_string << " : " <<
test_result << endl;
}

// Include data compared in the failing test
json_object_object_add(
return_json, "s1", json_object_new_string(string1.c_str()));
json_object_object_add(
return_json, "s2", json_object_new_string(string2.c_str()));

// Record the actual returned value
json_object_object_add(
return_json, "compare", json_object_new_int64(uni_result));
} else {
coll_result = true;
}

// Include data compared in the failing test
json_object_object_add(
return_json, "result", json_object_new_boolean(coll_result));
return_json, "s1", json_object_new_string(string1.c_str()));
json_object_object_add(
return_json, "s2", json_object_new_string(string2.c_str()));

// Record the actual returned value
json_object_object_add(
return_json, "compare", json_object_new_int64(uni_result));
}

json_object_object_add(
return_json, "result", json_object_new_boolean(coll_result));

return json_object_to_json_string(return_json);
}
49 changes: 14 additions & 35 deletions executors/cpp/datetime_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <iostream>
#include <string>
#include <regex>
#include <cstring>

#include "unicode/utypes.h"
Expand All @@ -21,6 +20,8 @@

#include "unicode/uclean.h"

#include "./util.h"

using icu::Calendar;
using icu::DateFormat;
using icu::Locale;
Expand Down Expand Up @@ -161,11 +162,7 @@ const string TestDatetimeFmt(json_object *json_in) {
display_locale,
status);
}
if (U_FAILURE(status)) {
json_object_object_add(
return_json,
"error",
json_object_new_string("Error in createInstanceForSkeleton"));
if (check_icu_error(status, return_json, "createInstanceForSkeleton")) {
return json_object_to_json_string(return_json);
}
} else {
Expand Down Expand Up @@ -205,7 +202,7 @@ const string TestDatetimeFmt(json_object *json_in) {

// SimpleDateFormat can't parse options or timezone offset
// First, remove options starting with "["
std:size_t pos = input_date_string.find("[");
std::size_t pos = input_date_string.find("[");
if (pos >= 0) {
input_date_string = input_date_string.substr(0, pos);
}
Expand Down Expand Up @@ -238,19 +235,10 @@ const string TestDatetimeFmt(json_object *json_in) {
}

// Get date from the parser if possible.

test_date_time = iso_date_fmt.parse(date_ustring, status);

if (U_FAILURE(status)) {
string error_message = "# iso_date_fmt parse failure: " +
input_date_string + " " +
u_errorName(status);

json_object_object_add(
return_json,
"error",
json_object_new_string(error_message.c_str()));

if (check_icu_error(status,
return_json,
"# iso_date_fmt parse failure" + input_date_string)) {
return json_object_to_json_string(return_json);
}
} else if (input_millis) {
Expand All @@ -265,27 +253,18 @@ const string TestDatetimeFmt(json_object *json_in) {
return json_object_to_json_string(return_json);
}

// The output of the formatting
// The output of the formatting step
UnicodeString formatted_result;

df->format(test_date_time, formatted_result);

// Get the resulting value as a string
char test_result_string[1000] = "";
formatted_result.extract(
test_result_string, 1000, nullptr, status); // ignore return value
string result_string;
formatted_result.toUTF8String(result_string);

if (U_FAILURE(status)) {
json_object_object_add(
return_json,
"error",
json_object_new_string("Failed extracting test result"));
} else {
// Good calls all around. Send the result!
json_object_object_add(return_json,
"result",
json_object_new_string(test_result_string));
}
// Good calls all around. Send the result!
json_object_object_add(return_json,
"result",
json_object_new_string(result_string.c_str()));

return json_object_to_json_string(return_json);
}
Loading

0 comments on commit 5cc9f73

Please sign in to comment.