mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-08 13:50:06 +00:00
10fd14f8b9
This patch consistently changes the inclusion order for unit test files to the following: 1. The header of the unit under test (using <> includes). 2. The unit_test.hpp header (using "" includes). 3. Any additional auxiliary test headers (using "" includes and sorted alphabetically). 4. Additional system headers needed for the test (using <> includes and sorted alphabetically). 5. Conditionally included system headers (using <> includes). Putting the unit under test's header at the very beginning has the advantage of also testing that the header is self-contained. It also makes it very quick to tell what unit is tested in this file.
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include <toml/utility.hpp>
|
|
|
|
#include "unit_test.hpp"
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
|
|
BOOST_AUTO_TEST_CASE(test_try_reserve)
|
|
{
|
|
{
|
|
// 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);
|
|
}
|
|
{
|
|
std::vector<int> v;
|
|
toml::try_reserve(v, 100);
|
|
BOOST_TEST(v.capacity() == 100u);
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_concat_to_string)
|
|
{
|
|
const std::string cat = toml::concat_to_string("foo", "bar", 42);
|
|
BOOST_TEST(cat == "foobar42");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_from_string)
|
|
{
|
|
{
|
|
const std::string str("123");
|
|
BOOST_TEST(toml::from_string<int>(str, 0) == 123);
|
|
}
|
|
{
|
|
const std::string str("01");
|
|
BOOST_TEST(toml::from_string<int>(str, 0) == 1);
|
|
}
|
|
}
|