//===- unittest/AST/ASTTypeTraits.cpp - AST type traits unit tests ------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===--------------------------------------------------------------------===// #include "clang/AST/ASTTypeTraits.h" #include "gtest/gtest.h" namespace clang { namespace ast_type_traits { TEST(ASTNodeKind, NoKind) { EXPECT_FALSE(ASTNodeKind().isBaseOf(ASTNodeKind())); EXPECT_FALSE(ASTNodeKind().isSame(ASTNodeKind())); } template static ASTNodeKind DNT() { return ASTNodeKind::getFromNodeKind(); } TEST(ASTNodeKind, Bases) { EXPECT_TRUE(DNT().isBaseOf(DNT())); EXPECT_FALSE(DNT().isSame(DNT())); EXPECT_FALSE(DNT().isBaseOf(DNT())); EXPECT_TRUE(DNT().isSame(DNT())); } TEST(ASTNodeKind, SameBase) { EXPECT_TRUE(DNT().isBaseOf(DNT())); EXPECT_TRUE(DNT().isBaseOf(DNT())); EXPECT_FALSE(DNT().isBaseOf(DNT())); EXPECT_FALSE(DNT().isBaseOf(DNT())); } TEST(ASTNodeKind, DiffBase) { EXPECT_FALSE(DNT().isBaseOf(DNT())); EXPECT_FALSE(DNT().isBaseOf(DNT())); EXPECT_FALSE(DNT().isSame(DNT())); } struct Foo {}; TEST(ASTNodeKind, UnknownKind) { // We can construct one, but it is nowhere in the hierarchy. EXPECT_FALSE(DNT().isSame(DNT())); } TEST(ASTNodeKind, Name) { EXPECT_EQ("Decl", DNT().asStringRef()); EXPECT_EQ("CallExpr", DNT().asStringRef()); EXPECT_EQ("ConstantArrayType", DNT().asStringRef()); EXPECT_EQ("", ASTNodeKind().asStringRef()); } } // namespace ast_type_traits } // namespace clang