Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ void Option::put(PrefPtr pref, const std::string& value)
table_[pref->i] = value;
}

void Option::append(PrefPtr pref, const std::string& value,
const std::string& delim)
{
if (!definedLocal(pref)) {
put(pref, get(pref));
}
table_[pref->i].append(value).append(delim);
}

bool Option::defined(PrefPtr pref) const
{
return bitfield::test(use_, use_.size() * 8, pref->i) ||
Expand Down
1 change: 1 addition & 0 deletions src/Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Option {
Option& operator=(const Option& option);

void put(PrefPtr pref, const std::string& value);
void append(PrefPtr pref, const std::string& value, const std::string& delim);
// Returns true if name is defined. Otherwise returns false. Note
// that even if the value is a empty string, this method returns
// true. If option is not defined in this object and parent_ is not
Expand Down
5 changes: 1 addition & 4 deletions src/OptionHandlerImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ void IndexOutOptionHandler::parseArg(Option& option,
{
// See optarg is in the format of "INDEX=PATH"
util::parseIndexPath(optarg);
std::string value = option.get(pref_);
value += optarg;
value += "\n";
option.put(pref_, value);
option.append(pref_, optarg, "\n");
}

std::string IndexOutOptionHandler::createPossibleValuesString() const
Expand Down
24 changes: 24 additions & 0 deletions test/OptionTest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Option.h"
#include "OptionHandlerImpl.h"

#include <string>

Expand All @@ -12,6 +13,7 @@ class OptionTest : public CppUnit::TestFixture {

CPPUNIT_TEST_SUITE(OptionTest);
CPPUNIT_TEST(testPutAndGet);
CPPUNIT_TEST(testAppendInheritedMappings);
CPPUNIT_TEST(testPutAndGetAsInt);
CPPUNIT_TEST(testPutAndGetAsDouble);
CPPUNIT_TEST(testDefined);
Expand All @@ -26,6 +28,7 @@ class OptionTest : public CppUnit::TestFixture {
void setUp() {}

void testPutAndGet();
void testAppendInheritedMappings();
void testPutAndGetAsInt();
void testPutAndGetAsDouble();
void testDefined();
Expand All @@ -37,6 +40,27 @@ class OptionTest : public CppUnit::TestFixture {

CPPUNIT_TEST_SUITE_REGISTRATION(OptionTest);

void OptionTest::testAppendInheritedMappings()
{
auto parent = std::make_shared<Option>();
parent->put(PREF_INDEX_OUT, "1=parent/file\n");
Option child;
child.setParent(parent);
IndexOutOptionHandler handler(PREF_INDEX_OUT, "output path");
std::string expected = parent->get(PREF_INDEX_OUT);
for (unsigned i = 2; i <= 26730; ++i) {
auto mapping = std::to_string(i) + "=local/subdir/item";
handler.parse(child, mapping);
expected.append(mapping).push_back('\n');
}
CPPUNIT_ASSERT(expected == child.get(PREF_INDEX_OUT));
CPPUNIT_ASSERT_EQUAL(std::string("1=parent/file\n"), parent->get(PREF_INDEX_OUT));
child.removeLocal(PREF_INDEX_OUT);
handler.parse(child, "2=other");
CPPUNIT_ASSERT_EQUAL(std::string("1=parent/file\n2=other\n"),
child.get(PREF_INDEX_OUT));
}

void OptionTest::testPutAndGet()
{
Option op;
Expand Down
Loading