// Copyright (C) 2017 Jonathan Müller // This file is subject to the license terms in the LICENSE file // found in the top-level directory of this distribution. #include #include "test_parser.hpp" using namespace cppast; TEST_CASE("cpp_alias_template") { // no need to check advanced types here nor template parameters auto code = R"( template using a = int; template using b = T; template using c = const T*; template using d = a; template using e = const b; template using f = b{(0,1)}, int>; template class Templ> using g = Templ; template using h = g; )"; cpp_entity_index idx; auto file = parse(idx, "cpp_alias_template.cpp", code); auto count = test_visit(*file, [&](const cpp_alias_template& alias) { if (alias.name() == "a") { check_template_parameters(alias, {{cpp_entity_kind::template_type_parameter_t, "T"}}); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *cpp_builtin_type::build("int"))); } else if (alias.name() == "b") { check_template_parameters(alias, {{cpp_entity_kind::non_type_template_parameter_t, "I"}, {cpp_entity_kind::template_type_parameter_t, "T"}}); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *cpp_template_parameter_type::build( cpp_template_type_parameter_ref(cpp_entity_id(""), "T")))); } else if (alias.name() == "c") { check_template_parameters(alias, {{cpp_entity_kind::template_type_parameter_t, "T"}}); auto param = cpp_template_parameter_type::build( cpp_template_type_parameter_ref(cpp_entity_id(""), "T")); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *cpp_pointer_type::build( cpp_cv_qualified_type::build(std::move(param), cpp_cv_const)))); } else if (alias.name() == "d") { check_template_parameters(alias, {{cpp_entity_kind::template_type_parameter_t, "T"}}); cpp_template_instantiation_type::builder builder( cpp_template_ref(cpp_entity_id(""), "a")); builder.add_unexposed_arguments("void"); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *builder.finish())); } else if (alias.name() == "e") { check_template_parameters(alias, {{cpp_entity_kind::non_type_template_parameter_t, "I"}}); cpp_template_instantiation_type::builder builder( cpp_template_ref(cpp_entity_id(""), "b")); builder.add_unexposed_arguments("I"); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *cpp_cv_qualified_type::build(builder.finish(), cpp_cv_const))); } else if (alias.name() == "f") { check_template_parameters(alias, {{cpp_entity_kind::non_type_template_parameter_t, "I"}}); cpp_template_instantiation_type::builder builder( cpp_template_ref(cpp_entity_id(""), "b")); builder.add_unexposed_arguments("I < a{(0 , 1)}, int"); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *builder.finish())); } else if (alias.name() == "g") { check_template_parameters(alias, {{cpp_entity_kind::template_type_parameter_t, "T"}, {cpp_entity_kind::template_template_parameter_t, "Templ"}}); cpp_template_instantiation_type::builder builder( cpp_template_ref(cpp_entity_id(""), "Templ")); builder.add_unexposed_arguments("T"); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *builder.finish())); } else if (alias.name() == "h") { check_template_parameters(alias, {{cpp_entity_kind::template_type_parameter_t, "T"}}); cpp_template_instantiation_type::builder builder( cpp_template_ref(cpp_entity_id(""), "g")); builder.add_unexposed_arguments("T, a"); REQUIRE(equal_types(idx, alias.type_alias().underlying_type(), *builder.finish())); } else REQUIRE(false); }); REQUIRE(count == 8u); }