Parse cpp_namespace

This commit is contained in:
Jonathan Müller 2017-02-21 22:36:38 +01:00
commit ce69b0157f
11 changed files with 160 additions and 16 deletions

53
test/cpp_namespace.cpp Normal file
View file

@ -0,0 +1,53 @@
// 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_namespace.hpp>
#include "test_parser.hpp"
using namespace cppast;
TEST_CASE("cpp_namespace")
{
auto code = R"(
namespace a {}
inline namespace b {}
namespace c
{
namespace d {}
}
)";
auto file = parse({}, "cpp_namespace.cpp", code);
auto count = test_visit<cpp_namespace>(*file, [&](const cpp_namespace& ns) {
auto no_children = count_children(ns);
if (ns.name() == "a")
{
REQUIRE(!ns.is_inline());
REQUIRE(no_children == 0u);
}
else if (ns.name() == "b")
{
REQUIRE(ns.is_inline());
REQUIRE(no_children == 0u);
}
else if (ns.name() == "c")
{
REQUIRE(!ns.is_inline());
REQUIRE(no_children == 1u);
}
else if (ns.name() == "d")
{
REQUIRE(ns.parent());
REQUIRE(ns.parent().value().name() == "c");
REQUIRE(!ns.is_inline());
REQUIRE(no_children == 0u);
}
else
REQUIRE(false);
});
REQUIRE(count == 4u);
}