Add explicit test for serialization of boolean attributes in XML

This commit is contained in:
Martin Hořeňovský
2021-05-30 20:02:02 +02:00
parent 0e2895934c
commit 5741de9ccd
10 changed files with 65 additions and 10 deletions

View File

@@ -2,6 +2,9 @@
#include <catch2/internal/catch_xmlwriter.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <sstream>
static std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
Catch::ReusableStringStream oss;
@@ -112,3 +115,19 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
}
#undef ESC
}
TEST_CASE("XmlWriter writes boolean attributes as true/false", "[XML][XmlWriter]") {
using Catch::Matchers::Contains;
std::stringstream stream;
{
Catch::XmlWriter xml(stream);
xml.scopedElement("Element1")
.writeAttribute("attr1", true)
.writeAttribute("attr2", false);
}
REQUIRE_THAT( stream.str(),
Contains(R"(attr1="true")") &&
Contains(R"(attr2="false")") );
}