Skip to content

Commit

Permalink
F Add support for approving strings with Unicode characters #154
Browse files Browse the repository at this point in the history
Co-Authored-By: Llewellyn Falco <[email protected]>
  • Loading branch information
claremacrae and isidore committed Oct 19, 2020
1 parent b746dec commit 80dbf0d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions ApprovalTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ add_library(${PROJECT_NAME}
utilities/MoreHelpMessages.h
utilities/MoreHelpMessages.cpp
utilities/StringMaker.h
utilities/StringMaker.cpp
utilities/StringUtils.h
utilities/StringUtils.cpp
utilities/SystemUtils.h
Expand Down
18 changes: 18 additions & 0 deletions ApprovalTests/utilities/StringMaker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "StringMaker.h"

#include <codecvt>

namespace ApprovalTests
{
std::string StringMaker::toString(const std::wstring& wstr)
{
static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> utf8_converter;
return utf8_converter.to_bytes(wstr);
}

std::string StringMaker::toString(const wchar_t* wstr)
{
static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> utf8_converter;
return utf8_converter.to_bytes(wstr);
}
}
4 changes: 4 additions & 0 deletions ApprovalTests/utilities/StringMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ namespace ApprovalTests
s << contents;
return s.str();
}

static std::string toString(const std::wstring& wstr);

static std::string toString(const wchar_t* wstr);
};
}
11 changes: 11 additions & 0 deletions tests/DocTest_Tests/ApprovalsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ TEST_CASE("TestNonCopyableStreamableObject")
Approvals::verify(object, Options());
}

TEST_CASE("Test Unicode")
{
Approvals::verify("I like unicode ☃");
}

TEST_CASE("Test wstring")
{
std::wstring text = L"I like unicode ☃";
Approvals::verify(text);
}

// ==============================================================

struct NonStreamablePoint
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I like unicode ☃
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I like unicode ☃

0 comments on commit 80dbf0d

Please sign in to comment.