-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
218 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "vdf_multiobject_generator.hpp" | ||
|
||
namespace tyti::vdf | ||
{ | ||
bool operator==(const tyti::vdf::multikey_object &rhs, | ||
const tyti::vdf::multikey_object &lhs) | ||
{ | ||
if (rhs.name != lhs.name) | ||
return false; | ||
if (rhs.attribs != lhs.attribs) | ||
return false; | ||
for (const auto &[k, v] : rhs.childs) | ||
{ | ||
auto [begin, end] = lhs.childs.equal_range(k); | ||
|
||
#ifdef _MSC_VER | ||
// suppress warning about recursive call of operator==. This is here | ||
// by intention | ||
#pragma warning(disable : 5232) | ||
#endif | ||
while (begin != end) | ||
{ | ||
if (begin->second == nullptr && v == nullptr) | ||
return true; | ||
if (*(begin->second) == *v) | ||
return true; | ||
++begin; | ||
} | ||
return false; | ||
#ifdef _MSC_VER | ||
#pragma warning(default : 5232) | ||
#endif | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace tyti::vdf | ||
|
||
namespace rc::detail | ||
{ | ||
|
||
void showValue(tyti::vdf::multikey_object obj, std::ostream &os) | ||
{ | ||
os << "name: " << obj.name << "\n"; | ||
os << "attribs (size:" << obj.attribs.size() << "): \n"; | ||
for (const auto &[k, v] : obj.attribs) | ||
os << k << "\t" << v << "\n"; | ||
os << "childs: (size:" << obj.childs.size() << "): \n"; | ||
for (const auto &[k, v] : obj.childs) | ||
{ | ||
os << "'" << k << "'\t'"; | ||
if (v) | ||
showValue(*v, os); | ||
else | ||
os << "nullptr!"; | ||
|
||
os << "'\n"; | ||
} | ||
|
||
os << "'\n"; | ||
} | ||
|
||
} // namespace rc::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <rapidcheck.h> | ||
#include <vdf_parser.hpp> | ||
|
||
namespace tyti::vdf | ||
{ | ||
bool operator==(const tyti::vdf::multikey_object &rhs, | ||
const tyti::vdf::multikey_object &lhs); | ||
} // namespace tyti::vdf | ||
|
||
namespace rc | ||
{ | ||
|
||
template <> struct Arbitrary<tyti::vdf::multikey_object> | ||
{ | ||
static Gen<tyti::vdf::multikey_object> arbitrary() | ||
{ | ||
using tyti::vdf::multikey_object; | ||
return gen::build<multikey_object>(gen::set(&multikey_object::name), | ||
gen::set(&multikey_object::attribs)); | ||
} | ||
}; | ||
} // namespace rc | ||
|
||
namespace rc::detail | ||
{ | ||
|
||
void showValue(tyti::vdf::multikey_object obj, std::ostream &os); | ||
|
||
} // namespace rc::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "vdf_object_generator.hpp" | ||
|
||
namespace tyti::vdf | ||
{ | ||
bool operator==(const tyti::vdf::object &rhs, const tyti::vdf::object &lhs) | ||
{ | ||
if (rhs.name != lhs.name) | ||
return false; | ||
if (rhs.attribs != lhs.attribs) | ||
return false; | ||
for (const auto &[k, v] : rhs.childs) | ||
{ | ||
auto itr = lhs.childs.find(k); | ||
if (itr == lhs.childs.end()) | ||
{ | ||
return false; | ||
} | ||
|
||
#ifdef _MSC_VER | ||
// suppress warning about recursive call of operator==. This is here | ||
// by intention | ||
#pragma warning(disable : 5232) | ||
#endif | ||
if (itr->second != v) | ||
{ | ||
if (itr->second == nullptr || v == nullptr) | ||
return *(itr->second) != *v; | ||
} | ||
#ifdef _MSC_VER | ||
#pragma warning(default : 5232) | ||
#endif | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace tyti::vdf | ||
|
||
namespace rc::details | ||
{ | ||
void showValue(tyti::vdf::object obj, std::ostream &os) | ||
{ | ||
os << "name: " << obj.name << "\n"; | ||
os << "attribs (size:" << obj.attribs.size() << "): \n"; | ||
for (const auto &[k, v] : obj.attribs) | ||
os << k << "\t" << v << "\n"; | ||
os << "childs: (size:" << obj.childs.size() << "): \n"; | ||
for (const auto &[k, v] : obj.childs) | ||
{ | ||
os << k << "\t"; | ||
if (v) | ||
showValue(*v, os); | ||
else | ||
os << "nullptr!"; | ||
os << "\n"; | ||
} | ||
} | ||
|
||
void showValue(const std::tuple<tyti::vdf::object, tyti::vdf::object> &objs, | ||
std::ostream &os) | ||
{ | ||
os << "[LHS]: \n"; | ||
showValue(std::get<0>(objs), os); | ||
os << "[RHS]: \n"; | ||
showValue(std::get<1>(objs), os); | ||
} | ||
} // namespace rc::details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <rapidcheck.h> | ||
#include <vdf_parser.hpp> | ||
|
||
namespace tyti::vdf | ||
{ | ||
bool operator==(const tyti::vdf::object &rhs, const tyti::vdf::object &lhs); | ||
|
||
} // namespace tyti::vdf | ||
|
||
namespace rc | ||
{ | ||
template <> struct Arbitrary<tyti::vdf::object> | ||
{ | ||
static Gen<tyti::vdf::object> arbitrary() | ||
{ | ||
using tyti::vdf::object; | ||
return gen::build<object>(gen::set(&object::name), | ||
gen::set(&object::attribs)); | ||
} | ||
}; | ||
} // namespace rc | ||
|
||
namespace rc::details | ||
{ | ||
|
||
void showValue(tyti::vdf::object obj, std::ostream &os); | ||
|
||
void showValue(const std::tuple<tyti::vdf::object, tyti::vdf::object> &objs, | ||
std::ostream &os); | ||
} // namespace rc::details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters