2022-09-16 10:51:41 +00:00
|
|
|
#include "unit_test.hpp"
|
|
|
|
|
2017-05-06 14:40:57 +00:00
|
|
|
#include <toml/utility.hpp>
|
|
|
|
#include <vector>
|
|
|
|
#include <array>
|
|
|
|
|
2020-03-27 09:06:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_try_reserve)
|
2017-05-06 14:40:57 +00:00
|
|
|
{
|
|
|
|
{
|
2020-03-27 09:06:02 +00:00
|
|
|
// since BOOST_TEST is a macro, it cannot handle commas correctly.
|
|
|
|
// When toml::detail::has_reserve_method<std::array<int, 1>>::value
|
|
|
|
// is passed to a macro, C preprocessor considers
|
|
|
|
// toml::detail::has_reserve_method<std::array<int as the first argument
|
|
|
|
// and 1>>::value as the second argument. We need an alias to avoid
|
|
|
|
// this problem.
|
|
|
|
using reservable_type = std::vector<int> ;
|
|
|
|
using nonreservable_type = std::array<int, 1>;
|
|
|
|
BOOST_TEST( toml::detail::has_reserve_method<reservable_type >::value);
|
|
|
|
BOOST_TEST(!toml::detail::has_reserve_method<nonreservable_type>::value);
|
2017-05-06 14:40:57 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
std::vector<int> v;
|
2020-03-27 09:06:02 +00:00
|
|
|
toml::try_reserve(v, 100);
|
|
|
|
BOOST_TEST(v.capacity() == 100u);
|
2017-05-06 14:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 10:22:41 +00:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_concat_to_string)
|
|
|
|
{
|
|
|
|
const std::string cat = toml::concat_to_string("foo", "bar", 42);
|
2019-06-21 06:00:41 +00:00
|
|
|
BOOST_TEST(cat == "foobar42");
|
2018-12-08 10:22:41 +00:00
|
|
|
}
|
2018-12-08 11:18:50 +00:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_from_string)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const std::string str("123");
|
2019-06-21 06:00:41 +00:00
|
|
|
BOOST_TEST(toml::from_string<int>(str, 0) == 123);
|
2018-12-08 11:18:50 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const std::string str("01");
|
2019-06-21 06:00:41 +00:00
|
|
|
BOOST_TEST(toml::from_string<int>(str, 0) == 1);
|
2018-12-08 11:18:50 +00:00
|
|
|
}
|
|
|
|
}
|