diff options
| author | Martin Hořeňovský | 2021-10-01 12:02:17 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-10-02 14:39:52 +0200 |
| commit | 13670f535fad8ab5db06049366a38f7a364d37d8 (patch) | |
| tree | 39d799b06fb7b6f27f29d4eef3cb107b0c134f8c /tests/SelfTest | |
| parent | c6640e4f470b99c9d95758bfd62d6205095757e6 (diff) | |
| download | catch3-13670f535fad8ab5db06049366a38f7a364d37d8.tar.gz | |
Add more tests for XmlWrite::write* members
Diffstat (limited to 'tests/SelfTest')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/Xml.tests.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp index 0459c579..4659dc52 100644 --- a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp @@ -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: < > ' " &")")); +} |