1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/AST/ASTContext.h" |
14 | #include "clang/AST/ASTVector.h" |
15 | #include "clang/Basic/Builtins.h" |
16 | #include "gtest/gtest.h" |
17 | |
18 | using namespace clang; |
19 | |
20 | namespace clang { |
21 | namespace ast { |
22 | |
23 | namespace { |
24 | class ASTVectorTest : public ::testing::Test { |
25 | protected: |
26 | ASTVectorTest() |
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) {} |
31 | |
32 | FileSystemOptions FileMgrOpts; |
33 | FileManager FileMgr; |
34 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID; |
35 | DiagnosticsEngine Diags; |
36 | SourceManager SourceMgr; |
37 | LangOptions LangOpts; |
38 | IdentifierTable Idents; |
39 | SelectorTable Sels; |
40 | Builtin::Context Builtins; |
41 | ASTContext Ctxt; |
42 | }; |
43 | } |
44 | |
45 | TEST_F(ASTVectorTest, Compile) { |
46 | ASTVector<int> V; |
47 | V.insert(Ctxt, V.begin(), 0); |
48 | } |
49 | |
50 | TEST_F(ASTVectorTest, InsertFill) { |
51 | ASTVector<double> V; |
52 | |
53 | |
54 | auto I = V.insert(Ctxt, V.begin(), 5, 1.0); |
55 | ASSERT_EQ(V.begin(), I); |
56 | |
57 | |
58 | I = V.insert(Ctxt, V.begin() + 1, 5, 1.0); |
59 | ASSERT_EQ(V.begin() + 1, I); |
60 | |
61 | |
62 | I = V.insert(Ctxt, V.end(), 5, 1.0); |
63 | ASSERT_EQ(V.end() - 5, I); |
64 | } |
65 | |
66 | TEST_F(ASTVectorTest, InsertEmpty) { |
67 | ASTVector<double> V; |
68 | |
69 | |
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()); |
75 | |
76 | |
77 | I = V.insert(Ctxt, V.begin(), IntVec.begin(), IntVec.end()); |
78 | ASSERT_EQ(V.begin(), I); |
79 | |
80 | |
81 | I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.begin()); |
82 | ASSERT_EQ(V.begin() + IntVec.size(), I); |
83 | |
84 | |
85 | I = V.insert(Ctxt, V.end(), IntVec.begin(), IntVec.end()); |
86 | ASSERT_EQ(V.begin() + IntVec.size(), I); |
87 | } |
88 | |
89 | } |
90 | } |
91 | |