From 1023ef28a13deb350b2ed32a090231a8da3250e4 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 14 May 2024 10:05:35 -0500 Subject: [PATCH] chore(core): Unicode version test - refactor and support >= node version Fixes: #10183 --- core/tests/unit/ldml/test_unicode.cpp | 35 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/core/tests/unit/ldml/test_unicode.cpp b/core/tests/unit/ldml/test_unicode.cpp index 680ffe212f9..f3e42fae3b0 100644 --- a/core/tests/unit/ldml/test_unicode.cpp +++ b/core/tests/unit/ldml/test_unicode.cpp @@ -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; @@ -79,14 +91,7 @@ void test_unicode_versions(const nlohmann::json &versions, const nlohmann::json node(versions["/node"_json_pointer].template get()), node_icu(versions["/icu"_json_pointer].template get()), node_engine(package["/engines/node"_json_pointer].template get()); - // 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); @@ -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; @@ -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;