mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-23 21:15:39 +02:00
Use std::string_view
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
TEST_CASE( "Incomplete AssertionHandler", "[assertion-handler][!shouldfail]" ) {
|
||||
Catch::AssertionHandler catchAssertionHandler(
|
||||
"REQUIRE"_catch_sr,
|
||||
"REQUIRE",
|
||||
CATCH_INTERNAL_LINEINFO,
|
||||
"Dummy",
|
||||
Catch::ResultDisposition::Normal );
|
||||
|
@@ -446,11 +446,11 @@ TEST_CASE( "Generators can stringify their elements",
|
||||
auto generator =
|
||||
Catch::Generators::FixedValuesGenerator<int>( { 1, 2, 3 } );
|
||||
|
||||
REQUIRE( generator.currentElementAsString() == "1"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "1" );
|
||||
REQUIRE( generator.countedNext() );
|
||||
REQUIRE( generator.currentElementAsString() == "2"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "2" );
|
||||
REQUIRE( generator.countedNext() );
|
||||
REQUIRE( generator.currentElementAsString() == "3"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "3" );
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -481,9 +481,9 @@ namespace {
|
||||
TEST_CASE( "Generators can override element stringification",
|
||||
"[generators][approvals]" ) {
|
||||
CustomStringifyGenerator generator;
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
REQUIRE( generator.countedNext() );
|
||||
REQUIRE( generator.currentElementAsString() == "second"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "second" );
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -519,11 +519,11 @@ namespace {
|
||||
TEST_CASE( "Generator element stringification is cached",
|
||||
"[generators][approvals]" ) {
|
||||
StringifyCountingGenerator generator;
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first"_catch_sr );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
REQUIRE( generator.currentElementAsString() == "first" );
|
||||
|
||||
REQUIRE( generator.stringificationCalls() == 1 );
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@
|
||||
using namespace Catch;
|
||||
|
||||
namespace {
|
||||
Catch::TestCaseTracking::NameAndLocationRef makeNAL( StringRef name ) {
|
||||
Catch::TestCaseTracking::NameAndLocationRef makeNAL( std::string_view name ) {
|
||||
return Catch::TestCaseTracking::NameAndLocationRef( name, Catch::SourceLineInfo("",0) );
|
||||
}
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ TEST_CASE( "The default listing implementation write to provided stream",
|
||||
StringIStream sstream;
|
||||
SECTION( "Listing tags" ) {
|
||||
std::vector<Catch::TagInfo> tags(1);
|
||||
tags[0].add("fakeTag"_catch_sr);
|
||||
tags[0].add("fakeTag");
|
||||
Catch::defaultListTags(sstream.stream(), tags, false);
|
||||
|
||||
auto listingString = sstream.str();
|
||||
@@ -72,7 +72,7 @@ TEST_CASE( "The default listing implementation write to provided stream",
|
||||
SECTION( "Listing tests" ) {
|
||||
Catch::TestCaseInfo fakeInfo{
|
||||
""s,
|
||||
{ "fake test name"_catch_sr, "[fakeTestTag]"_catch_sr },
|
||||
{ "fake test name", "[fakeTestTag]" },
|
||||
{ "fake-file.cpp", 123456789 } };
|
||||
std::vector<Catch::TestCaseHandle> tests({ {&fakeInfo, nullptr} });
|
||||
auto colour = Catch::makeColourImpl( Catch::ColourMode::None, &sstream);
|
||||
@@ -85,7 +85,7 @@ TEST_CASE( "The default listing implementation write to provided stream",
|
||||
}
|
||||
SECTION( "Listing listeners" ) {
|
||||
std::vector<Catch::ListenerDescription> listeners(
|
||||
{ { "fakeListener"_catch_sr, "fake description" } } );
|
||||
{ { "fakeListener", "fake description" } } );
|
||||
|
||||
Catch::defaultListListeners( sstream.stream(), listeners );
|
||||
auto listingString = sstream.str();
|
||||
@@ -117,7 +117,7 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
|
||||
|
||||
DYNAMIC_SECTION( factory.first << " reporter lists tags" ) {
|
||||
std::vector<Catch::TagInfo> tags(1);
|
||||
tags[0].add("fakeTag"_catch_sr);
|
||||
tags[0].add("fakeTag");
|
||||
reporter->listTags(tags);
|
||||
|
||||
auto listingString = sstreamRef.str();
|
||||
@@ -136,7 +136,7 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
|
||||
DYNAMIC_SECTION( factory.first << " reporter lists tests" ) {
|
||||
Catch::TestCaseInfo fakeInfo{
|
||||
""s,
|
||||
{ "fake test name"_catch_sr, "[fakeTestTag]"_catch_sr },
|
||||
{ "fake test name", "[fakeTestTag]" },
|
||||
{ "fake-file.cpp", 123456789 } };
|
||||
std::vector<Catch::TestCaseHandle> tests({ {&fakeInfo, nullptr} });
|
||||
reporter->listTests(tests);
|
||||
|
@@ -1,212 +0,0 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
using Catch::StringRef;
|
||||
|
||||
SECTION( "Empty string" ) {
|
||||
StringRef empty;
|
||||
REQUIRE( empty.empty() );
|
||||
REQUIRE( empty.size() == 0 );
|
||||
REQUIRE( std::strcmp( empty.data(), "" ) == 0 );
|
||||
}
|
||||
|
||||
SECTION( "From string literal" ) {
|
||||
StringRef s = "hello";
|
||||
REQUIRE( s.empty() == false );
|
||||
REQUIRE( s.size() == 5 );
|
||||
|
||||
auto rawChars = s.data();
|
||||
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 );
|
||||
|
||||
REQUIRE(s.data() == rawChars);
|
||||
}
|
||||
SECTION( "From sub-string" ) {
|
||||
StringRef original = StringRef( "original string" ).substr(0, 8);
|
||||
REQUIRE( original == "original" );
|
||||
|
||||
REQUIRE_NOTHROW(original.data());
|
||||
}
|
||||
SECTION( "Copy construction is shallow" ) {
|
||||
StringRef original = StringRef( "original string" );
|
||||
StringRef copy = original;
|
||||
REQUIRE(original.begin() == copy.begin());
|
||||
}
|
||||
SECTION( "Copy assignment is shallow" ) {
|
||||
StringRef original = StringRef( "original string" );
|
||||
StringRef copy;
|
||||
copy = original;
|
||||
REQUIRE(original.begin() == copy.begin());
|
||||
}
|
||||
|
||||
SECTION( "Substrings" ) {
|
||||
StringRef s = "hello world!";
|
||||
StringRef ss = s.substr(0, 5);
|
||||
|
||||
SECTION( "zero-based substring" ) {
|
||||
REQUIRE( ss.empty() == false );
|
||||
REQUIRE( ss.size() == 5 );
|
||||
REQUIRE( std::strncmp( ss.data(), "hello", 5 ) == 0 );
|
||||
REQUIRE( ss == "hello" );
|
||||
}
|
||||
|
||||
SECTION( "non-zero-based substring") {
|
||||
ss = s.substr( 6, 6 );
|
||||
REQUIRE( ss.size() == 6 );
|
||||
REQUIRE( std::strcmp( ss.data(), "world!" ) == 0 );
|
||||
}
|
||||
|
||||
SECTION( "Pointer values of full refs should match" ) {
|
||||
StringRef s2 = s;
|
||||
REQUIRE( s.data() == s2.data() );
|
||||
}
|
||||
|
||||
SECTION( "Pointer values of substring refs should also match" ) {
|
||||
REQUIRE( s.data() == ss.data() );
|
||||
}
|
||||
|
||||
SECTION("Past the end substring") {
|
||||
REQUIRE(s.substr(s.size() + 1, 123).empty());
|
||||
}
|
||||
|
||||
SECTION("Substring off the end are trimmed") {
|
||||
ss = s.substr(6, 123);
|
||||
REQUIRE(std::strcmp(ss.data(), "world!") == 0);
|
||||
}
|
||||
SECTION("substring start after the end is empty") {
|
||||
REQUIRE(s.substr(1'000'000, 1).empty());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "Comparisons are deep" ) {
|
||||
char buffer1[] = "Hello";
|
||||
char buffer2[] = "Hello";
|
||||
CHECK(reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2));
|
||||
|
||||
StringRef left(buffer1), right(buffer2);
|
||||
REQUIRE( left == right );
|
||||
REQUIRE(left != left.substr(0, 3));
|
||||
}
|
||||
|
||||
SECTION( "from std::string" ) {
|
||||
std::string stdStr = "a standard string";
|
||||
|
||||
SECTION( "implicitly constructed" ) {
|
||||
StringRef sr = stdStr;
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
SECTION( "explicitly constructed" ) {
|
||||
StringRef sr( stdStr );
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
StringRef sr;
|
||||
sr = stdStr;
|
||||
REQUIRE( sr == "a standard string" );
|
||||
REQUIRE( sr.size() == stdStr.size() );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION( "to std::string" ) {
|
||||
StringRef sr = "a stringref";
|
||||
|
||||
SECTION( "explicitly constructed" ) {
|
||||
std::string stdStr( sr );
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
std::string stdStr;
|
||||
stdStr = static_cast<std::string>(sr);
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("std::string += StringRef") {
|
||||
StringRef sr = "the stringref contents";
|
||||
std::string lhs("some string += ");
|
||||
lhs += sr;
|
||||
REQUIRE(lhs == "some string += the stringref contents");
|
||||
}
|
||||
SECTION("StringRef + StringRef") {
|
||||
StringRef sr1 = "abraka", sr2 = "dabra";
|
||||
std::string together = sr1 + sr2;
|
||||
REQUIRE(together == "abrakadabra");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
|
||||
using Catch::StringRef;
|
||||
SECTION("Simple constructors") {
|
||||
constexpr StringRef empty{};
|
||||
STATIC_REQUIRE(empty.size() == 0);
|
||||
STATIC_REQUIRE(empty.begin() == empty.end());
|
||||
|
||||
constexpr char const* const abc = "abc";
|
||||
|
||||
constexpr StringRef stringref(abc, 3);
|
||||
STATIC_REQUIRE(stringref.size() == 3);
|
||||
STATIC_REQUIRE(stringref.data() == abc);
|
||||
STATIC_REQUIRE(stringref.begin() == abc);
|
||||
STATIC_REQUIRE(stringref.begin() != stringref.end());
|
||||
STATIC_REQUIRE(stringref.substr(10, 0).empty());
|
||||
STATIC_REQUIRE(stringref.substr(2, 1).data() == abc + 2);
|
||||
STATIC_REQUIRE(stringref[1] == 'b');
|
||||
|
||||
|
||||
constexpr StringRef shortened(abc, 2);
|
||||
STATIC_REQUIRE(shortened.size() == 2);
|
||||
STATIC_REQUIRE(shortened.data() == abc);
|
||||
STATIC_REQUIRE(shortened.begin() != shortened.end());
|
||||
}
|
||||
SECTION("UDL construction") {
|
||||
constexpr auto sr1 = "abc"_catch_sr;
|
||||
STATIC_REQUIRE_FALSE(sr1.empty());
|
||||
STATIC_REQUIRE(sr1.size() == 3);
|
||||
|
||||
using Catch::operator""_sr;
|
||||
constexpr auto sr2 = ""_sr;
|
||||
STATIC_REQUIRE(sr2.empty());
|
||||
STATIC_REQUIRE(sr2.size() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StringRef::compare", "[Strings][StringRef][approvals]") {
|
||||
using Catch::StringRef;
|
||||
|
||||
SECTION("Same length on both sides") {
|
||||
StringRef sr1("abcdc");
|
||||
StringRef sr2("abcdd");
|
||||
StringRef sr3("abcdc");
|
||||
|
||||
REQUIRE(sr1.compare(sr2) < 0);
|
||||
REQUIRE(sr2.compare(sr1) > 0);
|
||||
REQUIRE(sr1.compare(sr3) == 0);
|
||||
REQUIRE(sr3.compare(sr1) == 0);
|
||||
}
|
||||
SECTION("Different lengths") {
|
||||
StringRef sr1("def");
|
||||
StringRef sr2("deff");
|
||||
StringRef sr3("ab");
|
||||
|
||||
REQUIRE(sr1.compare(sr2) < 0);
|
||||
REQUIRE(sr2.compare(sr1) > 0);
|
||||
REQUIRE(sr1.compare(sr3) > 0);
|
||||
REQUIRE(sr2.compare(sr3) > 0);
|
||||
REQUIRE(sr3.compare(sr1) < 0);
|
||||
REQUIRE(sr3.compare(sr2) < 0);
|
||||
}
|
||||
}
|
@@ -16,19 +16,19 @@ static const char * const trailing_whitespace = "There is no extra whitespace he
|
||||
static const char * const whitespace_at_both_ends = " \r\n \t There is no extra whitespace here \t\t\t \n";
|
||||
|
||||
TEST_CASE("Trim strings", "[string-manip]") {
|
||||
using Catch::trim; using Catch::StringRef;
|
||||
using Catch::trim;
|
||||
static_assert(std::is_same_v<std::string, decltype(trim(std::string{}))>, "Trimming std::string should return std::string");
|
||||
static_assert(std::is_same_v<StringRef, decltype(trim(StringRef{}))>, "Trimming StringRef should return StringRef");
|
||||
static_assert(std::is_same_v<std::string_view, decltype(trim(std::string_view{}))>, "Trimming std::string_view should return std::string_view");
|
||||
|
||||
REQUIRE(trim(std::string(no_whitespace)) == no_whitespace);
|
||||
REQUIRE(trim(std::string(leading_whitespace)) == no_whitespace);
|
||||
REQUIRE(trim(std::string(trailing_whitespace)) == no_whitespace);
|
||||
REQUIRE(trim(std::string(whitespace_at_both_ends)) == no_whitespace);
|
||||
|
||||
REQUIRE(trim(StringRef(no_whitespace)) == StringRef(no_whitespace));
|
||||
REQUIRE(trim(StringRef(leading_whitespace)) == StringRef(no_whitespace));
|
||||
REQUIRE(trim(StringRef(trailing_whitespace)) == StringRef(no_whitespace));
|
||||
REQUIRE(trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace));
|
||||
REQUIRE(trim(std::string_view(no_whitespace)) == std::string_view(no_whitespace));
|
||||
REQUIRE(trim(std::string_view(leading_whitespace)) == std::string_view(no_whitespace));
|
||||
REQUIRE(trim(std::string_view(trailing_whitespace)) == std::string_view(no_whitespace));
|
||||
REQUIRE(trim(std::string_view(whitespace_at_both_ends)) == std::string_view(no_whitespace));
|
||||
}
|
||||
|
||||
TEST_CASE("replaceInPlace", "[string-manip]") {
|
||||
@@ -78,11 +78,10 @@ TEST_CASE("replaceInPlace", "[string-manip]") {
|
||||
TEST_CASE("splitString", "[string-manip]") {
|
||||
using namespace Catch::Matchers;
|
||||
using Catch::splitStringRef;
|
||||
using Catch::StringRef;
|
||||
|
||||
CHECK_THAT(splitStringRef("", ','), Equals(std::vector<StringRef>()));
|
||||
CHECK_THAT(splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}));
|
||||
CHECK_THAT(splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}));
|
||||
CHECK_THAT(splitStringRef("", ','), Equals(std::vector<std::string_view>()));
|
||||
CHECK_THAT(splitStringRef("abc", ','), Equals(std::vector<std::string_view>{"abc"}));
|
||||
CHECK_THAT(splitStringRef("abc,def", ','), Equals(std::vector<std::string_view>{"abc", "def"}));
|
||||
}
|
||||
|
||||
TEST_CASE("startsWith", "[string-manip]") {
|
||||
@@ -90,5 +89,5 @@ TEST_CASE("startsWith", "[string-manip]") {
|
||||
|
||||
CHECK_FALSE(startsWith("", 'c'));
|
||||
CHECK(startsWith(std::string("abc"), 'a'));
|
||||
CHECK(startsWith("def"_catch_sr, 'd'));
|
||||
CHECK(startsWith("def", 'd'));
|
||||
}
|
||||
|
@@ -46,22 +46,20 @@ TEST_CASE( "Tag alias can be registered against tag patterns" ) {
|
||||
static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
|
||||
|
||||
TEST_CASE("shortened hide tags are split apart", "[tags]") {
|
||||
using Catch::StringRef;
|
||||
using Catch::Tag;
|
||||
using Catch::Matchers::VectorContains;
|
||||
|
||||
Catch::TestCaseInfo testcase("", {"fake test name", "[.magic-tag]"}, dummySourceLineInfo);
|
||||
REQUIRE_THAT( testcase.tags, VectorContains( Tag( "magic-tag" ) )
|
||||
&& VectorContains( Tag( "."_catch_sr ) ) );
|
||||
&& VectorContains( Tag( "." ) ) );
|
||||
}
|
||||
|
||||
TEST_CASE("tags with dots in later positions are not parsed as hidden", "[tags]") {
|
||||
using Catch::StringRef;
|
||||
using Catch::Matchers::VectorContains;
|
||||
Catch::TestCaseInfo testcase("", { "fake test name", "[magic.tag]" }, dummySourceLineInfo);
|
||||
|
||||
REQUIRE(testcase.tags.size() == 1);
|
||||
REQUIRE(testcase.tags[0].original == "magic.tag"_catch_sr);
|
||||
REQUIRE(testcase.tags[0].original == "magic.tag");
|
||||
}
|
||||
|
||||
TEST_CASE( "empty tags are not allowed", "[tags]" ) {
|
||||
@@ -83,7 +81,7 @@ TEST_CASE( "Tags with spaces and non-alphanumerical characters are accepted",
|
||||
REQUIRE( testCase.tags.size() == 2 );
|
||||
REQUIRE_THAT( testCase.tags,
|
||||
VectorContains( Tag( "tag with spaces" ) ) &&
|
||||
VectorContains( Tag( "I said \"good day\" sir!"_catch_sr ) ) );
|
||||
VectorContains( Tag( "I said \"good day\" sir!" ) ) );
|
||||
}
|
||||
|
||||
TEST_CASE( "Test case with identical tags keeps just one", "[tags]" ) {
|
||||
|
@@ -29,24 +29,24 @@ TEST_CASE( "parseEnums", "[Strings][enums]" ) {
|
||||
using Catch::Detail::parseEnums;
|
||||
|
||||
SECTION( "No enums" )
|
||||
CHECK_THAT( parseEnums( "" ), Equals( std::vector<Catch::StringRef>{} ) );
|
||||
CHECK_THAT( parseEnums( "" ), Equals( std::vector<std::string_view>{} ) );
|
||||
|
||||
SECTION( "One enum value" ) {
|
||||
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ),
|
||||
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
||||
Equals(std::vector<std::string_view>{"Value1"} ) );
|
||||
CHECK_THAT( parseEnums( "Value1" ),
|
||||
Equals( std::vector<Catch::StringRef>{"Value1"} ) );
|
||||
Equals( std::vector<std::string_view>{"Value1"} ) );
|
||||
CHECK_THAT( parseEnums( "EnumName::Value1" ),
|
||||
Equals(std::vector<Catch::StringRef>{"Value1"} ) );
|
||||
Equals(std::vector<std::string_view>{"Value1"} ) );
|
||||
}
|
||||
|
||||
SECTION( "Multiple enum values" ) {
|
||||
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ),
|
||||
Equals( std::vector<Catch::StringRef>{"Value1", "Value2"} ) );
|
||||
Equals( std::vector<std::string_view>{"Value1", "Value2"} ) );
|
||||
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ),
|
||||
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
||||
Equals( std::vector<std::string_view>{"Value1", "Value2", "Value3"} ) );
|
||||
CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ),
|
||||
Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) );
|
||||
Equals( std::vector<std::string_view>{"Value1", "Value2", "Value3"} ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,19 +70,19 @@ TEST_CASE("convertIntoString stringification helper", "[toString][approvals]") {
|
||||
using namespace Catch;
|
||||
|
||||
SECTION("No escaping") {
|
||||
CHECK(convertIntoString(""_sr, false) == R"("")"s);
|
||||
CHECK(convertIntoString("abcd"_sr, false) == R"("abcd")"s);
|
||||
CHECK(convertIntoString("ab\ncd"_sr, false) == "\"ab\ncd\""s);
|
||||
CHECK(convertIntoString("ab\r\ncd"_sr, false) == "\"ab\r\ncd\""s);
|
||||
CHECK(convertIntoString("ab\"cd"_sr, false) == R"("ab"cd")"s);
|
||||
CHECK(convertIntoString("", false) == R"("")"s);
|
||||
CHECK(convertIntoString("abcd", false) == R"("abcd")"s);
|
||||
CHECK(convertIntoString("ab\ncd", false) == "\"ab\ncd\""s);
|
||||
CHECK(convertIntoString("ab\r\ncd", false) == "\"ab\r\ncd\""s);
|
||||
CHECK(convertIntoString("ab\"cd", false) == R"("ab"cd")"s);
|
||||
}
|
||||
SECTION("Escaping invisibles") {
|
||||
CHECK(convertIntoString(""_sr, true) == R"("")"s);
|
||||
CHECK(convertIntoString("ab\ncd"_sr, true) == R"("ab\ncd")"s);
|
||||
CHECK(convertIntoString("ab\r\ncd"_sr, true) == R"("ab\r\ncd")"s);
|
||||
CHECK(convertIntoString("ab\tcd"_sr, true) == R"("ab\tcd")"s);
|
||||
CHECK(convertIntoString("ab\fcd"_sr, true) == R"("ab\fcd")"s);
|
||||
CHECK(convertIntoString("ab\"cd"_sr, true) == R"("ab"cd")"s);
|
||||
CHECK(convertIntoString("", true) == R"("")"s);
|
||||
CHECK(convertIntoString("ab\ncd", true) == R"("ab\ncd")"s);
|
||||
CHECK(convertIntoString("ab\r\ncd", true) == R"("ab\r\ncd")"s);
|
||||
CHECK(convertIntoString("ab\tcd", true) == R"("ab\tcd")"s);
|
||||
CHECK(convertIntoString("ab\fcd", true) == R"("ab\fcd")"s);
|
||||
CHECK(convertIntoString("ab\"cd", true) == R"("ab"cd")"s);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user