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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include "utility.hpp"
#include <toml11/parser.hpp>
TEST_CASE("testing offset_datetime")
{
const auto fmt = [](toml::datetime_delimiter_kind d, bool has_sec, std::size_t prec) {
toml::offset_datetime_format_info f;
f.delimiter = d;
f.has_seconds = has_sec;
f.subsecond_precision = prec;
return f;
};
{
toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00.999999-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 999)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 6), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00.999999-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 999)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 6), ctx);
}
{
auto spec = toml::spec::v(1,0,0);
spec.v1_1_0_make_seconds_optional = true;
toml::detail::context<toml::type_config> ctx(spec);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, false, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27T07:32:00.999999-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 999)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 6), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, false, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00Z",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(0, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::offset_datetime>(
"1979-05-27 07:32:00.999999-07:00",
toml::offset_datetime(
toml::local_datetime(
toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 999)
),
toml::time_offset(-7, 0)
),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 6), ctx);
}
}
TEST_CASE("testing local_datetime")
{
const auto fmt = [](toml::datetime_delimiter_kind d, bool has_sec, std::size_t prec) {
toml::local_datetime_format_info f;
f.delimiter = d;
f.has_seconds = has_sec;
f.subsecond_precision = prec;
return f;
};
{
toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27T07:32:00",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27T07:32:00.9999",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 900, 0)),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 4), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27 07:32:00",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27 07:32:00.9999",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 900, 0)),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 4), ctx);
}
{
auto spec = toml::spec::v(1,0,0);
spec.v1_1_0_make_seconds_optional = true;
toml::detail::context<toml::type_config> ctx(spec);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27T07:32",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, false, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27T07:32:00",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27T07:32:00.9999",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 900, 0)),
comments(), fmt(toml::datetime_delimiter_kind::upper_T, true, 4), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27 07:32",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::space, false, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27 07:32:00",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0)),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_datetime>( "1979-05-27 07:32:00.9999",
toml::local_datetime(toml::local_date(1979, toml::month_t::May, 27),
toml::local_time(7, 32, 0, 999, 900, 0)),
comments(), fmt(toml::datetime_delimiter_kind::space, true, 4), ctx);
}
}
TEST_CASE("testing local_date")
{
toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
toml11_test_parse_success<toml::value_t::local_date>("1979-05-27", toml::local_date(1979, toml::month_t::May, 27), comments(), toml::local_date_format_info{}, ctx);
toml11_test_parse_success<toml::value_t::local_date>("0979-12-27", toml::local_date( 979, toml::month_t::Dec, 27), comments(), toml::local_date_format_info{}, ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-00-27", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-13-27", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-05-00", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-05-32", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-05-2", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-5-02", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "1979-5-2", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "979-5-2", ctx);
toml11_test_parse_failure(toml::detail::parse_local_date<toml::type_config>, "12345-05-27", ctx);
}
TEST_CASE("testing local_time")
{
const auto fmt = [](const bool has_sec, const std::size_t sec_prec) {
toml::local_time_format_info f;
f.has_seconds = has_sec;
f.subsecond_precision = sec_prec;
return f;
};
{
toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
toml11_test_parse_success<toml::value_t::local_time>("01:02:03", toml::local_time(1, 2, 3), comments(), fmt(true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45", toml::local_time(1, 23, 45), comments(), fmt(true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1", toml::local_time(1, 23, 45, 100), comments(), fmt(true, 1), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.12", toml::local_time(1, 23, 45, 120), comments(), fmt(true, 2), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.123", toml::local_time(1, 23, 45, 123), comments(), fmt(true, 3), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1234", toml::local_time(1, 23, 45, 123, 400), comments(), fmt(true, 4), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1234567", toml::local_time(1, 23, 45, 123, 456, 700), comments(), fmt(true, 7), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.123456789", toml::local_time(1, 23, 45, 123, 456, 789), comments(), fmt(true, 9), ctx);
}
{
auto spec = toml::spec::v(1,0,0);
spec.v1_1_0_make_seconds_optional = true;
toml::detail::context<toml::type_config> ctx(spec);
toml11_test_parse_success<toml::value_t::local_time>("01:23", toml::local_time(1, 23, 0), comments(), fmt(false, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:02", toml::local_time(1, 2, 0), comments(), fmt(false, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:02:03", toml::local_time(1, 2, 3), comments(), fmt(true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45", toml::local_time(1, 23, 45), comments(), fmt(true, 0), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1", toml::local_time(1, 23, 45, 100), comments(), fmt(true, 1), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.12", toml::local_time(1, 23, 45, 120), comments(), fmt(true, 2), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.123", toml::local_time(1, 23, 45, 123), comments(), fmt(true, 3), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1234", toml::local_time(1, 23, 45, 123, 400), comments(), fmt(true, 4), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.1234567", toml::local_time(1, 23, 45, 123, 456, 700), comments(), fmt(true, 7), ctx);
toml11_test_parse_success<toml::value_t::local_time>("01:23:45.123456789", toml::local_time(1, 23, 45, 123, 456, 789), comments(), fmt(true, 9), ctx);
}
}
|