Skip to content

Commit

Permalink
adds line comments for CONTROL
Browse files Browse the repository at this point in the history
Adds line comments denoted by # within CONTROL files.
For the moment a comment must be start with # and is valid
until the end of the line. It's not possible to add a comment
at the end of usable lines.

Signed-off-by: Tobias Kohlbau <[email protected]>
  • Loading branch information
tobiaskohlbau authored and alexkaratarakis committed Apr 3, 2017
1 parent 23887e9 commit b992a05
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 52 deletions.
23 changes: 22 additions & 1 deletion toolsrc/src/Paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ namespace vcpkg::Paragraphs
}
}

void skip_comment(char& ch)
{
while (ch != '\r')
next(ch);
if (ch == '\r')
next(ch);
if (ch == '\n')
next(ch);
}

void skip_spaces(char& ch)
{
while (ch == ' ' || ch == '\t')
Expand All @@ -45,6 +55,11 @@ namespace vcpkg::Paragraphs
|| (ch >= '0' && ch <= '9');
}

static bool is_comment(char ch)
{
return (ch == '#');
}

static bool is_lineend(char ch)
{
return ch == '\r' || ch == '\n' || ch == 0;
Expand All @@ -68,7 +83,7 @@ namespace vcpkg::Paragraphs
if (ch == '\n')
next(ch);

if (is_alphanum(ch))
if (is_alphanum(ch) || is_comment(ch))
{
// Line begins a new field.
return;
Expand Down Expand Up @@ -115,6 +130,12 @@ namespace vcpkg::Paragraphs
std::string fieldvalue;
do
{
if (is_comment(ch))
{
skip_comment(ch);
continue;
}

get_fieldname(ch, fieldname);

auto it = fields.find(fieldname);
Expand Down
122 changes: 71 additions & 51 deletions toolsrc/src/tests_paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Construct_Minimum)
{
vcpkg::SourceParagraph pgh({
{"Source", "zlib"},
{"Version", "1.2.8"}
{ "Source", "zlib" },
{ "Version", "1.2.8" }
});

Assert::AreEqual("zlib", pgh.name.c_str());
Expand All @@ -38,11 +38,11 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Construct_Maximum)
{
vcpkg::SourceParagraph pgh({
{"Source", "s"},
{"Version", "v"},
{"Maintainer", "m"},
{"Description", "d"},
{"Build-Depends", "bd"}
{ "Source", "s" },
{ "Version", "v" },
{ "Maintainer", "m" },
{ "Description", "d" },
{ "Build-Depends", "bd" }
});
Assert::AreEqual("s", pgh.name.c_str());
Assert::AreEqual("v", pgh.version.c_str());
Expand All @@ -55,9 +55,9 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Two_Depends)
{
vcpkg::SourceParagraph pgh({
{"Source", "zlib"},
{"Version", "1.2.8"},
{"Build-Depends", "z, openssl"}
{ "Source", "zlib" },
{ "Version", "1.2.8" },
{ "Build-Depends", "z, openssl" }
});

Assert::AreEqual(size_t(2), pgh.depends.size());
Expand All @@ -68,9 +68,9 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Three_Depends)
{
vcpkg::SourceParagraph pgh({
{"Source", "zlib"},
{"Version", "1.2.8"},
{"Build-Depends", "z, openssl, xyz"}
{ "Source", "zlib" },
{ "Version", "1.2.8" },
{ "Build-Depends", "z, openssl, xyz" }
});

Assert::AreEqual(size_t(3), pgh.depends.size());
Expand All @@ -82,9 +82,9 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Construct_Qualified_Depends)
{
vcpkg::SourceParagraph pgh({
{"Source", "zlib"},
{"Version", "1.2.8"},
{"Build-Depends", "libA [windows], libB [uwp]"}
{ "Source", "zlib" },
{ "Version", "1.2.8" },
{ "Build-Depends", "libA [windows], libB [uwp]" }
});

Assert::AreEqual("zlib", pgh.name.c_str());
Expand All @@ -101,10 +101,10 @@ namespace UnitTest1
TEST_METHOD(BinaryParagraph_Construct_Minimum)
{
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{ "Package", "zlib" },
{ "Version", "1.2.8" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
});

Assert::AreEqual("zlib", pgh.spec.name().c_str());
Expand All @@ -118,13 +118,13 @@ namespace UnitTest1
TEST_METHOD(BinaryParagraph_Construct_Maximum)
{
vcpkg::BinaryParagraph pgh({
{"Package", "s"},
{"Version", "v"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Maintainer", "m"},
{"Description", "d"},
{"Depends", "bd"}
{ "Package", "s" },
{ "Version", "v" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
{ "Maintainer", "m" },
{ "Description", "d" },
{ "Depends", "bd" }
});
Assert::AreEqual("s", pgh.spec.name().c_str());
Assert::AreEqual("v", pgh.version.c_str());
Expand All @@ -137,11 +137,11 @@ namespace UnitTest1
TEST_METHOD(BinaryParagraph_Three_Depends)
{
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", "a, b, c"},
{ "Package", "zlib" },
{ "Version", "1.2.8" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
{ "Depends", "a, b, c" },
});

Assert::AreEqual(size_t(3), pgh.depends.size());
Expand Down Expand Up @@ -267,14 +267,36 @@ namespace UnitTest1
Assert::AreEqual("v4", pghs[1]["f4"].c_str());
}

TEST_METHOD(parse_paragraphs_comment)
{
const char* str =
"f1: v1\r\n"
"#comment\r\n"
"f2: v2\r\n"
"#comment\r\n"
"\r\n"
"#comment\r\n"
"f3: v3\r\n"
"#comment\r\n"
"f4: v4";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).value_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(2), pghs.size());
Assert::AreEqual(size_t(2), pghs[0].size());
Assert::AreEqual("v1", pghs[0]["f1"].c_str());
Assert::AreEqual("v2", pghs[0]["f2"].c_str());
Assert::AreEqual(size_t(2), pghs[1].size());
Assert::AreEqual("v3", pghs[1]["f3"].c_str());
Assert::AreEqual("v4", pghs[1]["f4"].c_str());
}

TEST_METHOD(BinaryParagraph_serialize_min)
{
std::stringstream ss;
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{ "Package", "zlib" },
{ "Version", "1.2.8" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).value_or_exit(VCPKG_LINE_INFO);
Expand All @@ -290,13 +312,13 @@ namespace UnitTest1
{
std::stringstream ss;
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "x86-windows"},
{"Description", "first line\n second line"},
{"Maintainer", "abc <[email protected]>"},
{"Depends", "dep"},
{"Multi-Arch", "same"},
{ "Package", "zlib" },
{ "Version", "1.2.8" },
{ "Architecture", "x86-windows" },
{ "Description", "first line\n second line" },
{ "Maintainer", "abc <[email protected]>" },
{ "Depends", "dep" },
{ "Multi-Arch", "same" },
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).value_or_exit(VCPKG_LINE_INFO);
Expand All @@ -314,11 +336,11 @@ namespace UnitTest1
{
std::stringstream ss;
vcpkg::BinaryParagraph pgh({
{"Package", "zlib"},
{"Version", "1.2.8"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", "a, b, c"},
{ "Package", "zlib" },
{ "Version", "1.2.8" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
{ "Depends", "a, b, c" },
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).value_or_exit(VCPKG_LINE_INFO);
Expand Down Expand Up @@ -361,7 +383,5 @@ namespace UnitTest1
}
};

TEST_CLASS(Metrics)
{
};
TEST_CLASS(Metrics) { };
}

0 comments on commit b992a05

Please sign in to comment.