underflow.cpp

 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
#include <felspar/test.hpp>
#include <felspar/exceptions.hpp>


namespace {


    auto const suite = felspar::testsuite("underflow");


    auto const c = suite.test("construct", []() {
        felspar::stdexcept::underflow_error{
                "Some text", felspar::source_location::current()};
        felspar::stdexcept::underflow_error{
                "Some text", 4.5, 6.0, felspar::source_location::current()};
    });


    auto const v = suite.test("void", [](auto check) {
        check([]() {
            throw felspar::stdexcept::underflow_error{
                    std::string{"Some error"}};
        }).throws(felspar::stdexcept::underflow_error{"Some error"});
        check([]() { throw felspar::stdexcept::underflow_error{"Some error"}; })
                .throws(felspar::stdexcept::underflow_error{
                        std::string{"Some error"}});
    });


    auto const i = suite.test("int", [](auto check) {
        check([]() {
            throw felspar::stdexcept::underflow_error{
                    std::string{"Too small"}, 3};
        }).throws(felspar::stdexcept::underflow_error<int>{"Too small"});
        check([]() {
            throw felspar::stdexcept::underflow_error{
                    std::string{"Too few items"}, 4, 6};
        }).throws(felspar::stdexcept::underflow_error<int>{"Too few items"});
    });


}