|
|
@@ -2,9 +2,12 @@
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
+#include <jvalidate/enum.h>
|
|
|
#include <jvalidate/validation_result.h>
|
|
|
#include <jvalidate/validator.h>
|
|
|
|
|
|
+using SchemaParams = std::tuple<jvalidate::schema::Version, std::filesystem::path>;
|
|
|
+
|
|
|
inline std::filesystem::path const & JSONSchemaTestSuiteDir() {
|
|
|
static auto const g_root =
|
|
|
std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
|
|
|
@@ -12,14 +15,23 @@ inline std::filesystem::path const & JSONSchemaTestSuiteDir() {
|
|
|
return g_path;
|
|
|
}
|
|
|
|
|
|
-inline auto SchemaTests(std::string_view draft) {
|
|
|
+inline std::string to_string(jvalidate::schema::Version version) {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << version;
|
|
|
+ return ss.str();
|
|
|
+}
|
|
|
+
|
|
|
+inline auto SchemaTests(jvalidate::schema::Version version) {
|
|
|
struct fs_iterator : std::filesystem::recursive_directory_iterator {
|
|
|
using super = std::filesystem::recursive_directory_iterator;
|
|
|
- using value_type = std::filesystem::path;
|
|
|
+ using value_type = SchemaParams;
|
|
|
+ using reference = SchemaParams;
|
|
|
|
|
|
- using super::super;
|
|
|
+ fs_iterator() = default;
|
|
|
+ explicit fs_iterator(jvalidate::schema::Version version)
|
|
|
+ : super(JSONSchemaTestSuiteDir() / "tests" / to_string(version)), version(version) {}
|
|
|
|
|
|
- std::filesystem::path operator*() const { return super::operator*().path(); }
|
|
|
+ SchemaParams operator*() const { return std::make_tuple(version, super::operator*().path()); }
|
|
|
|
|
|
fs_iterator operator++() {
|
|
|
do {
|
|
|
@@ -27,14 +39,19 @@ inline auto SchemaTests(std::string_view draft) {
|
|
|
} while (*this != fs_iterator() && super::operator*().is_directory());
|
|
|
return *this;
|
|
|
}
|
|
|
+
|
|
|
+ jvalidate::schema::Version version;
|
|
|
};
|
|
|
|
|
|
- auto const dir = JSONSchemaTestSuiteDir() / "tests" / draft;
|
|
|
- return testing::ValuesIn(fs_iterator(dir), fs_iterator());
|
|
|
+ return testing::ValuesIn(fs_iterator(version), fs_iterator());
|
|
|
}
|
|
|
|
|
|
static auto SchemaTestName = [](auto const & info) {
|
|
|
- std::string name = std::get<1>(info.param).stem();
|
|
|
+ auto [version, file] = info.param;
|
|
|
+ auto base = JSONSchemaTestSuiteDir() / "tests" / to_string(version);
|
|
|
+
|
|
|
+ std::string name = std::filesystem::relative(file, base);
|
|
|
+ name = name.substr(0, name.rfind('.'));
|
|
|
std::transform(name.begin(), name.end(), name.begin(),
|
|
|
[](char c) { return std::isalnum(c) ? c : '_'; });
|
|
|
return name;
|