Add and parse cpp_static_assert

This commit is contained in:
Jonathan Müller 2017-04-11 20:21:25 +02:00
commit 4db09778b5
14 changed files with 200 additions and 6 deletions

View 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);
}