aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-28 22:34:47 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-06-28 22:37:46 +0100
commit515fa4c9344ccf566f7db68d5df4fffbb9805087 (patch)
tree9ec2b76e9bb64d266eb46fb0fadd842da66a3a73
parentec191d1e2b6a0c0eff1cf8a939f49fa319b0aa98 (diff)
downloadpaludis-515fa4c9344ccf566f7db68d5df4fffbb9805087.tar.gz
paludis-515fa4c9344ccf566f7db68d5df4fffbb9805087.tar.xz
Make line continuations work (continued)
-rw-r--r--paludis/util/config_file.cc1
-rw-r--r--paludis/util/config_file_TEST.cc53
2 files changed, 54 insertions, 0 deletions
diff --git a/paludis/util/config_file.cc b/paludis/util/config_file.cc
index 3a3d5e4..12ad4d7 100644
--- a/paludis/util/config_file.cc
+++ b/paludis/util/config_file.cc
@@ -258,6 +258,7 @@ LineConfigFile::LineConfigFile(const Source & sr, const LineConfigFileOptions &
if (! parser.eof())
throw ConfigFileError(sr.filename(),
"Something is very strange at line '" + stringify(parser.current_line_number() + "'"));
+ break;
}
else if (parser.consume(simple_parser::exact("#") >> word))
{
diff --git a/paludis/util/config_file_TEST.cc b/paludis/util/config_file_TEST.cc
index da4452f..1bdfc18 100644
--- a/paludis/util/config_file_TEST.cc
+++ b/paludis/util/config_file_TEST.cc
@@ -401,5 +401,58 @@ namespace test_cases
&KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation), ConfigurationError);
}
} test_key_value_config_file_errors;
+
+ struct LineConfigFileInlineCommentsTest : TestCase
+ {
+ LineConfigFileInlineCommentsTest() : TestCase("line config file inline comments") { }
+
+ void run()
+ {
+ std::stringstream s;
+ s << "one # moo" << std::endl;
+ s << "tw\\" << std::endl;
+ s << "o # moo" << std::endl;
+ s << "" << std::endl;
+ s << "three #" << std::endl;
+ s << "#" << std::endl;
+ s << "four" << std::endl;
+ s << "five # moo" << std::endl;
+
+ LineConfigFile f(s, LineConfigFileOptions() + lcfo_allow_inline_comments);
+ TEST_CHECK_EQUAL(std::distance(f.begin(), f.end()), 5);
+ std::vector<std::string> lines;
+ std::copy(f.begin(), f.end(), std::back_inserter(lines));
+ TEST_CHECK_EQUAL(lines.at(0), "one");
+ TEST_CHECK_EQUAL(lines.at(1), "two");
+ TEST_CHECK_EQUAL(lines.at(2), "three");
+ TEST_CHECK_EQUAL(lines.at(3), "four");
+ TEST_CHECK_EQUAL(lines.at(4), "five");
+ }
+ } test_line_config_file_inline_comments;
+
+ struct KeyValueConfigFileInlineCommentsTest : TestCase
+ {
+ KeyValueConfigFileInlineCommentsTest() : TestCase("key value config inline comments") { }
+
+ void run()
+ {
+ std::stringstream d_s;
+ d_s << "one=\"one\" # foo" << std::endl;
+ d_s << "two=two # bar" << std::endl;
+ d_s << "three = \\" << std::endl;
+ d_s << "three # bar" << std::endl;
+ d_s << "four = four # foo" << std::endl;
+ d_s << "five = five # moo" << std::endl;
+ KeyValueConfigFile ff(d_s, KeyValueConfigFileOptions(),
+ &KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation);
+
+ TEST_CHECK_EQUAL(std::distance(ff.begin(), ff.end()), 5);
+ TEST_CHECK_EQUAL(ff.get("one"), "one");
+ TEST_CHECK_EQUAL(ff.get("two"), "two");
+ TEST_CHECK_EQUAL(ff.get("three"), "three");
+ TEST_CHECK_EQUAL(ff.get("four"), "four");
+ TEST_CHECK_EQUAL(ff.get("five"), "five");
+ }
+ } test_key_value_config_file_inline_comments;
}