From 895ac5d0c9268d5981b22d20b0969ad026472c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Thu, 23 Feb 2017 20:32:32 +0100 Subject: [PATCH] Add test for cpp_language_linkage --- test/cpp_language_linkage.cpp | 51 ++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/test/cpp_language_linkage.cpp b/test/cpp_language_linkage.cpp index 5a1b475..e786be6 100644 --- a/test/cpp_language_linkage.cpp +++ b/test/cpp_language_linkage.cpp @@ -2,11 +2,60 @@ // This file is subject to the license terms in the LICENSE file // found in the top-level directory of this distribution. +#include + +#include + #include "test_parser.hpp" using namespace cppast; TEST_CASE("cpp_language_linkage") { - // TODO: need actual entities to parse + auto code = R"( +extern "C" enum a {}; + +enum b {}; + +extern "C++" // yup +{ + enum c {}; + enum d {}; + enum e {}; +} + +enum f {}; +)"; + + auto file = parse({}, "cpp_language_linkage.cpp", code); + + // check linkages + auto count = test_visit(*file, [&](const cpp_language_linkage& linkage) { + if (linkage.name() == "\"C\"") + REQUIRE(!linkage.is_block()); + else if (linkage.name() == "\"C++\"") + REQUIRE(linkage.is_block()); + else + REQUIRE(false); + }); + REQUIRE(count == 2u); + + // check enums for their correct parent + count = test_visit(*file, [&](const cpp_enum& e) { + if (e.name() == "a") + check_parent(e, "\"C\"", "a"); + else if (e.name() == "b") + check_parent(e, "cpp_language_linkage.cpp", "b"); + else if (e.name() == "c") + check_parent(e, "\"C++\"", "c"); + else if (e.name() == "d") + check_parent(e, "\"C++\"", "d"); + else if (e.name() == "e") + check_parent(e, "\"C++\"", "e"); + else if (e.name() == "f") + check_parent(e, "cpp_language_linkage.cpp", "f"); + else + REQUIRE(false); + }); + REQUIRE(count == 6u); }