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

View File

@ -1,5 +1,6 @@
#pragma once
#include <initializer_list>
#include <memory>
#include <string>
#include <vector>
@ -22,11 +23,13 @@ struct IIndexer {
struct TestEntry {
std::string path;
int num_indexes = 0;
TestEntry(const std::string& path, int num_indexes);
};
static std::unique_ptr<IIndexer> MakeClangIndexer();
static std::unique_ptr<IIndexer> MakeTestIndexer(
const std::vector<TestEntry>& entries);
std::initializer_list<TestEntry> entries);
virtual ~IIndexer() = default;
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") {
indexer = IIndexer::MakeTestIndexer({{"foo.cc", 0}});
indexer = IIndexer::MakeTestIndexer({IIndexer::TestEntry{"foo.cc", 0}});
MakeRequest("foo.cc");
@ -639,7 +639,7 @@ TEST_SUITE("ImportPipeline") {
}
TEST_CASE_FIXTURE(Fixture, "one index request") {
indexer = IIndexer::MakeTestIndexer({{"foo.cc", 100}});
indexer = IIndexer::MakeTestIndexer({IIndexer::TestEntry{"foo.cc", 100}});
MakeRequest("foo.cc");
@ -651,7 +651,8 @@ TEST_SUITE("ImportPipeline") {
}
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("bar.cc");