Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Give warning when no headers specified in headers section
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Aug 4, 2014
1 parent 3630554 commit 671146e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/HeadersParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,29 @@ namespace snowcrash {

mdp::ByteBuffer subject = node->children().front().text;
TrimString(subject);

if (RegexMatch(subject, HeadersRegex))
return HeadersSectionType;
}

return UndefinedSectionType;
}

static void finalize(const MarkdownNodeIterator& node,
SectionParserData& pd,
Report& report,
Headers& out) {

if (out.empty()) {

// WARN: No headers defined
mdp::CharactersRangeSet sourceMap = mdp::BytesRangeSetToCharactersRangeSet(node->sourceMap, pd.sourceData);
report.warnings.push_back(Warning("No headers defined in headers section",
EmptyDefinitionWarning,
sourceMap));
}
}

/** Retrieve headers from content */
static void headersFromContent(const MarkdownNodeIterator& node,
const mdp::ByteBuffer& content,
Expand Down
16 changes: 15 additions & 1 deletion test/test-HeadersParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST_CASE("parse malformed headers fixture", "[headers]")
REQUIRE(headers[1].second == "Hello World!");
}

TEST_CASE("hparser/parse-multiple-blocks", "Parse header section composed of multiple blocks")
TEST_CASE("Parse header section composed of multiple blocks", "[headers]")
{
// Blueprint in question:
//R"(
Expand Down Expand Up @@ -116,3 +116,17 @@ TEST_CASE("hparser/parse-multiple-blocks", "Parse header section composed of mul
REQUIRE(headers[2].first == "X-My-Header");
REQUIRE(headers[2].second == "42");
}

TEST_CASE("Parse header section with missing headers", "[headers]")
{
mdp::ByteBuffer source = "+ Headers\n\n";

Headers headers;
Report report;
SectionParserHelper<Headers, HeadersParser>::parse(source, HeadersSectionType, report, headers);

REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.size() == 1); // no headers

REQUIRE(headers.size() == 0);
}

1 comment on commit 671146e

@zdne
Copy link
Contributor

@zdne zdne commented on 671146e Aug 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.