json_schema_test_suite.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <filesystem>
  2. #include <gmock/gmock.h>
  3. inline std::filesystem::path const & JSONSchemaTestSuiteDir() {
  4. static auto const g_root =
  5. std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
  6. static auto const g_path = g_root / "thirdparty" / "JSON-Schema-Test-Suite";
  7. return g_path;
  8. }
  9. inline auto SchemaTests(std::string_view draft) {
  10. struct fs_iterator : std::filesystem::recursive_directory_iterator {
  11. using super = std::filesystem::recursive_directory_iterator;
  12. using value_type = std::filesystem::path;
  13. using super::super;
  14. auto const operator*() const { return super::operator*().path(); }
  15. fs_iterator operator++() {
  16. do {
  17. super::operator++();
  18. } while (*this != fs_iterator() && super::operator*().is_directory());
  19. return *this;
  20. }
  21. };
  22. auto const dir = JSONSchemaTestSuiteDir() / "tests" / draft;
  23. return testing::ValuesIn(fs_iterator(dir), fs_iterator());
  24. }
  25. static auto SchemaTestName = [](auto const & info) {
  26. std::string name = std::get<1>(info.param).stem();
  27. std::transform(name.begin(), name.end(), name.begin(),
  28. [](char c) { return std::isalnum(c) ? c : '_'; });
  29. return name;
  30. };