1 #define BOOST_TEST_MODULE "parse_datetime_test"
2 #ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
3 #include <boost/test/unit_test.hpp>
4 #else
5 #define BOOST_TEST_NO_LIB
6 #include <boost/test/included/unit_test.hpp>
7 #endif
8 #include <toml/parser.hpp>
9 #include "test_parse_aux.hpp"
10
11 using namespace toml;
12 using namespace detail;
13
BOOST_AUTO_TEST_CASE(test_time)14 BOOST_AUTO_TEST_CASE(test_time)
15 {
16 TOML11_TEST_PARSE_EQUAL(parse_local_time, "07:32:00", toml::local_time(7, 32, 0));
17 TOML11_TEST_PARSE_EQUAL(parse_local_time, "07:32:00.99", toml::local_time(7, 32, 0, 990, 0));
18 TOML11_TEST_PARSE_EQUAL(parse_local_time, "07:32:00.999", toml::local_time(7, 32, 0, 999, 0));
19 TOML11_TEST_PARSE_EQUAL(parse_local_time, "07:32:00.999999", toml::local_time(7, 32, 0, 999, 999));
20 }
21
BOOST_AUTO_TEST_CASE(test_time_value)22 BOOST_AUTO_TEST_CASE(test_time_value)
23 {
24 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "07:32:00", toml::value(toml::local_time(7, 32, 0)));
25 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "07:32:00.99", toml::value(toml::local_time(7, 32, 0, 990, 0)));
26 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "07:32:00.999", toml::value(toml::local_time(7, 32, 0, 999, 0)));
27 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "07:32:00.999999", toml::value(toml::local_time(7, 32, 0, 999, 999)));
28 }
29
BOOST_AUTO_TEST_CASE(test_date)30 BOOST_AUTO_TEST_CASE(test_date)
31 {
32 TOML11_TEST_PARSE_EQUAL(parse_local_date, "1979-05-27",
33 toml::local_date(1979, toml::month_t::May, 27));
34 }
BOOST_AUTO_TEST_CASE(test_date_value)35 BOOST_AUTO_TEST_CASE(test_date_value)
36 {
37 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27",
38 value(toml::local_date(1979, toml::month_t::May, 27)));
39 }
40
BOOST_AUTO_TEST_CASE(test_datetime)41 BOOST_AUTO_TEST_CASE(test_datetime)
42 {
43 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27T07:32:00",
44 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0)));
45 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27T07:32:00.99",
46 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0)));
47 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27T07:32:00.999999",
48 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999)));
49
50 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27t07:32:00",
51 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0)));
52 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27t07:32:00.99",
53 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0)));
54 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27t07:32:00.999999",
55 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999)));
56
57 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27 07:32:00",
58 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0)));
59 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27 07:32:00.99",
60 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0)));
61 TOML11_TEST_PARSE_EQUAL(parse_local_datetime, "1979-05-27 07:32:00.999999",
62 toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999)));
63 }
64
BOOST_AUTO_TEST_CASE(test_datetime_value)65 BOOST_AUTO_TEST_CASE(test_datetime_value)
66 {
67 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00",
68 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0))));
69 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.99",
70 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0))));
71 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.999999",
72 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999))));
73
74 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27t07:32:00",
75 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0))));
76 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27t07:32:00.99",
77 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0))));
78 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27t07:32:00.999999",
79 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999))));
80
81 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27 07:32:00",
82 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0))));
83 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27 07:32:00.99",
84 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 990, 0))));
85 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27 07:32:00.999999",
86 toml::value(toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27), toml::local_time(7, 32, 0, 999, 999))));
87 }
88
BOOST_AUTO_TEST_CASE(test_offset_datetime)89 BOOST_AUTO_TEST_CASE(test_offset_datetime)
90 {
91 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00Z",
92 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
93 toml::local_time(7, 32, 0), toml::time_offset(0, 0)));
94 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00.99Z",
95 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
96 toml::local_time(7, 32, 0, 990, 0), toml::time_offset(0, 0)));
97 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00.999999Z",
98 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
99 toml::local_time(7, 32, 0, 999, 999), toml::time_offset(0, 0)));
100
101 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00+09:00",
102 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
103 toml::local_time(7, 32, 0), toml::time_offset(9, 0)));
104 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00.99+09:00",
105 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
106 toml::local_time(7, 32, 0, 990, 0), toml::time_offset(9, 0)));
107 TOML11_TEST_PARSE_EQUAL(parse_offset_datetime, "1979-05-27T07:32:00.999999+09:00",
108 toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
109 toml::local_time(7, 32, 0, 999, 999), toml::time_offset(9, 0)));
110 }
111
BOOST_AUTO_TEST_CASE(test_offset_datetime_value)112 BOOST_AUTO_TEST_CASE(test_offset_datetime_value)
113 {
114 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00Z",
115 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
116 toml::local_time(7, 32, 0), toml::time_offset(0, 0))));
117 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.99Z",
118 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
119 toml::local_time(7, 32, 0, 990, 0), toml::time_offset(0, 0))));
120 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.999999Z",
121 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
122 toml::local_time(7, 32, 0, 999, 999), toml::time_offset(0, 0))));
123
124 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00+09:00",
125 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
126 toml::local_time(7, 32, 0), toml::time_offset(9, 0))));
127 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.99+09:00",
128 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
129 toml::local_time(7, 32, 0, 990, 0), toml::time_offset(9, 0))));
130 TOML11_TEST_PARSE_EQUAL_VALUE(parse_value<toml::value>, "1979-05-27T07:32:00.999999+09:00",
131 toml::value(toml::offset_datetime(toml::local_date(1979, toml::month_t::May, 27),
132 toml::local_time(7, 32, 0, 999, 999), toml::time_offset(9, 0))));
133 }
134