Skip to content

Commit

Permalink
fix: cpp-gen: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SGSSGene committed Dec 18, 2024
1 parent a6f1d3c commit 5ef98ca
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 45 deletions.
15 changes: 9 additions & 6 deletions schema_salad/tests/cpp_tests/01_single_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ struct MyRecord {
};
}

template <typename T>
example_com::heap_object<T>::~heap_object() = default;
namespace example_com {
template <typename T> heap_object<T>::~heap_object() = default;
}

inline auto example_com::MyRecord::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
Expand All @@ -405,12 +406,13 @@ inline void example_com::MyRecord::fromYaml([[maybe_unused]] YAML::Node const& n
fromYaml(expandedNode, *name);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecord> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecord> {
struct DetectAndExtractFromYaml<::example_com::MyRecord> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecord> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecord{};
auto res = ::example_com::MyRecord{};

if constexpr (::example_com::IsConstant<decltype(res.name)::value_t>::value) try {
fromYaml(n["name"], *res.name);
Expand All @@ -421,6 +423,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecord> {
return std::nullopt;
}
};
}
namespace example_com {

template <typename T>
Expand Down Expand Up @@ -525,7 +528,7 @@ auto load_document_from_string(std::string document) -> DocumentRootType {
return load_document_from_yaml(YAML::Load(document));
}
auto load_document(std::filesystem::path path) -> DocumentRootType {
return load_document_from_yaml(YAML::LoadFile(path));
return load_document_from_yaml(YAML::LoadFile(path.string()));
}
void store_document(DocumentRootType const& root, std::ostream& ostream, store_config config={}) {
auto y = toYaml(root, config);
Expand Down
23 changes: 14 additions & 9 deletions schema_salad/tests/cpp_tests/02_two_records.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ struct MyRecordTwo {
};
}

template <typename T>
example_com::heap_object<T>::~heap_object() = default;
namespace example_com {
template <typename T> heap_object<T>::~heap_object() = default;
}

inline auto example_com::MyRecordOne::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
Expand All @@ -415,12 +416,13 @@ inline void example_com::MyRecordOne::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *name);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordOne> {
struct DetectAndExtractFromYaml<::example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordOne> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordOne{};
auto res = ::example_com::MyRecordOne{};

if constexpr (::example_com::IsConstant<decltype(res.name)::value_t>::value) try {
fromYaml(n["name"], *res.name);
Expand All @@ -431,6 +433,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
return std::nullopt;
}
};
}
inline auto example_com::MyRecordTwo::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
auto n = YAML::Node{};
Expand All @@ -452,12 +455,13 @@ inline void example_com::MyRecordTwo::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *value);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordTwo> {
struct DetectAndExtractFromYaml<::example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordTwo> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordTwo{};
auto res = ::example_com::MyRecordTwo{};

if constexpr (::example_com::IsConstant<decltype(res.value)::value_t>::value) try {
fromYaml(n["value"], *res.value);
Expand All @@ -468,6 +472,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
return std::nullopt;
}
};
}
namespace example_com {

template <typename T>
Expand Down Expand Up @@ -572,7 +577,7 @@ auto load_document_from_string(std::string document) -> DocumentRootType {
return load_document_from_yaml(YAML::Load(document));
}
auto load_document(std::filesystem::path path) -> DocumentRootType {
return load_document_from_yaml(YAML::LoadFile(path));
return load_document_from_yaml(YAML::LoadFile(path.string()));
}
void store_document(DocumentRootType const& root, std::ostream& ostream, store_config config={}) {
auto y = toYaml(root, config);
Expand Down
23 changes: 14 additions & 9 deletions schema_salad/tests/cpp_tests/03_simple_inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ struct MyRecordTwo
};
}

template <typename T>
example_com::heap_object<T>::~heap_object() = default;
namespace example_com {
template <typename T> heap_object<T>::~heap_object() = default;
}

inline auto example_com::MyRecordOne::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
Expand All @@ -416,12 +417,13 @@ inline void example_com::MyRecordOne::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *name);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordOne> {
struct DetectAndExtractFromYaml<::example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordOne> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordOne{};
auto res = ::example_com::MyRecordOne{};

if constexpr (::example_com::IsConstant<decltype(res.name)::value_t>::value) try {
fromYaml(n["name"], *res.name);
Expand All @@ -432,6 +434,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
return std::nullopt;
}
};
}
inline auto example_com::MyRecordTwo::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
auto n = YAML::Node{};
Expand All @@ -455,12 +458,13 @@ inline void example_com::MyRecordTwo::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *value);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordTwo> {
struct DetectAndExtractFromYaml<::example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordTwo> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordTwo{};
auto res = ::example_com::MyRecordTwo{};

if constexpr (::example_com::IsConstant<decltype(res.value)::value_t>::value) try {
fromYaml(n["value"], *res.value);
Expand All @@ -471,6 +475,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
return std::nullopt;
}
};
}
namespace example_com {

template <typename T>
Expand Down Expand Up @@ -575,7 +580,7 @@ auto load_document_from_string(std::string document) -> DocumentRootType {
return load_document_from_yaml(YAML::Load(document));
}
auto load_document(std::filesystem::path path) -> DocumentRootType {
return load_document_from_yaml(YAML::LoadFile(path));
return load_document_from_yaml(YAML::LoadFile(path.string()));
}
void store_document(DocumentRootType const& root, std::ostream& ostream, store_config config={}) {
auto y = toYaml(root, config);
Expand Down
15 changes: 9 additions & 6 deletions schema_salad/tests/cpp_tests/04_abstract_inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ struct MyRecordTwo
};
}

template <typename T>
example_com::heap_object<T>::~heap_object() = default;
namespace example_com {
template <typename T> heap_object<T>::~heap_object() = default;
}

inline example_com::MyRecordOne::~MyRecordOne() = default;
inline auto example_com::MyRecordOne::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
Expand Down Expand Up @@ -440,12 +441,13 @@ inline void example_com::MyRecordTwo::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *value);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordTwo> {
struct DetectAndExtractFromYaml<::example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordTwo> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordTwo{};
auto res = ::example_com::MyRecordTwo{};

if constexpr (::example_com::IsConstant<decltype(res.value)::value_t>::value) try {
fromYaml(n["value"], *res.value);
Expand All @@ -456,6 +458,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
return std::nullopt;
}
};
}
namespace example_com {

template <typename T>
Expand Down Expand Up @@ -560,7 +563,7 @@ auto load_document_from_string(std::string document) -> DocumentRootType {
return load_document_from_yaml(YAML::Load(document));
}
auto load_document(std::filesystem::path path) -> DocumentRootType {
return load_document_from_yaml(YAML::LoadFile(path));
return load_document_from_yaml(YAML::LoadFile(path.string()));
}
void store_document(DocumentRootType const& root, std::ostream& ostream, store_config config={}) {
auto y = toYaml(root, config);
Expand Down
39 changes: 24 additions & 15 deletions schema_salad/tests/cpp_tests/05_specialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ struct MyRecordTwo {
};
}

template <typename T>
example_com::heap_object<T>::~heap_object() = default;
namespace example_com {
template <typename T> heap_object<T>::~heap_object() = default;
}

inline auto example_com::FieldRecordA::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
Expand All @@ -424,16 +425,18 @@ inline auto example_com::FieldRecordA::toYaml([[maybe_unused]] ::example_com::st
inline void example_com::FieldRecordA::fromYaml([[maybe_unused]] YAML::Node const& n) {
using ::example_com::fromYaml;
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::FieldRecordA> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::FieldRecordA> {
struct DetectAndExtractFromYaml<::example_com::FieldRecordA> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::FieldRecordA> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::FieldRecordA{};
auto res = ::example_com::FieldRecordA{};

return std::nullopt;
}
};
}
inline auto example_com::FieldRecordB::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
auto n = YAML::Node{};
Expand All @@ -445,16 +448,18 @@ inline auto example_com::FieldRecordB::toYaml([[maybe_unused]] ::example_com::st
inline void example_com::FieldRecordB::fromYaml([[maybe_unused]] YAML::Node const& n) {
using ::example_com::fromYaml;
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::FieldRecordB> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::FieldRecordB> {
struct DetectAndExtractFromYaml<::example_com::FieldRecordB> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::FieldRecordB> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::FieldRecordB{};
auto res = ::example_com::FieldRecordB{};

return std::nullopt;
}
};
}
inline auto example_com::MyRecordOne::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
auto n = YAML::Node{};
Expand All @@ -476,12 +481,13 @@ inline void example_com::MyRecordOne::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *name);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordOne> {
struct DetectAndExtractFromYaml<::example_com::MyRecordOne> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordOne> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordOne{};
auto res = ::example_com::MyRecordOne{};

if constexpr (::example_com::IsConstant<decltype(res.name)::value_t>::value) try {
fromYaml(n["name"], *res.name);
Expand All @@ -492,6 +498,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordOne> {
return std::nullopt;
}
};
}
inline auto example_com::MyRecordTwo::toYaml([[maybe_unused]] ::example_com::store_config const& config) const -> YAML::Node {
using ::example_com::toYaml;
auto n = YAML::Node{};
Expand Down Expand Up @@ -523,12 +530,13 @@ inline void example_com::MyRecordTwo::fromYaml([[maybe_unused]] YAML::Node const
fromYaml(expandedNode, *value);
}
}
namespace example_com {
template <>
struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<example_com::MyRecordTwo> {
struct DetectAndExtractFromYaml<::example_com::MyRecordTwo> {
auto operator()(YAML::Node const& n) const -> std::optional<::example_com::MyRecordTwo> {
if (!n.IsDefined()) return std::nullopt;
if (!n.IsMap()) return std::nullopt;
auto res = example_com::MyRecordTwo{};
auto res = ::example_com::MyRecordTwo{};

if constexpr (::example_com::IsConstant<decltype(res.name)::value_t>::value) try {
fromYaml(n["name"], *res.name);
Expand All @@ -545,6 +553,7 @@ struct example_com::DetectAndExtractFromYaml<example_com::MyRecordTwo> {
return std::nullopt;
}
};
}
namespace example_com {

template <typename T>
Expand Down Expand Up @@ -649,7 +658,7 @@ auto load_document_from_string(std::string document) -> DocumentRootType {
return load_document_from_yaml(YAML::Load(document));
}
auto load_document(std::filesystem::path path) -> DocumentRootType {
return load_document_from_yaml(YAML::LoadFile(path));
return load_document_from_yaml(YAML::LoadFile(path.string()));
}
void store_document(DocumentRootType const& root, std::ostream& ostream, store_config config={}) {
auto y = toYaml(root, config);
Expand Down

0 comments on commit 5ef98ca

Please sign in to comment.