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/ASTVector.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/Basic/Builtins.h"
16 #include "clang/Basic/FileManager.h"
17 #include "clang/Basic/SourceManager.h"
18 #include "gtest/gtest.h"
20 using namespace clang
;
26 class ASTVectorTest
: public ::testing::Test
{
29 : FileMgr(FileMgrOpts
), DiagID(new DiagnosticIDs()),
30 Diags(DiagID
, new DiagnosticOptions
, new IgnoringDiagConsumer()),
31 SourceMgr(Diags
, FileMgr
), Idents(LangOpts
, nullptr),
32 Ctxt(LangOpts
, SourceMgr
, Idents
, Sels
, Builtins
, TU_Complete
) {}
34 FileSystemOptions FileMgrOpts
;
36 IntrusiveRefCntPtr
<DiagnosticIDs
> DiagID
;
37 DiagnosticsEngine Diags
;
38 SourceManager SourceMgr
;
40 IdentifierTable Idents
;
42 Builtin::Context Builtins
;
45 } // unnamed namespace
47 TEST_F(ASTVectorTest
, Compile
) {
49 V
.insert(Ctxt
, V
.begin(), 0);
52 TEST_F(ASTVectorTest
, InsertFill
) {
55 // Ensure returned iterator points to first of inserted elements
56 auto I
= V
.insert(Ctxt
, V
.begin(), 5, 1.0);
57 ASSERT_EQ(V
.begin(), I
);
59 // Check non-empty case as well
60 I
= V
.insert(Ctxt
, V
.begin() + 1, 5, 1.0);
61 ASSERT_EQ(V
.begin() + 1, I
);
64 I
= V
.insert(Ctxt
, V
.end(), 5, 1.0);
65 ASSERT_EQ(V
.end() - 5, I
);
68 TEST_F(ASTVectorTest
, InsertEmpty
) {
71 // Ensure no pointer overflow when inserting empty range
72 int Values
[] = { 0, 1, 2, 3 };
73 ArrayRef
<int> IntVec(Values
);
74 auto I
= V
.insert(Ctxt
, V
.begin(), IntVec
.begin(), IntVec
.begin());
75 ASSERT_EQ(V
.begin(), I
);
76 ASSERT_TRUE(V
.empty());
79 I
= V
.insert(Ctxt
, V
.begin(), IntVec
.begin(), IntVec
.end());
80 ASSERT_EQ(V
.begin(), I
);
82 // Non-Empty Vector, empty range
83 I
= V
.insert(Ctxt
, V
.end(), IntVec
.begin(), IntVec
.begin());
84 ASSERT_EQ(V
.begin() + IntVec
.size(), I
);
86 // Non-Empty Vector, non-empty range
87 I
= V
.insert(Ctxt
, V
.end(), IntVec
.begin(), IntVec
.end());
88 ASSERT_EQ(V
.begin() + IntVec
.size(), I
);
91 } // end namespace ast
92 } // end namespace clang