Kaynağa Gözat

test-refactor: add format enabling option

Sam Jaffe 1 yıl önce
ebeveyn
işleme
409dd7d58c
2 değiştirilmiş dosya ile 10 ekleme ve 8 silme
  1. 6 5
      tests/json_schema_test_suite.h
  2. 4 3
      tests/selfvalidate_test.cxx

+ 6 - 5
tests/json_schema_test_suite.h

@@ -57,17 +57,18 @@ static auto SchemaTestName = [](auto const & info) {
   return name;
 };
 
-MATCHER_P(ValidatesAgainst, schema, "") {
+MATCHER_P2(ValidatesAgainst, schema, format, "") {
   jvalidate::ValidationResult result;
-  bool valid = jvalidate::Validator(schema).validate(arg, &result);
+  bool valid = jvalidate::Validator(schema, {.validate_format = format}).validate(arg, &result);
   *result_listener << result;
   return valid;
 }
 
 template <typename T>
-testing::Matcher<T> ValidatesAgainst(jvalidate::Schema const & schema, T const & test) {
+testing::Matcher<T> ValidatesAgainst(jvalidate::Schema const & schema, T const & test,
+                                     bool format) {
   if (not jvalidate::adapter::AdapterFor<T const>(test)["valid"].as_boolean()) {
-    return testing::Not(ValidatesAgainst(std::cref(schema)));
+    return testing::Not(ValidatesAgainst(std::cref(schema), format));
   }
-  return ValidatesAgainst(std::cref(schema));
+  return ValidatesAgainst(std::cref(schema), format);
 }

+ 4 - 3
tests/selfvalidate_test.cxx

@@ -52,7 +52,7 @@ struct RecursiveTestFilter {
 
   bool accepts(std::string const & str) const {
     return std::count(blacklist.begin(), blacklist.end(), str) == 0 and
-      (whitelist.empty() or std::count(whitelist.begin(), whitelist.end(), str) > 0);
+           (whitelist.empty() or std::count(whitelist.begin(), whitelist.end(), str) > 0);
   }
 };
 
@@ -124,7 +124,7 @@ protected:
         tokens[i - 1] += tokens[i];
         tokens.erase(tokens.begin() + i);
       }
-      for (auto &tok : tokens) {
+      for (auto & tok : tokens) {
         into.emplace_back(tok);
       }
     };
@@ -164,6 +164,7 @@ TEST_P(JsonSchema, TestSuite) {
 
   EXPECT_TRUE(load_file(file, spec));
 
+  bool is_format = file.string().find("optional/format") != std::string::npos;
   for (auto const & suite : spec) {
     if (skip_suite(suite["description"].asString())) {
       continue;
@@ -178,7 +179,7 @@ TEST_P(JsonSchema, TestSuite) {
         try {
           std::cout << "\033[0;32m[ CASE     ] \033[0;0m    " << test["description"].asString()
                     << std::endl;
-          EXPECT_THAT(test["data"], ValidatesAgainst(schema, test)) << suite["schema"];
+          EXPECT_THAT(test["data"], ValidatesAgainst(schema, test, is_format)) << suite["schema"];
         } catch (std::exception const & ex) { ADD_FAILURE() << ex.what() << "\n" << test; }
       }
     } catch (std::exception const & ex) {