Home | History | Annotate | Download | only in AST
      1 //===- unittest/AST/ASTTypeTraits.cpp - AST type traits unit tests ------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===--------------------------------------------------------------------===//
      9 
     10 
     11 #include "clang/AST/ASTTypeTraits.h"
     12 #include "gtest/gtest.h"
     13 
     14 namespace clang {
     15 namespace ast_type_traits {
     16 
     17 TEST(ASTNodeKind, NoKind) {
     18   EXPECT_FALSE(ASTNodeKind().isBaseOf(ASTNodeKind()));
     19   EXPECT_FALSE(ASTNodeKind().isSame(ASTNodeKind()));
     20 }
     21 
     22 template <typename T> static ASTNodeKind DNT() {
     23   return ASTNodeKind::getFromNodeKind<T>();
     24 }
     25 
     26 TEST(ASTNodeKind, Bases) {
     27   EXPECT_TRUE(DNT<Decl>().isBaseOf(DNT<VarDecl>()));
     28   EXPECT_FALSE(DNT<Decl>().isSame(DNT<VarDecl>()));
     29   EXPECT_FALSE(DNT<VarDecl>().isBaseOf(DNT<Decl>()));
     30 
     31   EXPECT_TRUE(DNT<Decl>().isSame(DNT<Decl>()));
     32 }
     33 
     34 TEST(ASTNodeKind, SameBase) {
     35   EXPECT_TRUE(DNT<Expr>().isBaseOf(DNT<CallExpr>()));
     36   EXPECT_TRUE(DNT<Expr>().isBaseOf(DNT<BinaryOperator>()));
     37   EXPECT_FALSE(DNT<CallExpr>().isBaseOf(DNT<BinaryOperator>()));
     38   EXPECT_FALSE(DNT<BinaryOperator>().isBaseOf(DNT<CallExpr>()));
     39 }
     40 
     41 TEST(ASTNodeKind, DiffBase) {
     42   EXPECT_FALSE(DNT<Expr>().isBaseOf(DNT<ArrayType>()));
     43   EXPECT_FALSE(DNT<QualType>().isBaseOf(DNT<FunctionDecl>()));
     44   EXPECT_FALSE(DNT<Type>().isSame(DNT<QualType>()));
     45 }
     46 
     47 struct Foo {};
     48 
     49 TEST(ASTNodeKind, UnknownKind) {
     50   // We can construct one, but it is nowhere in the hierarchy.
     51   EXPECT_FALSE(DNT<Foo>().isSame(DNT<Foo>()));
     52 }
     53 
     54 TEST(ASTNodeKind, Name) {
     55   EXPECT_EQ("Decl", DNT<Decl>().asStringRef());
     56   EXPECT_EQ("CallExpr", DNT<CallExpr>().asStringRef());
     57   EXPECT_EQ("ConstantArrayType", DNT<ConstantArrayType>().asStringRef());
     58   EXPECT_EQ("<None>", ASTNodeKind().asStringRef());
     59 }
     60 
     61 }  // namespace ast_type_traits
     62 }  // namespace clang
     63