Files
toml11/tests/test_parse_boolean.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

2024-06-15 19:14:06 +09:00
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
2024-06-15 19:14:06 +09:00
#include "utility.hpp"
2018-12-11 21:51:39 +09:00
2024-06-15 19:14:06 +09:00
#include <toml11/parser.hpp>
#include <toml11/types.hpp>
2018-12-11 21:51:39 +09:00
2024-06-15 19:14:06 +09:00
TEST_CASE("testing valid boolean")
2018-12-11 21:51:39 +09:00
{
2024-06-15 19:14:06 +09:00
const toml::detail::context<toml::type_config> ctx(toml::spec::v(1,0,0));
{
auto loc = toml::detail::make_temporary_location("true");
const auto res = toml::detail::parse_boolean(loc, ctx);
REQUIRE_UNARY(res.is_ok());
const auto val = res.unwrap();
REQUIRE_UNARY(val.is_boolean());
CHECK_EQ(val.as_boolean(), true);
}
{
auto loc = toml::detail::make_temporary_location("false");
const auto res = toml::detail::parse_boolean(loc, ctx);
REQUIRE_UNARY(res.is_ok());
const auto val = res.unwrap();
REQUIRE_UNARY(val.is_boolean());
CHECK_EQ(val.as_boolean(), false);
}
2018-12-11 21:51:39 +09:00
}
2024-06-15 19:14:06 +09:00
TEST_CASE("testing invalid boolean")
2018-12-11 21:51:39 +09:00
{
2024-06-15 19:14:06 +09:00
using namespace toml::detail;
const context<toml::type_config> ctx(toml::spec::v(1,0,0));
toml11_test_parse_failure(parse_boolean<toml::type_config>, "True", ctx);
toml11_test_parse_failure(parse_boolean<toml::type_config>, "TRUE", ctx);
toml11_test_parse_failure(parse_boolean<toml::type_config>, "False", ctx);
toml11_test_parse_failure(parse_boolean<toml::type_config>, "FALSE", ctx);
2018-12-11 21:51:39 +09:00
}