#include #include #include inline std::filesystem::path const & JSONSchemaTestSuiteDir() { static auto const g_root = std::filesystem::path(__FILE__).parent_path().parent_path().parent_path(); static auto const g_path = g_root / "thirdparty" / "JSON-Schema-Test-Suite"; return g_path; } inline auto SchemaTests(std::string_view draft) { struct fs_iterator : std::filesystem::recursive_directory_iterator { using super = std::filesystem::recursive_directory_iterator; using value_type = std::filesystem::path; using super::super; auto const operator*() const { return super::operator*().path(); } fs_iterator operator++() { do { super::operator++(); } while (*this != fs_iterator() && super::operator*().is_directory()); return *this; } }; auto const dir = JSONSchemaTestSuiteDir() / "tests" / draft; return testing::ValuesIn(fs_iterator(dir), fs_iterator()); } static auto SchemaTestName = [](auto const & info) { std::string name = std::get<1>(info.param).stem(); std::transform(name.begin(), name.end(), name.begin(), [](char c) { return std::isalnum(c) ? c : '_'; }); return name; }; MATCHER_P(ValidatesAgainst, schema, "") { return jvalidate::Validator(schema).validate(arg); } template testing::Matcher ValidatesAgainst(jvalidate::Schema const & schema, T const & test) { if (jvalidate::adapter::AdapterFor(test)["valid"].as_boolean()) { return testing::Not(ValidatesAgainst(std::cref(schema))); } return ValidatesAgainst(std::cref(schema)); }