Skip to content

Commit

Permalink
adds some wchar_t proptests (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyTinni authored Oct 28, 2024
1 parent fe49f6a commit 63176a3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/proptests/main_rapidcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ template <> struct Arbitrary<tyti::vdf::object>
};
} // namespace rc

bool containsSurrogate(const std::wstring &str)
{
return str.find(wchar_t(-1)) != str.npos;
}

int main()
{

////////////////////////////////////////////////////////////////
// object parsing tests

Expand Down Expand Up @@ -130,6 +136,49 @@ int main()
RC_ASSERT(obj.name == to_test.name);
});

success &= 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::suchThat(rc::gen::string<std::wstring>(),
[](const auto &str)
{ return !containsSurrogate(str); });

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

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

success &= rc::check(
"serializing and then parsing just the name with default options "
"should return the original name - not escaped - wchar_t",
[]()
{
vdf::wobject obj;
obj.name =
*rc::gen::suchThat(rc::gen::string<std::wstring>(),
[](const std::wstring &str) {
return str.find(L"\"") == str.npos &&
!containsSurrogate(str);
});

vdf::WriteOptions writeOpts;
writeOpts.escape_symbols = false;

vdf::Options readOpts;
readOpts.strip_escape_symbols = false;

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

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

success &= rc::check(
"check if the attributes are also written and parsed correctly",
[](const vdf::object &in)
Expand Down

0 comments on commit 63176a3

Please sign in to comment.