[go: up one dir, main page]

File: test_utility.cpp

package info (click to toggle)
toml11 3.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,120 kB
  • sloc: cpp: 17,500; sh: 6; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define BOOST_TEST_MODULE "test_acceptor"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/utility.hpp>
#include <vector>
#include <array>

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);
    }
}