head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-9-5-RELEASE:1.1.1.4
	netbsd-11-0-RELEASE:1.1.1.5
	netbsd-11-0-RC7:1.1.1.5
	netbsd-11-0-RC6:1.1.1.5
	netbsd-11-0-RC5:1.1.1.5
	netbsd-11-0-RC4:1.1.1.5
	netbsd-11-0-RC3:1.1.1.5
	netbsd-11-0-RC2:1.1.1.5
	netbsd-11-0-RC1:1.1.1.5
	perseant-exfatfs-base-20250801:1.1.1.5
	netbsd-11:1.1.1.5.0.10
	netbsd-11-base:1.1.1.5
	netbsd-10-1-RELEASE:1.1.1.5
	perseant-exfatfs-base-20240630:1.1.1.5
	perseant-exfatfs:1.1.1.5.0.8
	perseant-exfatfs-base:1.1.1.5
	netbsd-8-3-RELEASE:1.1.1.3
	netbsd-9-4-RELEASE:1.1.1.4
	netbsd-10-0-RELEASE:1.1.1.5
	netbsd-10-0-RC6:1.1.1.5
	netbsd-10-0-RC5:1.1.1.5
	netbsd-10-0-RC4:1.1.1.5
	netbsd-10-0-RC3:1.1.1.5
	netbsd-10-0-RC2:1.1.1.5
	netbsd-10-0-RC1:1.1.1.5
	netbsd-10:1.1.1.5.0.6
	netbsd-10-base:1.1.1.5
	netbsd-9-3-RELEASE:1.1.1.4
	cjep_sun2x:1.1.1.5.0.4
	cjep_sun2x-base:1.1.1.5
	cjep_staticlib_x-base1:1.1.1.5
	netbsd-9-2-RELEASE:1.1.1.4
	cjep_staticlib_x:1.1.1.5.0.2
	cjep_staticlib_x-base:1.1.1.5
	netbsd-9-1-RELEASE:1.1.1.4
	phil-wifi-20200421:1.1.1.5
	phil-wifi-20200411:1.1.1.5
	phil-wifi-20200406:1.1.1.5
	netbsd-8-2-RELEASE:1.1.1.3
	netbsd-9-0-RELEASE:1.1.1.4
	netbsd-9-0-RC2:1.1.1.4
	netbsd-9-0-RC1:1.1.1.4
	netbsd-9:1.1.1.4.0.2
	netbsd-9-base:1.1.1.4
	phil-wifi-20190609:1.1.1.4
	netbsd-8-1-RELEASE:1.1.1.3
	netbsd-8-1-RC1:1.1.1.3
	pgoyette-compat-merge-20190127:1.1.1.3.14.1
	pgoyette-compat-20190127:1.1.1.4
	pgoyette-compat-20190118:1.1.1.4
	pgoyette-compat-1226:1.1.1.4
	pgoyette-compat-1126:1.1.1.4
	pgoyette-compat-1020:1.1.1.4
	pgoyette-compat-0930:1.1.1.4
	pgoyette-compat-0906:1.1.1.4
	netbsd-7-2-RELEASE:1.1.1.1.2.1
	pgoyette-compat-0728:1.1.1.4
	clang-337282:1.1.1.4
	netbsd-8-0-RELEASE:1.1.1.3
	phil-wifi:1.1.1.3.0.16
	phil-wifi-base:1.1.1.3
	pgoyette-compat-0625:1.1.1.3
	netbsd-8-0-RC2:1.1.1.3
	pgoyette-compat-0521:1.1.1.3
	pgoyette-compat-0502:1.1.1.3
	pgoyette-compat-0422:1.1.1.3
	netbsd-8-0-RC1:1.1.1.3
	pgoyette-compat-0415:1.1.1.3
	pgoyette-compat-0407:1.1.1.3
	pgoyette-compat-0330:1.1.1.3
	pgoyette-compat-0322:1.1.1.3
	pgoyette-compat-0315:1.1.1.3
	netbsd-7-1-2-RELEASE:1.1.1.1.2.1
	pgoyette-compat:1.1.1.3.0.14
	pgoyette-compat-base:1.1.1.3
	netbsd-7-1-1-RELEASE:1.1.1.1.2.1
	clang-319952:1.1.1.3
	matt-nb8-mediatek:1.1.1.3.0.12
	matt-nb8-mediatek-base:1.1.1.3
	clang-309604:1.1.1.3
	perseant-stdc-iso10646:1.1.1.3.0.10
	perseant-stdc-iso10646-base:1.1.1.3
	netbsd-8:1.1.1.3.0.8
	netbsd-8-base:1.1.1.3
	prg-localcount2-base3:1.1.1.3
	prg-localcount2-base2:1.1.1.3
	prg-localcount2-base1:1.1.1.3
	prg-localcount2:1.1.1.3.0.6
	prg-localcount2-base:1.1.1.3
	pgoyette-localcount-20170426:1.1.1.3
	bouyer-socketcan-base1:1.1.1.3
	pgoyette-localcount-20170320:1.1.1.3
	netbsd-7-1:1.1.1.1.2.1.0.6
	netbsd-7-1-RELEASE:1.1.1.1.2.1
	netbsd-7-1-RC2:1.1.1.1.2.1
	clang-294123:1.1.1.3
	netbsd-7-nhusb-base-20170116:1.1.1.1.2.1
	bouyer-socketcan:1.1.1.3.0.4
	bouyer-socketcan-base:1.1.1.3
	clang-291444:1.1.1.3
	pgoyette-localcount-20170107:1.1.1.3
	netbsd-7-1-RC1:1.1.1.1.2.1
	pgoyette-localcount-20161104:1.1.1.3
	netbsd-7-0-2-RELEASE:1.1.1.1.2.1
	localcount-20160914:1.1.1.3
	netbsd-7-nhusb:1.1.1.1.2.1.0.4
	netbsd-7-nhusb-base:1.1.1.1.2.1
	clang-280599:1.1.1.3
	pgoyette-localcount-20160806:1.1.1.3
	pgoyette-localcount-20160726:1.1.1.3
	pgoyette-localcount:1.1.1.3.0.2
	pgoyette-localcount-base:1.1.1.3
	netbsd-7-0-1-RELEASE:1.1.1.1.2.1
	clang-261930:1.1.1.3
	netbsd-7-0:1.1.1.1.2.1.0.2
	netbsd-7-0-RELEASE:1.1.1.1.2.1
	netbsd-7-0-RC3:1.1.1.1.2.1
	netbsd-7-0-RC2:1.1.1.1.2.1
	netbsd-7-0-RC1:1.1.1.1.2.1
	clang-237755:1.1.1.2
	clang-232565:1.1.1.2
	clang-227398:1.1.1.2
	tls-maxphys-base:1.1.1.1
	tls-maxphys:1.1.1.1.0.4
	netbsd-7:1.1.1.1.0.2
	netbsd-7-base:1.1.1.1
	clang-215315:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@// @;


1.1
date	2014.08.10.17.08.25;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	N85tXAN6Ex9VZPLx;

1.1.1.1
date	2014.08.10.17.08.25;	author joerg;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	1.1.1.2;
commitid	N85tXAN6Ex9VZPLx;

1.1.1.2
date	2015.01.29.19.57.28;	author joerg;	state Exp;
branches;
next	1.1.1.3;
commitid	mlISSizlPKvepX7y;

1.1.1.3
date	2016.02.27.22.11.43;	author joerg;	state Exp;
branches
	1.1.1.3.14.1
	1.1.1.3.16.1;
next	1.1.1.4;
commitid	tIimz3oDlh1NpBWy;

1.1.1.4
date	2018.07.17.18.32.13;	author joerg;	state Exp;
branches;
next	1.1.1.5;
commitid	wDzL46ALjrCZgwKA;

1.1.1.5
date	2019.11.13.22.23.09;	author joerg;	state dead;
branches;
next	;
commitid	QD8YATxuNG34YJKB;

1.1.1.1.2.1
date	2015.06.04.20.04.46;	author snj;	state Exp;
branches;
next	;
commitid	yRnjq9fueSo6n9oy;

1.1.1.1.4.1
date	2014.08.10.17.08.25;	author tls;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.1.4.2
date	2014.08.19.23.49.27;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.3.14.1
date	2018.07.28.04.34.17;	author pgoyette;	state Exp;
branches;
next	;
commitid	1UP1xAIUxv1ZgRLA;

1.1.1.3.16.1
date	2019.06.10.21.46.45;	author christos;	state Exp;
branches;
next	1.1.1.3.16.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.3.16.2
date	2020.04.13.07.50.37;	author martin;	state dead;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.1
log
@Initial revision
@
text
@//===- unittests/AST/NamedDeclPrinterTest.cpp --- NamedDecl printer tests -===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains tests for NamedDecl::printQualifiedName().
//
// These tests have a coding convention:
// * declaration to be printed is named 'A' unless it should have some special
// name (e.g., 'operator+');
// * additional helper declarations are 'Z', 'Y', 'X' and so on.
//
//===----------------------------------------------------------------------===//

#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
#include "gtest/gtest.h"

using namespace clang;
using namespace ast_matchers;
using namespace tooling;

namespace {

class PrintMatch : public MatchFinder::MatchCallback {
  SmallString<1024> Printed;
  unsigned NumFoundDecls;
  bool SuppressUnwrittenScope;

public:
  explicit PrintMatch(bool suppressUnwrittenScope)
    : NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope) {}

  virtual void run(const MatchFinder::MatchResult &Result) {
    const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("id");
    if (!ND)
      return;
    NumFoundDecls++;
    if (NumFoundDecls > 1)
      return;

    llvm::raw_svector_ostream Out(Printed);
    PrintingPolicy Policy = Result.Context->getPrintingPolicy();
    Policy.SuppressUnwrittenScope = SuppressUnwrittenScope;
    ND->printQualifiedName(Out, Policy);
  }

  StringRef getPrinted() const {
    return Printed;
  }

  unsigned getNumFoundDecls() const {
    return NumFoundDecls;
  }
};

::testing::AssertionResult
PrintedNamedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
                        bool SuppressUnwrittenScope,
                        const DeclarationMatcher &NodeMatch,
                        StringRef ExpectedPrinted, StringRef FileName) {
  PrintMatch Printer(SuppressUnwrittenScope);
  MatchFinder Finder;
  Finder.addMatcher(NodeMatch, &Printer);
  std::unique_ptr<FrontendActionFactory> Factory(
      newFrontendActionFactory(&Finder));

  if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName))
    return testing::AssertionFailure()
        << "Parsing error in \"" << Code.str() << "\"";

  if (Printer.getNumFoundDecls() == 0)
    return testing::AssertionFailure()
        << "Matcher didn't find any named declarations";

  if (Printer.getNumFoundDecls() > 1)
    return testing::AssertionFailure()
        << "Matcher should match only one named declaration "
           "(found " << Printer.getNumFoundDecls() << ")";

  if (Printer.getPrinted() != ExpectedPrinted)
    return ::testing::AssertionFailure()
        << "Expected \"" << ExpectedPrinted.str() << "\", "
           "got \"" << Printer.getPrinted().str() << "\"";

  return ::testing::AssertionSuccess();
}

::testing::AssertionResult
PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
                             StringRef ExpectedPrinted) {
  std::vector<std::string> Args(1, "-std=c++98");
  return PrintedNamedDeclMatches(Code,
                                 Args,
                                 /*SuppressUnwrittenScope*/ false,
                                 namedDecl(hasName(DeclName)).bind("id"),
                                 ExpectedPrinted,
                                 "input.cc");
}

::testing::AssertionResult
PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
                                    StringRef ExpectedPrinted) {
  std::vector<std::string> Args(1, "-std=c++11");
  return PrintedNamedDeclMatches(Code,
                                 Args,
                                 /*SuppressUnwrittenScope*/ true,
                                 namedDecl(hasName(DeclName)).bind("id"),
                                 ExpectedPrinted,
                                 "input.cc");
}

} // unnamed namespace

TEST(NamedDeclPrinter, TestNamespace1) {
  ASSERT_TRUE(PrintedNamedDeclCXX98Matches(
    "namespace { int A; }",
    "A",
    "(anonymous namespace)::A"));
}

TEST(NamedDeclPrinter, TestNamespace2) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "inline namespace Z { namespace { int A; } }",
    "A",
    "A"));
}
@


1.1.1.1
log
@Import clang 3.6svn r215315.
@
text
@@


1.1.1.1.2.1
log
@Update LLVM to 3.6.1, requested by joerg in ticket 824.
@
text
@d71 2
a72 2
  std::unique_ptr<FrontendActionFactory> Factory =
      newFrontendActionFactory(&Finder);
@


1.1.1.2
log
@Import Clang 3.6RC1 r227398.
@
text
@d71 2
a72 2
  std::unique_ptr<FrontendActionFactory> Factory =
      newFrontendActionFactory(&Finder);
@


1.1.1.3
log
@Import Clang 3.8.0rc3 r261930.
@
text
@d40 1
a40 1
  void run(const MatchFinder::MatchResult &Result) override {
a133 42

TEST(NamedDeclPrinter, TestUnscopedUnnamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "enum { A };",
    "A",
    "A"));
}

TEST(NamedDeclPrinter, TestNamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "enum X { A };",
    "A",
    "X::A"));
}

TEST(NamedDeclPrinter, TestScopedNamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "enum class X { A };",
    "A",
    "X::A"));
}

TEST(NamedDeclPrinter, TestClassWithUnscopedUnnamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "class X { enum { A }; };",
    "A",
    "X::A"));
}

TEST(NamedDeclPrinter, TestClassWithUnscopedNamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "class X { enum Y { A }; };",
    "A",
    "X::Y::A"));
}

TEST(NamedDeclPrinter, TestClassWithScopedNamedEnum) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "class X { enum class Y { A }; };",
    "A",
    "X::Y::A"));
}
@


1.1.1.3.16.1
log
@Sync with HEAD
@
text
@d146 1
a146 1
    "A"));
d167 1
a167 1
    "X::A"));
a175 7

TEST(NamedDeclPrinter, TestLinkageInNamespace) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "namespace X { extern \"C\" { int A; } }",
    "A",
    "X::A"));
}
@


1.1.1.3.16.2
log
@Mostly merge changes from HEAD upto 20200411
@
text
@@


1.1.1.3.14.1
log
@Sync with HEAD
@
text
@d146 1
a146 1
    "A"));
d167 1
a167 1
    "X::A"));
a175 7

TEST(NamedDeclPrinter, TestLinkageInNamespace) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "namespace X { extern \"C\" { int A; } }",
    "A",
    "X::A"));
}
@


1.1.1.4
log
@Import clang r337282 from trunk
@
text
@d146 1
a146 1
    "A"));
d167 1
a167 1
    "X::A"));
a175 7

TEST(NamedDeclPrinter, TestLinkageInNamespace) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "namespace X { extern \"C\" { int A; } }",
    "A",
    "X::A"));
}
@


1.1.1.5
log
@Mark old LLVM instance as dead.
@
text
@@


1.1.1.1.4.1
log
@file NamedDeclPrinterTest.cpp was added on branch tls-maxphys on 2014-08-19 23:49:27 +0000
@
text
@d1 133
@


1.1.1.1.4.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 133
//===- unittests/AST/NamedDeclPrinterTest.cpp --- NamedDecl printer tests -===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains tests for NamedDecl::printQualifiedName().
//
// These tests have a coding convention:
// * declaration to be printed is named 'A' unless it should have some special
// name (e.g., 'operator+');
// * additional helper declarations are 'Z', 'Y', 'X' and so on.
//
//===----------------------------------------------------------------------===//

#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
#include "gtest/gtest.h"

using namespace clang;
using namespace ast_matchers;
using namespace tooling;

namespace {

class PrintMatch : public MatchFinder::MatchCallback {
  SmallString<1024> Printed;
  unsigned NumFoundDecls;
  bool SuppressUnwrittenScope;

public:
  explicit PrintMatch(bool suppressUnwrittenScope)
    : NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope) {}

  virtual void run(const MatchFinder::MatchResult &Result) {
    const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("id");
    if (!ND)
      return;
    NumFoundDecls++;
    if (NumFoundDecls > 1)
      return;

    llvm::raw_svector_ostream Out(Printed);
    PrintingPolicy Policy = Result.Context->getPrintingPolicy();
    Policy.SuppressUnwrittenScope = SuppressUnwrittenScope;
    ND->printQualifiedName(Out, Policy);
  }

  StringRef getPrinted() const {
    return Printed;
  }

  unsigned getNumFoundDecls() const {
    return NumFoundDecls;
  }
};

::testing::AssertionResult
PrintedNamedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
                        bool SuppressUnwrittenScope,
                        const DeclarationMatcher &NodeMatch,
                        StringRef ExpectedPrinted, StringRef FileName) {
  PrintMatch Printer(SuppressUnwrittenScope);
  MatchFinder Finder;
  Finder.addMatcher(NodeMatch, &Printer);
  std::unique_ptr<FrontendActionFactory> Factory(
      newFrontendActionFactory(&Finder));

  if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName))
    return testing::AssertionFailure()
        << "Parsing error in \"" << Code.str() << "\"";

  if (Printer.getNumFoundDecls() == 0)
    return testing::AssertionFailure()
        << "Matcher didn't find any named declarations";

  if (Printer.getNumFoundDecls() > 1)
    return testing::AssertionFailure()
        << "Matcher should match only one named declaration "
           "(found " << Printer.getNumFoundDecls() << ")";

  if (Printer.getPrinted() != ExpectedPrinted)
    return ::testing::AssertionFailure()
        << "Expected \"" << ExpectedPrinted.str() << "\", "
           "got \"" << Printer.getPrinted().str() << "\"";

  return ::testing::AssertionSuccess();
}

::testing::AssertionResult
PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
                             StringRef ExpectedPrinted) {
  std::vector<std::string> Args(1, "-std=c++98");
  return PrintedNamedDeclMatches(Code,
                                 Args,
                                 /*SuppressUnwrittenScope*/ false,
                                 namedDecl(hasName(DeclName)).bind("id"),
                                 ExpectedPrinted,
                                 "input.cc");
}

::testing::AssertionResult
PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
                                    StringRef ExpectedPrinted) {
  std::vector<std::string> Args(1, "-std=c++11");
  return PrintedNamedDeclMatches(Code,
                                 Args,
                                 /*SuppressUnwrittenScope*/ true,
                                 namedDecl(hasName(DeclName)).bind("id"),
                                 ExpectedPrinted,
                                 "input.cc");
}

} // unnamed namespace

TEST(NamedDeclPrinter, TestNamespace1) {
  ASSERT_TRUE(PrintedNamedDeclCXX98Matches(
    "namespace { int A; }",
    "A",
    "(anonymous namespace)::A"));
}

TEST(NamedDeclPrinter, TestNamespace2) {
  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
    "inline namespace Z { namespace { int A; } }",
    "A",
    "A"));
}
@


