Skip to content

Commit

Permalink
fixes return type of rapidcheck (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyTinni authored Oct 28, 2024
1 parent 96b5509 commit dad202a
Showing 1 changed file with 87 additions and 95 deletions.
182 changes: 87 additions & 95 deletions tests/proptests/main_rapidcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,103 +90,95 @@ int main()
// object parsing tests

using namespace tyti;
rc::check("serializing and then parsing just the name with default options "
"should return the original name",
[]()
{
vdf::object obj;
obj.name = *rc::gen::string<std::string>();

std::stringstream sstr;
vdf::write(sstr, obj);

auto to_test = vdf::read(sstr);
RC_ASSERT(obj.name == to_test.name);
});

rc::check("serializing and then parsing just the name with default options "
"should return the original name - wchar_t",
[]()
{
vdf::wobject obj;
obj.name = *rc::gen::string<std::wstring>();

std::wstringstream sstr;
vdf::write(sstr, obj);

auto to_test = vdf::read(sstr);
RC_ASSERT(obj.name == to_test.name);
});

rc::check("check if the attributes are also written and parsed correctly",
[](const vdf::object &in)
{
std::stringstream sstr;
vdf::write(sstr, in);
auto to_test = tyti::vdf::read(sstr);
RC_ASSERT(in == to_test);
});

rc::check("check if the childs are also written and parsed correctly",
[](vdf::object in)
{
// todo this just tests childs with depth 1
using child_vec = std::vector<std::shared_ptr<vdf::object>>;
child_vec childs = *rc::gen::container<child_vec>(
rc::gen::makeShared<vdf::object>(
rc::gen::arbitrary<vdf::object>()));

for (const auto &c : childs)
{
in.childs[c->name] = c;
}

std::stringstream sstr;
vdf::write(sstr, in);
auto to_test = tyti::vdf::read(sstr);
RC_ASSERT(in == to_test);
});
bool success = true;
success &= rc::check(
"serializing and then parsing just the name with default options "
"should return the original name",
[]()
{
vdf::object obj;
obj.name = *rc::gen::string<std::string>();

std::stringstream sstr;
vdf::write(sstr, obj);

auto to_test = vdf::read(sstr);
RC_ASSERT(obj.name == to_test.name);
});

success &= rc::check(
"check if the attributes are also written and parsed correctly",
[](const vdf::object &in)
{
std::stringstream sstr;
vdf::write(sstr, in);
auto to_test = tyti::vdf::read(sstr);
RC_ASSERT(in == to_test);
});

success &= rc::check(
"check if the childs are also written and parsed correctly",
[](vdf::object in)
{
// todo this just tests childs with depth 1
using child_vec = std::vector<std::shared_ptr<vdf::object>>;
child_vec childs =
*rc::gen::container<child_vec>(rc::gen::makeShared<vdf::object>(
rc::gen::arbitrary<vdf::object>()));

for (const auto &c : childs)
{
in.childs[c->name] = c;
}

std::stringstream sstr;
vdf::write(sstr, in);
auto to_test = tyti::vdf::read(sstr);
RC_ASSERT(in == to_test);
});

////////////////////////////////////////////////////////////////
// comments parsing tests

rc::check("single line comment should not cause any errors",
[]()
{
auto comment = *rc::gen::suchThat(
rc::gen::string<std::string>(), [](const std::string &str)
{ return str.find("\n") == str.npos; });

std::stringstream input;
input << "\"test\""
<< "{"
<< "//" << comment << "\n"
<< "\"key\" \"value\"\n"
<< "}";
auto to_test = vdf::read(input);
RC_ASSERT("test" == to_test.name);
RC_ASSERT(1 == to_test.attribs.size());
RC_ASSERT("value" == to_test.attribs["key"]);
});

rc::check("multi line comment should not cause any errors",
[]()
{
auto comment = *rc::gen::suchThat(
rc::gen::string<std::string>(), [](const std::string &str)
{ return str.find("*/") == str.npos; });

std::stringstream input;
input << "\"test\""
<< "{"
<< "/*" << comment << "*/"
<< "\"key\" \"value\"\n"
<< "}";
auto to_test = vdf::read(input);
RC_ASSERT("test" == to_test.name);
RC_ASSERT(1 == to_test.attribs.size());
RC_ASSERT("value" == to_test.attribs["key"]);
});

return 0;
success &= rc::check("single line comment should not cause any errors",
[]()
{
auto comment = *rc::gen::suchThat(
rc::gen::string<std::string>(),
[](const std::string &str)
{ return str.find("\n") == str.npos; });

std::stringstream input;
input << "\"test\""
<< "{"
<< "//" << comment << "\n"
<< "\"key\" \"value\"\n"
<< "}";
auto to_test = vdf::read(input);
RC_ASSERT("test" == to_test.name);
RC_ASSERT(1 == to_test.attribs.size());
RC_ASSERT("value" == to_test.attribs["key"]);
});

success &= rc::check("multi line comment should not cause any errors",
[]()
{
auto comment = *rc::gen::suchThat(
rc::gen::string<std::string>(),
[](const std::string &str)
{ return str.find("*/") == str.npos; });

std::stringstream input;
input << "\"test\""
<< "{"
<< "/*" << comment << "*/"
<< "\"key\" \"value\"\n"
<< "}";
auto to_test = vdf::read(input);
RC_ASSERT("test" == to_test.name);
RC_ASSERT(1 == to_test.attribs.size());
RC_ASSERT("value" == to_test.attribs["key"]);
});

return (success) ? 0 : 1;
}

0 comments on commit dad202a

Please sign in to comment.