File: test_error_message.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 (79 lines) | stat: -rw-r--r-- 2,805 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
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

#include <toml.hpp>

TEST_CASE("testing custom error message using source_location")
{
    const toml::value root = toml::parse_str(R"(
        range = [0, 42]
        val = 54
    )");

    const auto& lower = root.at("range").at(0);
    const auto& upper = root.at("range").at(1);
    const auto& val = root.at("val");

    const auto err = toml::make_error_info("val not in range",
            lower.location(), "lower limit is defined here",
            upper.location(), "upper limit is defined here",
            val.location(),   "this is not in the range",
            "Hint: upper limit is inclusive"
        );

    CHECK_EQ(err.title(), "val not in range");
    CHECK_EQ(err.locations().size(), 3);
    CHECK_EQ(err.locations().at(0).second, "lower limit is defined here");
    CHECK_EQ(err.locations().at(1).second, "upper limit is defined here");
    CHECK_EQ(err.locations().at(2).second, "this is not in the range"   );
}

TEST_CASE("testing custom error message using value")
{
    const toml::value root = toml::parse_str(R"(
        range = [0, 42]
        val = 54
    )");

    const auto& lower = root.at("range").at(0);
    const auto& upper = root.at("range").at(1);
    const auto& val = root.at("val");

    const auto err = toml::make_error_info("val not in range",
            lower, "lower limit is defined here",
            upper, "upper limit is defined here",
            val,   "this is not in the range",
            "Hint: upper limit is inclusive"
        );

    CHECK_EQ(err.title(), "val not in range");
    CHECK_EQ(err.locations().size(), 3);
    CHECK_EQ(err.locations().at(0).second, "lower limit is defined here");
    CHECK_EQ(err.locations().at(1).second, "upper limit is defined here");
    CHECK_EQ(err.locations().at(2).second, "this is not in the range"   );
}

TEST_CASE("testing custom error message using source_location and value")
{
    const toml::value root = toml::parse_str(R"(
        range = [0, 42]
        val = 54
    )");

    const auto& lower = root.at("range").at(0);
    const auto& upper = root.at("range").at(1);
    const auto& val = root.at("val");

    const auto err = toml::make_error_info("val not in range",
            lower,          "lower limit is defined here",
            upper,          "upper limit is defined here",
            val.location(), "this is not in the range",
            "Hint: upper limit is inclusive"
        );

    CHECK_EQ(err.title(), "val not in range");
    CHECK_EQ(err.locations().size(), 3);
    CHECK_EQ(err.locations().at(0).second, "lower limit is defined here");
    CHECK_EQ(err.locations().at(1).second, "upper limit is defined here");
    CHECK_EQ(err.locations().at(2).second, "this is not in the range"   );
}