Add and parse cpp_static_assert
This commit is contained in:
parent
d125869df5
commit
4db09778b5
14 changed files with 200 additions and 6 deletions
|
|
@ -22,6 +22,7 @@ set(tests
|
|||
cpp_member_variable.cpp
|
||||
cpp_namespace.cpp
|
||||
cpp_preprocessor.cpp
|
||||
cpp_static_assert.cpp
|
||||
cpp_template_parameter.cpp
|
||||
cpp_type_alias.cpp
|
||||
cpp_variable.cpp)
|
||||
|
|
|
|||
47
test/cpp_static_assert.cpp
Normal file
47
test/cpp_static_assert.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
|
||||
// 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),
|
||||
"true||false")));
|
||||
else if (assert.message() == "b")
|
||||
REQUIRE(equal_expressions(assert.expression(),
|
||||
*cpp_unexposed_expression::build(std::move(bool_t), "!B")));
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
REQUIRE(count == 3u);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue