1 //===- unittests/AST/DeclTest.cpp --- Declaration tests -------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Unit tests for the ASTVector container.
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/ASTVector.h"
15 #include "clang/Basic/Builtins.h"
16 #include "gtest/gtest.h"
18 using namespace clang;
24 class ASTVectorTest : public ::testing::Test {
27 : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
28 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
29 SourceMgr(Diags, FileMgr), Idents(LangOpts, nullptr),
30 Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins) {}
32 FileSystemOptions FileMgrOpts;
34 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
35 DiagnosticsEngine Diags;
36 SourceManager SourceMgr;
38 IdentifierTable Idents;
40 Builtin::Context Builtins;
43 } // unnamed namespace
45 TEST_F(ASTVectorTest, Compile) {
47 V.insert(Ctxt, V.begin(), 0);
50 TEST_F(ASTVectorTest, InsertFill) {
53 // Ensure returned iterator points to first of inserted elements
54 auto I = V.insert(Ctxt, V.begin(), 5, 1.0);
55 ASSERT_EQ(V.begin(), I);
57 // Check non-empty case as well
58 I = V.insert(Ctxt, V.begin() + 1, 5, 1.0);
59 ASSERT_EQ(V.begin() + 1, I);
62 I = V.insert(Ctxt, V.end(), 5, 1.0);
63 ASSERT_EQ(V.end() - 5, I);
66 TEST_F(ASTVectorTest, InsertEmpty) {
69 // Ensure no pointer overflow when inserting empty range
70 int Values[] = { 0, 1, 2, 3 };
71 ArrayRef<int> IntVec(Values);
72 auto I = V.insert(Ctxt, V.begin(), IntVec.begin(), IntVec.begin());
73 ASSERT_EQ(V.begin(), I);
74 ASSERT_TRUE(V.empty());
77 I = V.insert(Ctxt, V.begin(), IntVec.begin(), IntVec.end());
78 ASSERT_EQ(V.begin(), I);
80 // Non-Empty Vector, empty range
81 I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.begin());
82 ASSERT_EQ(V.begin() + IntVec.size(), I);
84 // Non-Empty Vector, non-empty range
85 I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.end());
86 ASSERT_EQ(V.begin() + IntVec.size(), I);
89 } // end namespace ast
90 } // end namespace clang