Skip to content

Commit

Permalink
chore(core): Unicode version test
Browse files Browse the repository at this point in the history
- refactor and support >= node version

Fixes: #10183
  • Loading branch information
srl295 committed May 14, 2024
1 parent 9199c71 commit 1023ef2
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions core/tests/unit/ldml/test_unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ std::string get_major(const std::string& ver) {
return ver.substr(start, end - start);
}

std::string get_block_unicode_ver() {
// fetch Blocks.txt
std::ifstream blocks_file(
km::core::path("../../../../resources/standards-data/unicode-character-database/Blocks.txt").native());
assert(blocks_file.good());
std::string block_line;
assert(std::getline(blocks_file, block_line)); // first line
const std::string prefix = "# Blocks-";
assert(block_line.length() > prefix.length());
return block_line.substr(prefix.length());
}

void test_unicode_versions(const nlohmann::json &versions, const nlohmann::json &package) {
std::cout << "== " << __FUNCTION__ << std::endl;

Expand All @@ -79,14 +91,7 @@ void test_unicode_versions(const nlohmann::json &versions, const nlohmann::json
node(versions["/node"_json_pointer].template get<std::string>()),
node_icu(versions["/icu"_json_pointer].template get<std::string>()),
node_engine(package["/engines/node"_json_pointer].template get<std::string>());
// fetch Blocks.txt
std::ifstream blocks_file(km::core::path("../../../../resources/standards-data/unicode-character-database/Blocks.txt").native());
assert(blocks_file.good());
std::string block_line;
assert(std::getline(blocks_file, block_line)); // first line
const std::string prefix = "# Blocks-";
assert(block_line.length() > prefix.length());
const auto block_unicode_ver = block_line.substr(prefix.length());
const auto block_unicode_ver = get_block_unicode_ver();

// calculations
auto block_ver_major = get_major(block_unicode_ver);
Expand All @@ -106,13 +111,17 @@ void test_unicode_versions(const nlohmann::json &versions, const nlohmann::json
SHOW_VAR(block_unicode_ver);
#undef SHOW_VAR

assert_basic_equal(node_major, node_engine_major);
// allow the Node.js version to be >= required
auto node_engine_num = std::atoi(node_engine_major.c_str());
auto node_num = std::atoi(node_major.c_str());
assert(node_num >= node_engine_num);

// the cxx_icu can come from the Ubuntu environment, so do not depend on it
// for now.
//assert_basic_equal(node_icu_unicode_major, cxx_icu_unicode_major);
assert_basic_equal(node_icu_unicode_major, block_ver_major);

// seems less important if the Unicode verison matches the ICU version.
// seems less important if the C++ ICU verison matches the Node.js ICU version.
//assert_basic_equal(cxx_icu_major, node_icu_major);

std::cout << "All OK!" << std::endl;
Expand All @@ -123,11 +132,13 @@ void test_unicode_versions(const nlohmann::json &versions, const nlohmann::json
int test_all(const char *jsonpath) {
std::cout << "= " << __FUNCTION__ << std::endl;

// load the dump of node's process.versions which the meson.build file generated
auto versions = load_json(km::core::path(jsonpath));
auto package = load_json(km::core::path("../../../../package.json"));

assert(!versions.empty());

// load our top level package.json
auto package = load_json(km::core::path("../../../../package.json"));

test_unicode_versions(versions, package);

return EXIT_SUCCESS;
Expand Down

0 comments on commit 1023ef2

Please sign in to comment.