diff options
Diffstat (limited to 'unittests/AST')
-rw-r--r-- | unittests/AST/ASTTypeTraitsTest.cpp | 62 | ||||
-rw-r--r-- | unittests/AST/CMakeLists.txt | 1 |
2 files changed, 63 insertions, 0 deletions
diff --git a/unittests/AST/ASTTypeTraitsTest.cpp b/unittests/AST/ASTTypeTraitsTest.cpp new file mode 100644 index 0000000000..5e3abe25d1 --- /dev/null +++ b/unittests/AST/ASTTypeTraitsTest.cpp @@ -0,0 +1,62 @@ +//===- 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 <typename T> static ASTNodeKind DNT() { + return ASTNodeKind::getFromNodeKind<T>(); +} + +TEST(ASTNodeKind, Bases) { + EXPECT_TRUE(DNT<Decl>().isBaseOf(DNT<VarDecl>())); + EXPECT_FALSE(DNT<Decl>().isSame(DNT<VarDecl>())); + EXPECT_FALSE(DNT<VarDecl>().isBaseOf(DNT<Decl>())); + + EXPECT_TRUE(DNT<Decl>().isSame(DNT<Decl>())); +} + +TEST(ASTNodeKind, SameBase) { + EXPECT_TRUE(DNT<Expr>().isBaseOf(DNT<CallExpr>())); + EXPECT_TRUE(DNT<Expr>().isBaseOf(DNT<BinaryOperator>())); + EXPECT_FALSE(DNT<CallExpr>().isBaseOf(DNT<BinaryOperator>())); + EXPECT_FALSE(DNT<BinaryOperator>().isBaseOf(DNT<CallExpr>())); +} + +TEST(ASTNodeKind, DiffBase) { + EXPECT_FALSE(DNT<Expr>().isBaseOf(DNT<ArrayType>())); + EXPECT_FALSE(DNT<QualType>().isBaseOf(DNT<FunctionDecl>())); + EXPECT_FALSE(DNT<Type>().isSame(DNT<QualType>())); +} + +struct Foo {}; + +TEST(ASTNodeKind, UnknownKind) { + // We can construct one, but it is nowhere in the hierarchy. + EXPECT_FALSE(DNT<Foo>().isSame(DNT<Foo>())); +} + +TEST(ASTNodeKind, Name) { + EXPECT_EQ("Decl", DNT<Decl>().asStringRef()); + EXPECT_EQ("CallExpr", DNT<CallExpr>().asStringRef()); + EXPECT_EQ("ConstantArrayType", DNT<ConstantArrayType>().asStringRef()); + EXPECT_EQ("<None>", ASTNodeKind().asStringRef()); +} + +} // namespace ast_type_traits +} // namespace clang diff --git a/unittests/AST/CMakeLists.txt b/unittests/AST/CMakeLists.txt index 3ef2a5e153..c414ae3b23 100644 --- a/unittests/AST/CMakeLists.txt +++ b/unittests/AST/CMakeLists.txt @@ -1,5 +1,6 @@ add_clang_unittest(ASTTests ASTContextParentMapTest.cpp + ASTTypeTraitsTest.cpp CommentLexer.cpp CommentParser.cpp DeclPrinterTest.cpp |