add implicit conversions test (operator T())
This commit is contained in:
parent
9f8b270ed9
commit
9f103d19d7
1 changed files with 48 additions and 19 deletions
|
@ -261,26 +261,55 @@ TEST_CASE("basic usage", "[udt]")
|
||||||
{
|
{
|
||||||
const auto big_json =
|
const auto big_json =
|
||||||
u8R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json;
|
u8R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json;
|
||||||
const auto parsed_book = big_json.get<udt::contact_book>();
|
SECTION("via explicit calls to get")
|
||||||
const auto book_name = big_json["name"].get<udt::name>();
|
{
|
||||||
const auto contacts = big_json["contacts"].get<std::vector<udt::contact>>();
|
const auto parsed_book = big_json.get<udt::contact_book>();
|
||||||
const auto contact_json = big_json["contacts"].at(0);
|
const auto book_name = big_json["name"].get<udt::name>();
|
||||||
const auto contact = contact_json.get<udt::contact>();
|
const auto contacts =
|
||||||
const auto person = contact_json["person"].get<udt::person>();
|
big_json["contacts"].get<std::vector<udt::contact>>();
|
||||||
const auto address = contact_json["address"].get<udt::address>();
|
const auto contact_json = big_json["contacts"].at(0);
|
||||||
const auto age = contact_json["person"]["age"].get<udt::age>();
|
const auto contact = contact_json.get<udt::contact>();
|
||||||
const auto country = contact_json["person"]["country"].get<udt::country>();
|
const auto person = contact_json["person"].get<udt::person>();
|
||||||
const auto name = contact_json["person"]["name"].get<udt::name>();
|
const auto address = contact_json["address"].get<udt::address>();
|
||||||
|
const auto age = contact_json["person"]["age"].get<udt::age>();
|
||||||
|
const auto country =
|
||||||
|
contact_json["person"]["country"].get<udt::country>();
|
||||||
|
const auto name = contact_json["person"]["name"].get<udt::name>();
|
||||||
|
|
||||||
CHECK(age == a);
|
CHECK(age == a);
|
||||||
CHECK(name == n);
|
CHECK(name == n);
|
||||||
CHECK(country == c);
|
CHECK(country == c);
|
||||||
CHECK(address == addr);
|
CHECK(address == addr);
|
||||||
CHECK(person == sfinae_addict);
|
CHECK(person == sfinae_addict);
|
||||||
CHECK(contact == cpp_programmer);
|
CHECK(contact == cpp_programmer);
|
||||||
CHECK(contacts == book.m_contacts);
|
CHECK(contacts == book.m_contacts);
|
||||||
CHECK(book_name == udt::name{"C++"});
|
CHECK(book_name == udt::name{"C++"});
|
||||||
CHECK(book == parsed_book);
|
CHECK(book == parsed_book);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("implicit conversions")
|
||||||
|
{
|
||||||
|
const udt::contact_book parsed_book = big_json;
|
||||||
|
const udt::name book_name = big_json["name"];
|
||||||
|
const std::vector<udt::contact> contacts = big_json["contacts"];
|
||||||
|
const auto contact_json = big_json["contacts"].at(0);
|
||||||
|
const udt::contact contact = contact_json;
|
||||||
|
const udt::person person = contact_json["person"];
|
||||||
|
const udt::address address = contact_json["address"];
|
||||||
|
const udt::age age = contact_json["person"]["age"];
|
||||||
|
const udt::country country = contact_json["person"]["country"];
|
||||||
|
const udt::name name = contact_json["person"]["name"];
|
||||||
|
|
||||||
|
CHECK(age == a);
|
||||||
|
CHECK(name == n);
|
||||||
|
CHECK(country == c);
|
||||||
|
CHECK(address == addr);
|
||||||
|
CHECK(person == sfinae_addict);
|
||||||
|
CHECK(contact == cpp_programmer);
|
||||||
|
CHECK(contacts == book.m_contacts);
|
||||||
|
CHECK(book_name == udt::name{"C++"});
|
||||||
|
CHECK(book == parsed_book);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue