Add test for static member variable

This commit is contained in:
Jonathan Müller 2017-03-02 16:22:16 +01:00
commit de2855820a
2 changed files with 35 additions and 0 deletions

View file

@ -14,6 +14,7 @@ namespace cppast
/// A [cppast::cpp_entity]() modelling a C++ variable.
/// \notes This is not a member variable,
/// use [cppast::cpp_member_variable]() for that.
/// But it can be `static` member variable.
class cpp_variable final : public cpp_entity, public cpp_variable_base
{
public:

View file

@ -109,3 +109,37 @@ static struct {} l;
});
REQUIRE(count == 12u);
}
TEST_CASE("static cpp_variable")
{
auto code = R"(
struct test
{
static int a;
static const int b;
static thread_local int c;
};
)";
auto file = parse({}, "static_cpp_variable.cpp", code);
auto count = test_visit<cpp_variable>(*file, [&](const cpp_variable& var) {
REQUIRE(!var.default_value());
REQUIRE(!var.is_constexpr());
REQUIRE(is_static(var.storage_class()));
if (var.name() == "a")
REQUIRE(equal_types({}, var.type(), *cpp_builtin_type::build("int")));
else if (var.name() == "b")
REQUIRE(equal_types({}, var.type(),
*cpp_cv_qualified_type::build(cpp_builtin_type::build("int"),
cpp_cv_const)));
else if (var.name() == "c")
{
REQUIRE(equal_types({}, var.type(), *cpp_builtin_type::build("int")));
REQUIRE(is_thread_local(var.storage_class()));
}
else
REQUIRE(false);
});
REQUIRE(count == 3u);
}