Usage initializer_list

This commit is contained in:
Jacob Dufault 2018-01-06 17:11:34 -08:00
parent a1423a39a0
commit 8debcf1d9d
3 changed files with 12 additions and 5 deletions

View File

@ -71,6 +71,9 @@ struct TestIndexer : IIndexer {
} // namespace } // namespace
IIndexer::TestEntry::TestEntry(const std::string& path, int num_indexes)
: path(path), num_indexes(num_indexes) {}
// static // static
std::unique_ptr<IIndexer> IIndexer::MakeClangIndexer() { std::unique_ptr<IIndexer> IIndexer::MakeClangIndexer() {
return MakeUnique<ClangIndexer>(); return MakeUnique<ClangIndexer>();
@ -78,6 +81,6 @@ std::unique_ptr<IIndexer> IIndexer::MakeClangIndexer() {
// static // static
std::unique_ptr<IIndexer> IIndexer::MakeTestIndexer( std::unique_ptr<IIndexer> IIndexer::MakeTestIndexer(
const std::vector<TestEntry>& entries) { std::initializer_list<TestEntry> entries) {
return TestIndexer::FromEntries(entries); return TestIndexer::FromEntries(entries);
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <initializer_list>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -22,11 +23,13 @@ struct IIndexer {
struct TestEntry { struct TestEntry {
std::string path; std::string path;
int num_indexes = 0; int num_indexes = 0;
TestEntry(const std::string& path, int num_indexes);
}; };
static std::unique_ptr<IIndexer> MakeClangIndexer(); static std::unique_ptr<IIndexer> MakeClangIndexer();
static std::unique_ptr<IIndexer> MakeTestIndexer( static std::unique_ptr<IIndexer> MakeTestIndexer(
const std::vector<TestEntry>& entries); std::initializer_list<TestEntry> entries);
virtual ~IIndexer() = default; virtual ~IIndexer() = default;
virtual std::vector<std::unique_ptr<IndexFile>> Index( virtual std::vector<std::unique_ptr<IndexFile>> Index(

View File

@ -627,7 +627,7 @@ TEST_SUITE("ImportPipeline") {
}; };
TEST_CASE_FIXTURE(Fixture, "index request with zero results") { TEST_CASE_FIXTURE(Fixture, "index request with zero results") {
indexer = IIndexer::MakeTestIndexer({{"foo.cc", 0}}); indexer = IIndexer::MakeTestIndexer({IIndexer::TestEntry{"foo.cc", 0}});
MakeRequest("foo.cc"); MakeRequest("foo.cc");
@ -639,7 +639,7 @@ TEST_SUITE("ImportPipeline") {
} }
TEST_CASE_FIXTURE(Fixture, "one index request") { TEST_CASE_FIXTURE(Fixture, "one index request") {
indexer = IIndexer::MakeTestIndexer({{"foo.cc", 100}}); indexer = IIndexer::MakeTestIndexer({IIndexer::TestEntry{"foo.cc", 100}});
MakeRequest("foo.cc"); MakeRequest("foo.cc");
@ -651,7 +651,8 @@ TEST_SUITE("ImportPipeline") {
} }
TEST_CASE_FIXTURE(Fixture, "multiple index requests") { TEST_CASE_FIXTURE(Fixture, "multiple index requests") {
indexer = IIndexer::MakeTestIndexer({{"foo.cc", 100}, {"bar.cc", 5}}); indexer = IIndexer::MakeTestIndexer(
{IIndexer::TestEntry{"foo.cc", 100}, IIndexer::TestEntry{"bar.cc", 5}});
MakeRequest("foo.cc"); MakeRequest("foo.cc");
MakeRequest("bar.cc"); MakeRequest("bar.cc");