Add tests for StringRef's copy operations being shallow

This commit is contained in:
Martin Jeřábek 2021-03-08 14:57:59 +01:00 committed by Martin Hořeňovský
parent 72a09de236
commit 8711b63a0a
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
8 changed files with 72 additions and 6 deletions

View File

@ -1554,6 +1554,8 @@ String.tests.cpp:<line number>: passed: std::strcmp( rawChars, "hello" ) == 0 fo
String.tests.cpp:<line number>: passed: s.data() == rawChars for: "hello" == "hello"
String.tests.cpp:<line number>: passed: original == "original"
String.tests.cpp:<line number>: passed: original.data()
String.tests.cpp:<line number>: passed: original.begin() == copy.begin() for: "original string" == "original string"
String.tests.cpp:<line number>: passed: original.begin() == copy.begin() for: "original string" == "original string"
String.tests.cpp:<line number>: passed: ss.empty() == false for: false == false
String.tests.cpp:<line number>: passed: ss.size() == 5 for: 5 == 5
String.tests.cpp:<line number>: passed: std::strncmp( ss.data(), "hello", 5 ) == 0 for: 0 == 0

View File

@ -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

View File

@ -11079,6 +11079,30 @@ String.tests.cpp:<line number>: PASSED:
String.tests.cpp:<line number>: PASSED:
REQUIRE_NOTHROW( original.data() )
-------------------------------------------------------------------------------
StringRef
Copy construction is shallow
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( original.begin() == copy.begin() )
with expansion:
"original string" == "original string"
-------------------------------------------------------------------------------
StringRef
Copy assignment is shallow
-------------------------------------------------------------------------------
String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
REQUIRE( original.begin() == copy.begin() )
with expansion:
"original string" == "original string"
-------------------------------------------------------------------------------
StringRef
Substrings
@ -17541,5 +17565,5 @@ Misc.tests.cpp:<line number>: 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="129" tests="2200" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" tests="2202" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@ -1235,6 +1235,8 @@ Matchers.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="StringRef/Empty string" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/From string literal" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/From sub-string" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/Copy construction is shallow" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/Copy assignment is shallow" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/zero-based substring" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/non-zero-based substring" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="StringRef/Substrings/Pointer values of full refs should match" time="{duration}" status="run"/>

View File

@ -210,6 +210,8 @@
<testCase name="StringRef/Empty string" duration="{duration}"/>
<testCase name="StringRef/From string literal" duration="{duration}"/>
<testCase name="StringRef/From sub-string" duration="{duration}"/>
<testCase name="StringRef/Copy construction is shallow" duration="{duration}"/>
<testCase name="StringRef/Copy assignment is shallow" duration="{duration}"/>
<testCase name="StringRef/Substrings/zero-based substring" duration="{duration}"/>
<testCase name="StringRef/Substrings/non-zero-based substring" duration="{duration}"/>
<testCase name="StringRef/Substrings/Pointer values of full refs should match" duration="{duration}"/>

View File

@ -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

View File

@ -13222,6 +13222,28 @@ Message from section two
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="Copy construction is shallow" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Original>
original.begin() == copy.begin()
</Original>
<Expanded>
"original string" == "original string"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Copy assignment is shallow" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Original>
original.begin() == copy.begin()
</Original>
<Expanded>
"original string" == "original string"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Substrings" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Section name="zero-based substring" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
@ -20573,6 +20595,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2027" failures="146" expectedFailures="27"/>
<OverallResults successes="2029" failures="146" expectedFailures="27"/>
<OverallResultsCases successes="291" failures="86" expectedFailures="7"/>
</Catch2TestRun>

View File

@ -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!";