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


namespace {


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


    auto const c = suite.test("construct", []() {
        felspar::stdexcept::bad_alloc{};
        felspar::stdexcept::bad_alloc{"Error message"};
        felspar::stdexcept::bad_alloc{std::string{"Error message"}};
    });


    auto const t = suite.test("throw", [](auto check) {
        check([]() {
            throw felspar::stdexcept::bad_alloc{};
        }).throws(felspar::stdexcept::bad_alloc{});
        check([]() {
            throw felspar::stdexcept::bad_alloc{};
        }).template throws_type<std::bad_alloc>();
        check([]() {
            throw felspar::stdexcept::bad_alloc{"An error message"};
        }).throws(felspar::stdexcept::bad_alloc{"An error message"});
    });


}