File: test_parse_boolean.cpp

package info (click to toggle)
toml11 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,464 kB
  • sloc: cpp: 38,446; makefile: 8; sh: 5
file content (44 lines) | stat: -rw-r--r-- 1,336 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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

#include "utility.hpp"

#include <toml11/parser.hpp>
#include <toml11/types.hpp>

TEST_CASE("testing valid boolean")
{
    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);
    }
}

TEST_CASE("testing invalid boolean")
{
    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);
}