forked from standardese/cppast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_static_assert.cpp
More file actions
50 lines (43 loc) · 1.87 KB
/
Copy pathcpp_static_assert.cpp
File metadata and controls
50 lines (43 loc) · 1.87 KB
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
// Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <cppast/cpp_static_assert.hpp>
#include "test_parser.hpp"
using namespace cppast;
TEST_CASE("cpp_static_assert")
{
auto code = R"(
/// static_assert(true,"");
static_assert(true, "");
/// static_assert(true||false,"a");
static_assert(true || false, "a");
template <bool B>
struct foo
{
/// static_assert(!B,"b");
static_assert(!B, "b");
};
)";
cpp_entity_index idx;
auto file = parse(idx, "cpp_static_assert.cpp", code);
auto count = test_visit<cpp_static_assert>(*file, [&](const cpp_static_assert& assert) {
auto bool_t = cpp_builtin_type::build(cpp_builtin_type_kind::cpp_bool);
REQUIRE(assert.name().empty());
if (assert.message() == "")
REQUIRE(equal_expressions(assert.expression(),
*cpp_literal_expression::build(std::move(bool_t), "true")));
else if (assert.message() == "a")
REQUIRE(equal_expressions(assert.expression(),
*cpp_unexposed_expression::build(std::move(bool_t),
cpp_token_string::tokenize(
"true||false"))));
else if (assert.message() == "b")
REQUIRE(equal_expressions(assert.expression(),
*cpp_unexposed_expression::build(std::move(bool_t),
cpp_token_string::tokenize(
"!B"))));
else
REQUIRE(false);
});
REQUIRE(count == 3u);
}