From 8711b63a0a7a64e0b0e65f41971a3a8c27ab7a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Je=C5=99=C3=A1bek?= Date: Mon, 8 Mar 2021 14:57:59 +0100 Subject: [PATCH] Add tests for StringRef's copy operations being shallow --- .../Baselines/compact.sw.approved.txt | 2 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 26 ++++++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 4 ++- .../Baselines/sonarqube.sw.approved.txt | 2 ++ tests/SelfTest/Baselines/tap.sw.approved.txt | 6 ++++- tests/SelfTest/Baselines/xml.sw.approved.txt | 24 ++++++++++++++++- .../IntrospectiveTests/String.tests.cpp | 12 ++++++++- 8 files changed, 72 insertions(+), 6 deletions(-) diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index fab13bf2..390e9a6e 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1554,6 +1554,8 @@ String.tests.cpp:: passed: std::strcmp( rawChars, "hello" ) == 0 fo String.tests.cpp:: passed: s.data() == rawChars for: "hello" == "hello" String.tests.cpp:: passed: original == "original" String.tests.cpp:: passed: original.data() +String.tests.cpp:: passed: original.begin() == copy.begin() for: "original string" == "original string" +String.tests.cpp:: passed: original.begin() == copy.begin() for: "original string" == "original string" String.tests.cpp:: passed: ss.empty() == false for: false == false String.tests.cpp:: passed: ss.size() == 5 for: 5 == 5 String.tests.cpp:: passed: std::strncmp( ss.data(), "hello", 5 ) == 0 for: 0 == 0 diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 92b8d9d9..fb5b2b28 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1427,5 +1427,5 @@ due to unexpected exception with message: =============================================================================== test cases: 384 | 307 passed | 70 failed | 7 failed as expected -assertions: 2183 | 2027 passed | 129 failed | 27 failed as expected +assertions: 2185 | 2029 passed | 129 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index ac9f7eee..65baafcf 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -11079,6 +11079,30 @@ String.tests.cpp:: PASSED: String.tests.cpp:: PASSED: REQUIRE_NOTHROW( original.data() ) +------------------------------------------------------------------------------- +StringRef + Copy construction is shallow +------------------------------------------------------------------------------- +String.tests.cpp: +............................................................................... + +String.tests.cpp:: PASSED: + REQUIRE( original.begin() == copy.begin() ) +with expansion: + "original string" == "original string" + +------------------------------------------------------------------------------- +StringRef + Copy assignment is shallow +------------------------------------------------------------------------------- +String.tests.cpp: +............................................................................... + +String.tests.cpp:: PASSED: + REQUIRE( original.begin() == copy.begin() ) +with expansion: + "original string" == "original string" + ------------------------------------------------------------------------------- StringRef Substrings @@ -17541,5 +17565,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 384 | 291 passed | 86 failed | 7 failed as expected -assertions: 2200 | 2027 passed | 146 failed | 27 failed as expected +assertions: 2202 | 2029 passed | 146 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index a82176bd..9132e982 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1235,6 +1235,8 @@ Matchers.tests.cpp: + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 72c2e692..ee0df2e4 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -210,6 +210,8 @@ + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index e3d75dd8..0a587189 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -2792,6 +2792,10 @@ ok {test-number} - original == "original" # StringRef ok {test-number} - original.data() # StringRef +ok {test-number} - original.begin() == copy.begin() for: "original string" == "original string" +# StringRef +ok {test-number} - original.begin() == copy.begin() for: "original string" == "original string" +# StringRef ok {test-number} - ss.empty() == false for: false == false # StringRef ok {test-number} - ss.size() == 5 for: 5 == 5 @@ -4402,5 +4406,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2200 +1..2202 diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 2551e03b..fd542b29 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -13222,6 +13222,28 @@ Message from section two +
+ + + original.begin() == copy.begin() + + + "original string" == "original string" + + + +
+
+ + + original.begin() == copy.begin() + + + "original string" == "original string" + + + +
@@ -20573,6 +20595,6 @@ loose text artifact
- + diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp index 9fd8a780..6245ca77 100644 --- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp @@ -29,7 +29,17 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { 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!";