add test for substitution

This commit is contained in:
ToruNiina 2017-04-20 00:13:37 +09:00
parent 0b13f01668
commit 9234a34faa

View File

@ -130,3 +130,72 @@ BOOST_AUTO_TEST_CASE(test_value_copy_move_constructor)
BOOST_CHECK_EQUAL(w4.cast<toml::value_t::String >(), "hoge");
}
BOOST_AUTO_TEST_CASE(test_value_copy_move_substitution)
{
toml::Boolean b(true);
toml::Integer i(42);
toml::Float f(3.14);
toml::String s("hoge");
toml::Datetime d(std::chrono::system_clock::now());
toml::Array a;
a.emplace_back(2);
a.emplace_back(7);
a.emplace_back(1);
a.emplace_back(8);
a.emplace_back(2);
toml::Table t;
t.emplace("val1", true);
t.emplace("val2", 42);
t.emplace("val3", 3.14);
t.emplace("val4", "piyo");
toml::value v1(b);
toml::value v2(i);
toml::value v3(f);
toml::value v4(s);
toml::value v5(d);
toml::value v6(a);
toml::value v7(t);
v1 = i;
v2 = f;
v3 = s;
v4 = d;
v5 = a;
v6 = t;
v7 = b;
BOOST_CHECK_EQUAL(v1.type(), toml::value_t::Integer);
BOOST_CHECK_EQUAL(v2.type(), toml::value_t::Float);
BOOST_CHECK_EQUAL(v3.type(), toml::value_t::String);
BOOST_CHECK_EQUAL(v4.type(), toml::value_t::Datetime);
BOOST_CHECK_EQUAL(v5.type(), toml::value_t::Array);
BOOST_CHECK_EQUAL(v6.type(), toml::value_t::Table);
BOOST_CHECK_EQUAL(v7.type(), toml::value_t::Boolean);
BOOST_CHECK_EQUAL(v7.cast<toml::value_t::Boolean >(), b);
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Integer >(), i);
BOOST_CHECK_EQUAL(v2.cast<toml::value_t::Float >(), f);
BOOST_CHECK_EQUAL(v3.cast<toml::value_t::String >(), s);
v1 = std::move(f);
v2 = std::move(s);
v3 = std::move(d);
v4 = std::move(a);
v5 = std::move(t);
v6 = std::move(b);
v7 = std::move(i);
BOOST_CHECK_EQUAL(v1.type(), toml::value_t::Float);
BOOST_CHECK_EQUAL(v2.type(), toml::value_t::String);
BOOST_CHECK_EQUAL(v3.type(), toml::value_t::Datetime);
BOOST_CHECK_EQUAL(v4.type(), toml::value_t::Array);
BOOST_CHECK_EQUAL(v5.type(), toml::value_t::Table);
BOOST_CHECK_EQUAL(v6.type(), toml::value_t::Boolean);
BOOST_CHECK_EQUAL(v7.type(), toml::value_t::Integer);
BOOST_CHECK_EQUAL(v6.cast<toml::value_t::Boolean >(), b);
BOOST_CHECK_EQUAL(v7.cast<toml::value_t::Integer >(), i);
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Float >(), f);
BOOST_CHECK_EQUAL(v2.cast<toml::value_t::String >(), s);
}