mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Add more tests for XmlWrite::write* members
This commit is contained in:
@@ -131,3 +131,47 @@ TEST_CASE("XmlWriter writes boolean attributes as true/false", "[XML][XmlWriter]
|
||||
ContainsSubstring(R"(attr1="true")") &&
|
||||
ContainsSubstring(R"(attr2="false")") );
|
||||
}
|
||||
|
||||
TEST_CASE("XmlWriter does not escape comments", "[XML][XmlWriter][approvals]") {
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
std::stringstream stream;
|
||||
{
|
||||
Catch::XmlWriter xml(stream);
|
||||
|
||||
xml.writeComment(R"(unescaped special chars: < > ' " &)");
|
||||
}
|
||||
REQUIRE_THAT( stream.str(),
|
||||
ContainsSubstring(R"(<!-- unescaped special chars: < > ' " & -->)"));
|
||||
}
|
||||
|
||||
TEST_CASE("XmlWriter errors out when writing text without enclosing element", "[XmlWriter][approvals]") {
|
||||
std::stringstream stream;
|
||||
Catch::XmlWriter xml(stream);
|
||||
REQUIRE_THROWS(xml.writeText("some text"));
|
||||
}
|
||||
|
||||
TEST_CASE("XmlWriter escapes text properly", "[XML][XmlWriter][approvals]") {
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
std::stringstream stream;
|
||||
{
|
||||
Catch::XmlWriter xml(stream);
|
||||
xml.scopedElement("root")
|
||||
.writeText(R"(Special chars need escaping: < > ' " &)");
|
||||
}
|
||||
|
||||
REQUIRE_THAT( stream.str(),
|
||||
ContainsSubstring(R"(Special chars need escaping: < > ' " &)"));
|
||||
}
|
||||
|
||||
TEST_CASE("XmlWriter escapes attributes properly", "[XML][XmlWriter][approvals]") {
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
std::stringstream stream;
|
||||
{
|
||||
Catch::XmlWriter xml(stream);
|
||||
xml.scopedElement("root")
|
||||
.writeAttribute("some-attribute", R"(Special chars need escaping: < > ' " &)");
|
||||
}
|
||||
|
||||
REQUIRE_THAT(stream.str(),
|
||||
ContainsSubstring(R"(some-attribute="Special chars need escaping: < > ' " &")"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user