Skip to content

Commit

Permalink
Merge branch 'unicode-org:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly authored Jan 26, 2024
2 parents 0af99f4 + 53f4fdf commit 0b11e93
Show file tree
Hide file tree
Showing 29 changed files with 1,359 additions and 608 deletions.
8 changes: 3 additions & 5 deletions executors/cpp/coll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const string test_collator(json_object *json_in) {
// Allow for different levels or types of comparison.
json_object *compare_type = json_object_object_get(json_in, "compare_type");
if (compare_type) {
// TODO: Apply this in tests.
const char *comparison_type = json_object_get_string(compare_type);
}

Expand All @@ -135,8 +136,7 @@ const string test_collator(json_object *json_in) {
if (rules_string != "") {
char uni_rules_out[1000] = "";
int32_t rule_chars_out = uni_rules.extract(uni_rules_out, 1000, nullptr, status);
cout << "# RULES string: " << rules_string << endl;
// !!! rb_coll = new RuleBasedCollator(uni_rules, strength_type, status);

rb_coll = new RuleBasedCollator(uni_rules, status);
if (U_FAILURE(status)) {
test_result = error_message.c_str();
Expand All @@ -148,7 +148,6 @@ const string test_collator(json_object *json_in) {
no_error = false;
}

// cout << "# Calling rb_coll compare" << endl;
uni_result = rb_coll->compare(us1, us2, status);
if (U_FAILURE(status)) {
test_result = error_message.c_str();
Expand All @@ -164,6 +163,7 @@ const string test_collator(json_object *json_in) {
else {
// Not a rule-based collator.
if (locale_string == "") {

uni_coll = Collator::createInstance(status);
} else {
cout << "# Locale set to " << locale_string << endl;
Expand All @@ -179,8 +179,6 @@ const string test_collator(json_object *json_in) {
}

if (strength_obj) {
// !!!
cout << "# Collator strength = " << strength_string << endl;
uni_coll->setStrength(strength_type);
}

Expand Down
83 changes: 52 additions & 31 deletions executors/cpp/number_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ const string test_numfmt(json_object *json_in) {
UNumberUnitWidth unit_width_setting =
UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW;

NumberingSystem* numbering_system = NumberingSystem::createInstance(displayLocale, status);
NumberingSystem* numbering_system =
NumberingSystem::createInstance(displayLocale, status);

// Check all the options
if (options_obj) {
Expand Down Expand Up @@ -428,14 +429,17 @@ const string test_numfmt(json_object *json_in) {
// Other settings...
// NumberFormatter::with().symbols(DecimalFormatSymbols(Locale("de_CH"), status))

json_object* numbering_system_obj = json_object_object_get(options_obj, "numberingSystem");
json_object* numbering_system_obj = json_object_object_get(options_obj,
"numberingSystem");
if (numbering_system_obj) {
string numbering_system_string = json_object_get_string(numbering_system_obj);
numbering_system = NumberingSystem::createInstanceByName(numbering_system_string.c_str(), status);
numbering_system = NumberingSystem::createInstanceByName(
numbering_system_string.c_str(), status);
}

// Handling decimal point
json_object* decimal_always_obj = json_object_object_get(options_obj, "conformanceDecimalAlways");
json_object* decimal_always_obj =
json_object_object_get(options_obj, "conformanceDecimalAlways");
if (decimal_always_obj) {
string separator_string = json_object_get_string(
decimal_always_obj);
Expand All @@ -456,6 +460,10 @@ const string test_numfmt(json_object *json_in) {
json_object *return_json = json_object_new_object();
json_object_object_add(return_json, "label", label_obj);

int32_t chars_out; // Results of extracting characters from Unicode string
bool no_error = true;
char test_result_string[1000] = "";

string test_result;

// Get the numeric value
Expand All @@ -481,9 +489,9 @@ const string test_numfmt(json_object *json_in) {
}

if (skeleton_obj) {
cout << "# SKELETON " << skeleton_string << endl;
cout << "# LOCALE " << locale_string << endl;
nf = NumberFormatter::forSkeleton(unicode_skeleton_string, status).locale(displayLocale);
// If present, use the skeleton
nf = NumberFormatter::forSkeleton(
unicode_skeleton_string, status).locale(displayLocale);
}
else {
// Use settings to initialize the formatter
Expand All @@ -503,34 +511,47 @@ const string test_numfmt(json_object *json_in) {

if (U_FAILURE(status)) {
test_result = error_message.c_str();
// TODO: report the error in creating the instance
}

UnicodeString number_result;
FormattedNumber fmt_number = nf.formatDouble(input_double, status);
number_result = fmt_number.toString(status);
if (U_FAILURE(status)) {
test_result = error_message.c_str();
// TODO: report the error
const char* error_name = u_errorName(status);
json_object_object_add(return_json,
"error", json_object_new_string("error in constructor"));
json_object_object_add(return_json,
"error_detail", json_object_new_string(error_name));
no_error = false;
}

// Get the resulting value as a string
char test_result_string[1000] = "";
int32_t chars_out = number_result.extract(test_result_string, 1000, nullptr, status);
test_result = test_result_string;
if (no_error) {
UnicodeString number_result;
// Use formatDecimal, passing the string instead of a double.
FormattedNumber fmt_number = nf.formatDecimal(input_string, status);
number_result = fmt_number.toString(status);
if (U_FAILURE(status)) {
const char* error_name = u_errorName(status);
json_object_object_add(return_json,
"error", json_object_new_string("error in toString"));
json_object_object_add(return_json,
"error_detail", json_object_new_string(error_name));
no_error = false;
}

if (U_FAILURE(status)) {
// Report a failure
test_result = error_message.c_str();
json_object_object_add(return_json,
"error", json_object_new_string("langnames extract error"));
} else {
// It worked!
json_object_object_add(return_json,
"result",
json_object_new_string(test_result.c_str()));
// Get the resulting value as a string
chars_out = number_result.extract(test_result_string, 1000, nullptr, status);
test_result = test_result_string;

if (U_FAILURE(status)) {
// Report a failure
const char* error_name = u_errorName(status);
json_object_object_add(
return_json, "error", json_object_new_string("error in string extract"));
json_object_object_add(
return_json, "error_detail", json_object_new_string(error_name));
no_error = false;
} else {
// It worked!
json_object_object_add(return_json,
"result",
json_object_new_string(test_result.c_str()));
}
}

// To see what was actually used.
UnicodeString u_skeleton_out = nf.toSkeleton(status);
chars_out = u_skeleton_out.extract(test_result_string, 1000, nullptr, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@ public static void printResponseString(String responseString) {
System.out.println(responseString);
}

public static io.lacuna.bifurcan.Map<String,String> parseInputLine(String inputLine) {
TypeToken<Map<String, String>> mapType = new TypeToken<Map<String, String>>(){};
Map<String,String> parsedInputJavaMap = ExecutorUtils.GSON.fromJson(inputLine, mapType);
public static io.lacuna.bifurcan.Map<String,Object> parseInputLine(String inputLine) {
Map<String,Object> parsedInputJavaMap = stringMapFromString(inputLine);

io.lacuna.bifurcan.Map<String,String> parsedInputPersistentMap =
io.lacuna.bifurcan.Map<String,Object> parsedInputPersistentMap =
io.lacuna.bifurcan.Map.from(parsedInputJavaMap);

return parsedInputPersistentMap;
}

public static String formatAsJson(io.lacuna.bifurcan.IMap<String,String> mapData) {
java.util.Map<String,String> jMap = new HashMap<>();
for (Iterator<IEntry<String, String>> it = mapData.stream().iterator(); it.hasNext(); ) {
IEntry<String, String> entry = it.next();
public static String formatAsJson(io.lacuna.bifurcan.IMap<String,Object> mapData) {
java.util.Map<String,Object> jMap = new HashMap<>();
for (Iterator<IEntry<String, Object>> it = mapData.stream().iterator(); it.hasNext(); ) {
IEntry<String, Object> entry = it.next();
jMap.put(entry.key(), entry.value());
}
return GSON.toJson(jMap);
}

public static Map<String,Object> stringMapFromString(String s) {
TypeToken<Map<String, Object>> mapType = new TypeToken<Map<String, Object>>(){};
Map<String,Object> parsedInputJavaMap = ExecutorUtils.GSON.fromJson(s, mapType);

return parsedInputJavaMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import com.google.gson.reflect.TypeToken;
import com.ibm.icu.impl.locale.XCldrStub.ImmutableMap;
import com.ibm.icu.number.NumberFormatter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.unicode.conformance.testtype.ITestType;
import org.unicode.conformance.testtype.ITestTypeOutputJson;
import org.unicode.conformance.testtype.collator.CollatorTester;
import org.unicode.conformance.testtype.langnames.LangNamesTester;
import org.unicode.conformance.testtype.likelysubtags.LikelySubtagsTester;
import org.unicode.conformance.testtype.numberformatter.NumberFormatterTester;

/**
* Hello world!
Expand Down Expand Up @@ -97,37 +100,49 @@ public static String getVersionResponse() {

public static String getTestCaseResponse(String inputLine) throws Exception {

io.lacuna.bifurcan.Map<String,String> parsedInputPersistentMap =
io.lacuna.bifurcan.Map<String,Object> parsedInputPersistentMap =
ExecutorUtils.parseInputLine(inputLine);

Optional<String> testTypeOpt = parsedInputPersistentMap.get("test_type");
Optional<Object> testTypeOpt = parsedInputPersistentMap.get("test_type");

if (!testTypeOpt.isPresent()) {
io.lacuna.bifurcan.IMap<String,String> response =
io.lacuna.bifurcan.IMap<String,Object> response =
parsedInputPersistentMap
.put("error", "Error in input")
.put("error_msg", "Error in input found in executor before execution");

return ExecutorUtils.formatAsJson(response);
} else {
String testTypeStr = testTypeOpt.get();
String testTypeStr = (String) testTypeOpt.get();
ITestType testType;
if (testTypeStr.equals("collation_short")) {
testType = CollatorTester.INSTANCE;
} else if (testTypeStr.equals("lang_names")) {
testType = LangNamesTester.INSTANCE;
} else if (testTypeStr.equals("likely_subtags")) {
testType = LikelySubtagsTester.INSTANCE;
} else if (testTypeStr.equals("number_fmt")) {
testType = NumberFormatterTester.INSTANCE;
} else {
io.lacuna.bifurcan.IMap<String,String> response =
io.lacuna.bifurcan.IMap<String,Object> response =
parsedInputPersistentMap
.put("error", "Error in input")
.put("error_msg", "Error in input found in executor before execution");

return ExecutorUtils.formatAsJson(response);
}

return testType.getFinalOutputFromInput(parsedInputPersistentMap);
try {
return testType.getFinalOutputFromInput(parsedInputPersistentMap);
} catch (Exception e) {
ITestTypeOutputJson defaultOutput = testType.getDefaultOutputJson();
return ExecutorUtils.formatAsJson(
testType.convertOutputToMap(defaultOutput)
.put("label", parsedInputPersistentMap.get("label", null))
.put("error", "Error in input")
.put("error_msg", "Error in handling test case: " + e.getMessage())
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

public interface ITestType {

default io.lacuna.bifurcan.Map<String,String> parseInput(String inputLine) {
default io.lacuna.bifurcan.Map<String,Object> parseInput(String inputLine) {
return ExecutorUtils.parseInputLine(inputLine);
}

ITestTypeInputJson inputMapToJson(io.lacuna.bifurcan.Map<String,String> inputMapData);
ITestTypeInputJson inputMapToJson(io.lacuna.bifurcan.Map<String,Object> inputMapData);

default ITestTypeInputJson parseInputJson(String inputLine) {
io.lacuna.bifurcan.Map<String,String> inputMapData =
io.lacuna.bifurcan.Map<String,Object> inputMapData =
parseInput(inputLine);
ITestTypeInputJson inputJson = inputMapToJson(inputMapData);

Expand All @@ -20,20 +20,24 @@ default ITestTypeInputJson parseInputJson(String inputLine) {

ITestTypeOutputJson execute(ITestTypeInputJson inputJson);

ITestTypeOutputJson getDefaultOutputJson();

io.lacuna.bifurcan.IMap<String,Object> convertOutputToMap(ITestTypeOutputJson outputJson);

String formatOutputJson(ITestTypeOutputJson outputJson);

default ITestTypeOutputJson getStructuredOutputFromInputStr(String inputLine) {
io.lacuna.bifurcan.Map<String,String> inputMapData = parseInput(inputLine);
io.lacuna.bifurcan.Map<String,Object> inputMapData = parseInput(inputLine);
return getStructuredOutputFromInput(inputMapData);
}

default ITestTypeOutputJson getStructuredOutputFromInput(io.lacuna.bifurcan.Map<String,String> inputMapData) {
default ITestTypeOutputJson getStructuredOutputFromInput(io.lacuna.bifurcan.Map<String,Object> inputMapData) {
ITestTypeInputJson inputJson = inputMapToJson(inputMapData);
ITestTypeOutputJson outputJson = execute(inputJson);
return outputJson;
}

default String getFinalOutputFromInput(io.lacuna.bifurcan.Map<String,String> inputMapData) throws Exception {
default String getFinalOutputFromInput(io.lacuna.bifurcan.Map<String,Object> inputMapData) throws Exception {
ITestTypeOutputJson outputJson = getStructuredOutputFromInput(inputMapData);
String formattedOutput = formatOutputJson(outputJson);
return formattedOutput;
Expand Down
Loading

0 comments on commit 0b11e93

Please sign in to comment.