Ver código fonte

chore: import cleanup/fixes from feat/format-matcher

Sam Jaffe 2 semanas atrás
pai
commit
510dd917a8
3 arquivos alterados com 32 adições e 21 exclusões
  1. 2 1
      include/jvalidate/_config.h
  2. 13 3
      include/jvalidate/detail/string.h
  3. 17 17
      tests/CMakeLists.txt

+ 2 - 1
include/jvalidate/_config.h

@@ -1,6 +1,7 @@
 #pragma once
 
-#if __has_include(<unicode/std_string.h>)
+#if !defined(JVALIDATE_HAS_ICU)
+#elif __has_include(<unicode/std_string.h>)
 #define JVALIDATE_HAS_ICU 1
 #else
 #define JVALIDATE_HAS_ICU 0

+ 13 - 3
include/jvalidate/detail/string.h

@@ -6,6 +6,7 @@
 #include <jvalidate/_config.h>
 
 #include <cstring>
+#include <string_view>
 
 #if JVALIDATE_HAS_ICU
 #include <unicode/brkiter.h>
@@ -13,8 +14,9 @@
 #endif
 
 namespace jvalidate::detail {
+#if JVALIDATE_HAS_ICU
 /**
- * @brief Calclates the string-length of the argument, treating multi-byte
+ * @brief Calculates the string-length of the argument, treating multi-byte
  * characters and unicode graphemes as single characters (which std::string
  * cannot do).
  *
@@ -23,13 +25,21 @@ namespace jvalidate::detail {
  * @returns A number no greater than arg.length(), depending on the number of
  * graphemes/codepoints in the string.
  */
-#if JVALIDATE_HAS_ICU
 inline size_t length(std::string_view arg) {
   icu::UnicodeString ucs = icu::UnicodeString::fromUTF8(icu::StringPiece(arg));
   return ucs.countChar32();
 }
 #else
-
+/**
+ * @brief Calculates the string-length of the argument, without attempting to
+ * parse out graphemes. This method is provided so that it is possible to use
+ * maxLength and minLength constraints even when building without IDNA or ICU
+ * in the toolchain.
+ *
+ * @param arg Any UTF8 compatible string (including a standard ASCII string)
+ *
+ * @returns arg.length()
+ */
 inline size_t length(std::string_view arg) { return arg.length(); }
 #endif
 }

+ 17 - 17
tests/CMakeLists.txt

@@ -11,13 +11,6 @@ find_package(CURL REQUIRED)
 # ICU components = data, i18n, io, le, lx, test, tu and uc.
 find_package(ICU 77.1 COMPONENTS uc i18n)
 
-FetchContent_Declare(
-  IDNA
-  GIT_REPOSITORY https://github.com/ada-url/idna.git
-  GIT_TAG        0.5.0
-)
-FetchContent_MakeAvailable(IDNA)
-
 FetchContent_Declare(
   json_schema_test_suite
   GIT_REPOSITORY https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
@@ -28,11 +21,11 @@ FetchContent_MakeAvailable(json_schema_test_suite)
 include(GoogleTest)
 
 add_executable(annotation_test annotation_test.cxx)
-target_link_libraries(annotation_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib)
+target_link_libraries(annotation_test GTest::gtest GTest::gmock jsoncpp_lib)
 gtest_discover_tests(annotation_test)
 
 add_executable(extension_test extension_test.cxx)
-target_link_libraries(extension_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib)
+target_link_libraries(extension_test GTest::gtest GTest::gmock jsoncpp_lib)
 gtest_discover_tests(extension_test)
 
 add_executable(selfvalidate_test selfvalidate_test.cxx)
@@ -43,7 +36,7 @@ target_compile_definitions(selfvalidate_test
     JVALIDATE_JSON_SCHEMA_TEST_SUITE_DIR="${json_schema_test_suite_SOURCE_DIR}"
 )
 endif()
-target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib CURL::libcurl)
+target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock jsoncpp_lib CURL::libcurl)
 
 if (ICU_FOUND)
   target_link_libraries(annotation_test ICU::uc ICU::i18n)
@@ -59,16 +52,23 @@ string(
   "*optional_zeroTerminatedFloats"
   "*optional_format*"
 )
-if (NOT ${ICU_FOUND})
+set(SelfValidateTest_Unsupported_Suites "")
+set(SelfValidateTest_Unsupported_Cases "*leap second")
+
+if (ICU_FOUND)
+  target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_ICU=1)
+  target_link_libraries(annotation_test ICU::uc ICU::i18n)
+  target_link_libraries(extension_test ICU::uc ICU::i18n)
+  target_link_libraries(selfvalidate_test ICU::uc ICU::i18n)
+else()
+  target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_ICU=0)
   string(
-    JOIN ":"
-    SelfValidateTest_Unsupported
-    ${SelfValidateTest_Unsupported}
-    "*optional_non_bmp_regex"
+    APPEND SelfValidateTest_Unsupported
+    ":*optional_non_bmp_regex"
   )
 endif()
-set(SelfValidateTest_Unsupported_Cases "*leap second")
 
 gtest_discover_tests(selfvalidate_test
-                     EXTRA_ARGS --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
+                     EXTRA_ARGS --json_suite_filter=-${SelfValidateTest_Unsupported_Suites}
+                                --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
                      TEST_FILTER -${SelfValidateTest_Unsupported})