Skip to content

Commit

Permalink
fix: conflicted cdata constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamska1008 committed Sep 15, 2024
1 parent 7ffdd86 commit 3834cfc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 4 additions & 2 deletions include/myxml/cdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ namespace myxml
class cdata : public printable
{
friend class element;

private:
std::shared_ptr<cdata_impl> _impl;

cdata(std::shared_ptr<cdata_impl>);

public:
cdata(std::string &&);
cdata(std::string_view);
explicit cdata(std::string);
explicit cdata(std::string_view);
explicit cdata(const char *);

virtual void entity_encoding(bool) override {}
virtual void platform_specific_newline(bool) override {}
Expand Down
7 changes: 6 additions & 1 deletion src/cdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ namespace myxml
{
}

cdata::cdata(std::string &&str)
cdata::cdata(const char *str)
: _impl(std::make_shared<cdata_impl>(std::string_view(str)))
{
}

cdata::cdata(std::string str)
: _impl(std::make_shared<cdata_impl>(str))
{
}
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ add_custom_test(printable_test)
add_custom_test(document_test)
add_custom_test(buffer_test)
add_custom_test(text_test)
add_custom_test(cdata_test)
23 changes: 23 additions & 0 deletions tests/cdata_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <sstream>
#include <catch2/catch_test_macros.hpp>
#include "myxml/cdata.hpp"

TEST_CASE("Simple", "[cdata]")
{
SECTION("Constructor")
{
myxml::cdata cdata1("It is a CDATA <");
std::string view("It is also a CDATA");
myxml::cdata cdata2(view);
std::string owner("It is the last CDATA");
myxml::cdata cdata3(std::move(owner));
}

SECTION("Print")
{
myxml::cdata cdata("It is a CDATA <");
std::stringstream sstream;
sstream << cdata;
REQUIRE(sstream.str() == "<![CDATA[It is a CDATA <]]>\n");
}
}

0 comments on commit 3834cfc

Please sign in to comment.