From 6da00c1b64b0826bdc735805a65c7dd2147fdf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 7 Sep 2019 20:22:36 +0200 Subject: [PATCH] Split out the rest of string manipulation tests --- .../Baselines/compact.sw.approved.txt | 34 ++++----- .../Baselines/console.sw.approved.txt | 70 +++++++++--------- .../SelfTest/Baselines/xml.sw.approved.txt | 72 +++++++++---------- .../IntrospectiveTests/String.tests.cpp | 45 ------------ .../IntrospectiveTests/StringManip.tests.cpp | 43 +++++++++++ 5 files changed, 131 insertions(+), 133 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 20fade32..aa3613f2 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1522,26 +1522,26 @@ Message.tests.cpp:: passed: true Misc.tests.cpp:: passed: a != b for: 1 != 2 Misc.tests.cpp:: passed: b != a for: 2 != 1 Misc.tests.cpp:: passed: a != b for: 1 != 2 -String.tests.cpp:: passed: Catch::replaceInPlace( letters, "b", "z" ) for: true -String.tests.cpp:: passed: letters == "azcdefcg" for: "azcdefcg" == "azcdefcg" -String.tests.cpp:: passed: Catch::replaceInPlace( letters, "c", "z" ) for: true -String.tests.cpp:: passed: letters == "abzdefzg" for: "abzdefzg" == "abzdefzg" -String.tests.cpp:: passed: Catch::replaceInPlace( letters, "a", "z" ) for: true -String.tests.cpp:: passed: letters == "zbcdefcg" for: "zbcdefcg" == "zbcdefcg" -String.tests.cpp:: passed: Catch::replaceInPlace( letters, "g", "z" ) for: true -String.tests.cpp:: passed: letters == "abcdefcz" for: "abcdefcz" == "abcdefcz" -String.tests.cpp:: passed: Catch::replaceInPlace( letters, letters, "replaced" ) for: true -String.tests.cpp:: passed: letters == "replaced" for: "replaced" == "replaced" -String.tests.cpp:: passed: !(Catch::replaceInPlace( letters, "x", "z" )) for: !false -String.tests.cpp:: passed: letters == letters for: "abcdefcg" == "abcdefcg" -String.tests.cpp:: passed: Catch::replaceInPlace( s, "'", "|'" ) for: true -String.tests.cpp:: passed: s == "didn|'t" for: "didn|'t" == "didn|'t" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(letters, "b", "z") for: true +StringManip.tests.cpp:: passed: letters == "azcdefcg" for: "azcdefcg" == "azcdefcg" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(letters, "c", "z") for: true +StringManip.tests.cpp:: passed: letters == "abzdefzg" for: "abzdefzg" == "abzdefzg" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(letters, "a", "z") for: true +StringManip.tests.cpp:: passed: letters == "zbcdefcg" for: "zbcdefcg" == "zbcdefcg" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(letters, "g", "z") for: true +StringManip.tests.cpp:: passed: letters == "abcdefcz" for: "abcdefcz" == "abcdefcz" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(letters, letters, "replaced") for: true +StringManip.tests.cpp:: passed: letters == "replaced" for: "replaced" == "replaced" +StringManip.tests.cpp:: passed: !(Catch::replaceInPlace(letters, "x", "z")) for: !false +StringManip.tests.cpp:: passed: letters == letters for: "abcdefcg" == "abcdefcg" +StringManip.tests.cpp:: passed: Catch::replaceInPlace(s, "'", "|'") for: true +StringManip.tests.cpp:: passed: s == "didn|'t" for: "didn|'t" == "didn|'t" Misc.tests.cpp:: failed: false with 1 message: '3' Message.tests.cpp:: failed: false with 2 messages: 'hi' and 'i := 7' Tag.tests.cpp:: passed: testcase.tags, Catch::VectorContains(std::string("magic-tag")) && Catch::VectorContains(std::string(".")) for: { ".", "magic-tag" } ( Contains: "magic-tag" and Contains: "." ) -String.tests.cpp:: passed: splitStringRef("", ',' ), Equals(std::vector() ) for: { } Equals: { } -String.tests.cpp:: passed: splitStringRef("abc", ',' ), Equals(std::vector{"abc"} ) for: { abc } Equals: { abc } -String.tests.cpp:: passed: splitStringRef("abc,def", ',' ), Equals(std::vector{"abc", "def"} ) for: { abc, def } Equals: { abc, def } +StringManip.tests.cpp:: passed: splitStringRef("", ','), Equals(std::vector()) for: { } Equals: { } +StringManip.tests.cpp:: passed: splitStringRef("abc", ','), Equals(std::vector{"abc"}) for: { abc } Equals: { abc } +StringManip.tests.cpp:: passed: splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) for: { abc, def } Equals: { abc, def } Message.tests.cpp:: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' Message.tests.cpp:: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6' ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( emptyMap ) == "{ }" for: "{ }" == "{ }" diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 11eedbb4..6a0ac776 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -11441,15 +11441,15 @@ with expansion: replaceInPlace replace single char ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( letters, "b", "z" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(letters, "b", "z") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == "azcdefcg" ) with expansion: "azcdefcg" == "azcdefcg" @@ -11458,15 +11458,15 @@ with expansion: replaceInPlace replace two chars ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( letters, "c", "z" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(letters, "c", "z") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == "abzdefzg" ) with expansion: "abzdefzg" == "abzdefzg" @@ -11475,15 +11475,15 @@ with expansion: replaceInPlace replace first char ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( letters, "a", "z" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(letters, "a", "z") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == "zbcdefcg" ) with expansion: "zbcdefcg" == "zbcdefcg" @@ -11492,15 +11492,15 @@ with expansion: replaceInPlace replace last char ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( letters, "g", "z" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(letters, "g", "z") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == "abcdefcz" ) with expansion: "abcdefcz" == "abcdefcz" @@ -11509,15 +11509,15 @@ with expansion: replaceInPlace replace all chars ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( letters, letters, "replaced" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(letters, letters, "replaced") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == "replaced" ) with expansion: "replaced" == "replaced" @@ -11526,15 +11526,15 @@ with expansion: replaceInPlace replace no chars ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK_FALSE( Catch::replaceInPlace( letters, "x", "z" ) ) +StringManip.tests.cpp:: PASSED: + CHECK_FALSE( Catch::replaceInPlace(letters, "x", "z") ) with expansion: !false -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( letters == letters ) with expansion: "abcdefcg" == "abcdefcg" @@ -11543,15 +11543,15 @@ with expansion: replaceInPlace escape ' ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK( Catch::replaceInPlace( s, "'", "|'" ) ) +StringManip.tests.cpp:: PASSED: + CHECK( Catch::replaceInPlace(s, "'", "|'") ) with expansion: true -String.tests.cpp:: PASSED: +StringManip.tests.cpp:: PASSED: CHECK( s == "didn|'t" ) with expansion: "didn|'t" == "didn|'t" @@ -11602,21 +11602,21 @@ with expansion: ------------------------------------------------------------------------------- splitString ------------------------------------------------------------------------------- -String.tests.cpp: +StringManip.tests.cpp: ............................................................................... -String.tests.cpp:: PASSED: - CHECK_THAT( splitStringRef("", ',' ), Equals(std::vector() ) ) +StringManip.tests.cpp:: PASSED: + CHECK_THAT( splitStringRef("", ','), Equals(std::vector()) ) with expansion: { } Equals: { } -String.tests.cpp:: PASSED: - CHECK_THAT( splitStringRef("abc", ',' ), Equals(std::vector{"abc"} ) ) +StringManip.tests.cpp:: PASSED: + CHECK_THAT( splitStringRef("abc", ','), Equals(std::vector{"abc"}) ) with expansion: { abc } Equals: { abc } -String.tests.cpp:: PASSED: - CHECK_THAT( splitStringRef("abc,def", ',' ), Equals(std::vector{"abc", "def"} ) ) +StringManip.tests.cpp:: PASSED: + CHECK_THAT( splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) ) with expansion: { abc, def } Equals: { abc, def } diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 03c11cde..67e85dd8 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -13732,17 +13732,17 @@ loose text artifact - -
- + +
+ - Catch::replaceInPlace( letters, "b", "z" ) + Catch::replaceInPlace(letters, "b", "z") true - + letters == "azcdefcg" @@ -13752,16 +13752,16 @@ loose text artifact
-
- +
+ - Catch::replaceInPlace( letters, "c", "z" ) + Catch::replaceInPlace(letters, "c", "z") true - + letters == "abzdefzg" @@ -13771,16 +13771,16 @@ loose text artifact
-
- +
+ - Catch::replaceInPlace( letters, "a", "z" ) + Catch::replaceInPlace(letters, "a", "z") true - + letters == "zbcdefcg" @@ -13790,16 +13790,16 @@ loose text artifact
-
- +
+ - Catch::replaceInPlace( letters, "g", "z" ) + Catch::replaceInPlace(letters, "g", "z") true - + letters == "abcdefcz" @@ -13809,16 +13809,16 @@ loose text artifact
-
- +
+ - Catch::replaceInPlace( letters, letters, "replaced" ) + Catch::replaceInPlace(letters, letters, "replaced") true - + letters == "replaced" @@ -13828,16 +13828,16 @@ loose text artifact
-
- +
+ - !(Catch::replaceInPlace( letters, "x", "z" )) + !(Catch::replaceInPlace(letters, "x", "z")) !false - + letters == letters @@ -13847,16 +13847,16 @@ loose text artifact
-
- +
+ - Catch::replaceInPlace( s, "'", "|'" ) + Catch::replaceInPlace(s, "'", "|'") true - + s == "didn|'t" @@ -13913,26 +13913,26 @@ loose text artifact - - + + - splitStringRef("", ',' ), Equals(std::vector<StringRef>() ) + splitStringRef("", ','), Equals(std::vector<StringRef>()) { } Equals: { } - + - splitStringRef("abc", ',' ), Equals(std::vector<StringRef>{"abc"} ) + splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) { abc } Equals: { abc } - + - splitStringRef("abc,def", ',' ), Equals(std::vector<StringRef>{"abc", "def"} ) + splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) { abc, def } Equals: { abc, def } diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp index aedd2f38..6a888f90 100644 --- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp @@ -160,48 +160,3 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { } } } - -TEST_CASE( "replaceInPlace", "[Strings][StringManip]" ) { - std::string letters = "abcdefcg"; - SECTION( "replace single char" ) { - CHECK( Catch::replaceInPlace( letters, "b", "z" ) ); - CHECK( letters == "azcdefcg" ); - } - SECTION( "replace two chars" ) { - CHECK( Catch::replaceInPlace( letters, "c", "z" ) ); - CHECK( letters == "abzdefzg" ); - } - SECTION( "replace first char" ) { - CHECK( Catch::replaceInPlace( letters, "a", "z" ) ); - CHECK( letters == "zbcdefcg" ); - } - SECTION( "replace last char" ) { - CHECK( Catch::replaceInPlace( letters, "g", "z" ) ); - CHECK( letters == "abcdefcz" ); - } - SECTION( "replace all chars" ) { - CHECK( Catch::replaceInPlace( letters, letters, "replaced" ) ); - CHECK( letters == "replaced" ); - } - SECTION( "replace no chars" ) { - CHECK_FALSE( Catch::replaceInPlace( letters, "x", "z" ) ); - CHECK( letters == letters ); - } - SECTION( "escape '" ) { - std::string s = "didn't"; - CHECK( Catch::replaceInPlace( s, "'", "|'" ) ); - CHECK( s == "didn|'t" ); - } -} - -TEST_CASE( "splitString", "[Strings]" ) { - using namespace Catch::Matchers; - using Catch::splitStringRef; - using Catch::StringRef; - - CHECK_THAT( splitStringRef("", ',' ), Equals(std::vector() ) ); - CHECK_THAT( splitStringRef("abc", ',' ), Equals(std::vector{"abc"} ) ); - CHECK_THAT( splitStringRef("abc,def", ',' ), Equals(std::vector{"abc", "def"} ) ); -} - - diff --git a/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp index e0b00565..b817f372 100644 --- a/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp @@ -22,3 +22,46 @@ TEST_CASE("Trim strings", "[string-manip]") { REQUIRE(trim(StringRef(trailing_whitespace)) == StringRef(no_whitespace)); REQUIRE(trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace)); } + +TEST_CASE("replaceInPlace", "[string-manip]") { + std::string letters = "abcdefcg"; + SECTION("replace single char") { + CHECK(Catch::replaceInPlace(letters, "b", "z")); + CHECK(letters == "azcdefcg"); + } + SECTION("replace two chars") { + CHECK(Catch::replaceInPlace(letters, "c", "z")); + CHECK(letters == "abzdefzg"); + } + SECTION("replace first char") { + CHECK(Catch::replaceInPlace(letters, "a", "z")); + CHECK(letters == "zbcdefcg"); + } + SECTION("replace last char") { + CHECK(Catch::replaceInPlace(letters, "g", "z")); + CHECK(letters == "abcdefcz"); + } + SECTION("replace all chars") { + CHECK(Catch::replaceInPlace(letters, letters, "replaced")); + CHECK(letters == "replaced"); + } + SECTION("replace no chars") { + CHECK_FALSE(Catch::replaceInPlace(letters, "x", "z")); + CHECK(letters == letters); + } + SECTION("escape '") { + std::string s = "didn't"; + CHECK(Catch::replaceInPlace(s, "'", "|'")); + CHECK(s == "didn|'t"); + } +} + +TEST_CASE("splitString", "[string-manip]") { + using namespace Catch::Matchers; + using Catch::splitStringRef; + using Catch::StringRef; + + CHECK_THAT(splitStringRef("", ','), Equals(std::vector())); + CHECK_THAT(splitStringRef("abc", ','), Equals(std::vector{"abc"})); + CHECK_THAT(splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"})); +}