Add tests for case insensitive string matching

This commit is contained in:
Martin Hořeňovský 2017-11-13 15:46:33 +01:00
parent b0857e846f
commit 55b71bebf1
5 changed files with 223 additions and 51 deletions

View File

@ -145,9 +145,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Contains( "not there" ) )
CHECK_THAT( testStringForMatching(), Contains( "not there", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" contains: "not there"
"this string contains 'abc' as a substring" contains: "not there" (case
insensitive)
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Contains( "STRING" ) )
with expansion:
"this string contains 'abc' as a substring" contains: "STRING"
-------------------------------------------------------------------------------
Custom exceptions can be translated when testing for nothrow
@ -188,9 +194,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), EndsWith( "this" ) )
CHECK_THAT( testStringForMatching(), EndsWith( "Substring" ) )
with expansion:
"this string contains 'abc' as a substring" ends with: "this"
"this string contains 'abc' as a substring" ends with: "Substring"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" ends with: "this" (case
insensitive)
-------------------------------------------------------------------------------
Equality checks that should fail
@ -270,9 +282,16 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Equals( "something else" ) )
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'ABC' as a substring" ) )
with expansion:
"this string contains 'abc' as a substring" equals: "something else"
"this string contains 'abc' as a substring" equals: "this string contains
'ABC' as a substring"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Equals( "something else", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" equals: "something else" (case
insensitive)
-------------------------------------------------------------------------------
Exception matchers that fail
@ -690,9 +709,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), StartsWith( "string" ) )
CHECK_THAT( testStringForMatching(), StartsWith( "This String" ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "string"
"this string contains 'abc' as a substring" starts with: "This String"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "string" (case
insensitive)
-------------------------------------------------------------------------------
Tabs and newlines show in output
@ -1027,6 +1052,6 @@ with expansion:
"{?}" == "1"
===============================================================================
test cases: 189 | 137 passed | 48 failed | 4 failed as expected
assertions: 948 | 828 passed | 99 failed | 21 failed as expected
test cases: 189 | 137 passed | 48 failed | 4 failed as expected
assertions: 957 | 833 passed | 103 failed | 21 failed as expected

View File

@ -1315,9 +1315,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Contains( "not there" ) )
CHECK_THAT( testStringForMatching(), Contains( "not there", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" contains: "not there"
"this string contains 'abc' as a substring" contains: "not there" (case
insensitive)
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Contains( "STRING" ) )
with expansion:
"this string contains 'abc' as a substring" contains: "STRING"
-------------------------------------------------------------------------------
Custom exceptions can be translated when testing for nothrow
@ -1376,9 +1382,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), EndsWith( "this" ) )
CHECK_THAT( testStringForMatching(), EndsWith( "Substring" ) )
with expansion:
"this string contains 'abc' as a substring" ends with: "this"
"this string contains 'abc' as a substring" ends with: "Substring"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" ends with: "this" (case
insensitive)
-------------------------------------------------------------------------------
Epsilon only applies to Approx's value
@ -1524,6 +1536,13 @@ with expansion:
"this string contains 'abc' as a substring" equals: "this string contains
'abc' as a substring"
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'ABC' as a substring", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" equals: "this string contains
'abc' as a substring" (case insensitive)
-------------------------------------------------------------------------------
Equals string matcher
-------------------------------------------------------------------------------
@ -1531,9 +1550,16 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Equals( "something else" ) )
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'ABC' as a substring" ) )
with expansion:
"this string contains 'abc' as a substring" equals: "something else"
"this string contains 'abc' as a substring" equals: "this string contains
'ABC' as a substring"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), Equals( "something else", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" equals: "something else" (case
insensitive)
-------------------------------------------------------------------------------
Exception matchers that fail
@ -4636,9 +4662,15 @@ MatchersTests.cpp:<line number>
...............................................................................
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), StartsWith( "string" ) )
CHECK_THAT( testStringForMatching(), StartsWith( "This String" ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "string"
"this string contains 'abc' as a substring" starts with: "This String"
MatchersTests.cpp:<line number>: FAILED:
CHECK_THAT( testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "string" (case
insensitive)
-------------------------------------------------------------------------------
String matchers
@ -4652,24 +4684,52 @@ PASSED:
with expansion:
"this string contains 'abc' as a substring" contains: "string"
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( testStringForMatching(), Contains( "string", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" contains: "string" (case
insensitive)
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), Contains( "abc" ) )
with expansion:
"this string contains 'abc' as a substring" contains: "abc"
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), Contains( "aBC", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" contains: "abc" (case insensitive)
insensitive)
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), StartsWith( "this" ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "this"
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), StartsWith( "THIS", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" starts with: "this" (case
insensitive)
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) )
with expansion:
"this string contains 'abc' as a substring" ends with: "substring"
MatchersTests.cpp:<line number>:
PASSED:
CHECK_THAT( testStringForMatching(), EndsWith(" SuBsTrInG", Catch::CaseSensitive::No ) )
with expansion:
"this string contains 'abc' as a substring" ends with: " substring" (case
insensitive)
MatchersTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( testStringForMatching(), Matches("this string contains 'abc' as a substring") )
@ -7963,5 +8023,5 @@ PASSED:
===============================================================================
test cases: 189 | 135 passed | 50 failed | 4 failed as expected
assertions: 947 | 824 passed | 102 failed | 21 failed as expected
assertions: 956 | 829 passed | 106 failed | 21 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="15" failures="88" tests="948" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="15" failures="92" tests="957" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@ -126,7 +126,10 @@ ExceptionTests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Comparisons with int literals don't warn when mixing signed/ unsigned" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Contains string matcher" time="{duration}">
<failure message="&quot;this string contains 'abc' as a substring&quot; contains: &quot;not there&quot;" type="CHECK_THAT">
<failure message="&quot;this string contains 'abc' as a substring&quot; contains: &quot;not there&quot; (case insensitive)" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
<failure message="&quot;this string contains 'abc' as a substring&quot; contains: &quot;STRING&quot;" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
</testcase>
@ -150,7 +153,10 @@ ExceptionTests.cpp:<line number>
</testcase>
<testcase classname="<exe-name>.global" name="Default scale is invisible to comparison" time="{duration}"/>
<testcase classname="<exe-name>.global" name="EndsWith string matcher" time="{duration}">
<failure message="&quot;this string contains 'abc' as a substring&quot; ends with: &quot;this&quot;" type="CHECK_THAT">
<failure message="&quot;this string contains 'abc' as a substring&quot; ends with: &quot;Substring&quot;" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
<failure message="&quot;this string contains 'abc' as a substring&quot; ends with: &quot;this&quot; (case insensitive)" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
</testcase>
@ -199,7 +205,10 @@ ConditionTests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Equality checks that should succeed" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Equals" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Equals string matcher" time="{duration}">
<failure message="&quot;this string contains 'abc' as a substring&quot; equals: &quot;something else&quot;" type="CHECK_THAT">
<failure message="&quot;this string contains 'abc' as a substring&quot; equals: &quot;this string contains 'ABC' as a substring&quot;" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
<failure message="&quot;this string contains 'abc' as a substring&quot; equals: &quot;something else&quot; (case insensitive)" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
</testcase>
@ -518,7 +527,10 @@ Message from section two
</system-out>
</testcase>
<testcase classname="<exe-name>.global" name="StartsWith string matcher" time="{duration}">
<failure message="&quot;this string contains 'abc' as a substring&quot; starts with: &quot;string&quot;" type="CHECK_THAT">
<failure message="&quot;this string contains 'abc' as a substring&quot; starts with: &quot;This String&quot;" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
<failure message="&quot;this string contains 'abc' as a substring&quot; starts with: &quot;string&quot; (case insensitive)" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
</testcase>

View File

@ -1469,10 +1469,18 @@
<TestCase name="Contains string matcher" tags="[.][failing][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" >
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Contains( "not there" )
testStringForMatching(), Contains( "not there", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" contains: "not there"
"this string contains 'abc' as a substring" contains: "not there" (case insensitive)
</Expanded>
</Expression>
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Contains( "STRING" )
</Original>
<Expanded>
"this string contains 'abc' as a substring" contains: "STRING"
</Expanded>
</Expression>
<OverallResult success="false"/>
@ -1533,10 +1541,18 @@
<TestCase name="EndsWith string matcher" tags="[.][failing][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" >
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), EndsWith( "this" )
testStringForMatching(), EndsWith( "Substring" )
</Original>
<Expanded>
"this string contains 'abc' as a substring" ends with: "this"
"this string contains 'abc' as a substring" ends with: "Substring"
</Expanded>
</Expression>
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" ends with: "this" (case insensitive)
</Expanded>
</Expression>
<OverallResult success="false"/>
@ -1727,15 +1743,31 @@
"this string contains 'abc' as a substring" equals: "this string contains 'abc' as a substring"
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Equals( "this string contains 'ABC' as a substring", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" equals: "this string contains 'abc' as a substring" (case insensitive)
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Equals string matcher" tags="[.][failing][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" >
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Equals( "something else" )
testStringForMatching(), Equals( "this string contains 'ABC' as a substring" )
</Original>
<Expanded>
"this string contains 'abc' as a substring" equals: "something else"
"this string contains 'abc' as a substring" equals: "this string contains 'ABC' as a substring"
</Expanded>
</Expression>
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Equals( "something else", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" equals: "something else" (case insensitive)
</Expanded>
</Expression>
<OverallResult success="false"/>
@ -5307,10 +5339,18 @@ Message from section two
<TestCase name="StartsWith string matcher" tags="[.][failing][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" >
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), StartsWith( "string" )
testStringForMatching(), StartsWith( "This String" )
</Original>
<Expanded>
"this string contains 'abc' as a substring" starts with: "string"
"this string contains 'abc' as a substring" starts with: "This String"
</Expanded>
</Expression>
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" starts with: "string" (case insensitive)
</Expanded>
</Expression>
<OverallResult success="false"/>
@ -5324,6 +5364,14 @@ Message from section two
"this string contains 'abc' as a substring" contains: "string"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Contains( "string", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" contains: "string" (case insensitive)
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Contains( "abc" )
@ -5332,6 +5380,14 @@ Message from section two
"this string contains 'abc' as a substring" contains: "abc"
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Contains( "aBC", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" contains: "abc" (case insensitive)
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), StartsWith( "this" )
@ -5340,6 +5396,14 @@ Message from section two
"this string contains 'abc' as a substring" starts with: "this"
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), StartsWith( "THIS", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" starts with: "this" (case insensitive)
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), EndsWith( "substring" )
@ -5348,6 +5412,14 @@ Message from section two
"this string contains 'abc' as a substring" ends with: "substring"
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), EndsWith(" SuBsTrInG", Catch::CaseSensitive::No )
</Original>
<Expanded>
"this string contains 'abc' as a substring" ends with: " substring" (case insensitive)
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
testStringForMatching(), Matches("this string contains 'abc' as a substring")
@ -8831,7 +8903,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="824" failures="103" expectedFailures="21"/>
<OverallResults successes="829" failures="107" expectedFailures="21"/>
</Group>
<OverallResults successes="824" failures="102" expectedFailures="21"/>
<OverallResults successes="829" failures="106" expectedFailures="21"/>
</Catch>

View File

@ -29,13 +29,16 @@ inline const char* testStringForMatching2()
using namespace Catch::Matchers;
TEST_CASE("String matchers", "[matchers]" )
{
TEST_CASE("String matchers", "[matchers]" ) {
REQUIRE_THAT( testStringForMatching(), Contains( "string" ) );
REQUIRE_THAT( testStringForMatching(), Contains( "string", Catch::CaseSensitive::No ));
CHECK_THAT( testStringForMatching(), Contains( "abc" ) );
CHECK_THAT( testStringForMatching(), Contains( "aBC", Catch::CaseSensitive::No ));
CHECK_THAT( testStringForMatching(), StartsWith( "this" ) );
CHECK_THAT( testStringForMatching(), StartsWith( "THIS", Catch::CaseSensitive::No ));
CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) );
CHECK_THAT( testStringForMatching(), EndsWith(" SuBsTrInG", Catch::CaseSensitive::No ));
REQUIRE_THAT(testStringForMatching(), Matches("this string contains 'abc' as a substring"));
REQUIRE_THAT(testStringForMatching(), Matches("this string CONTAINS 'abc' as a substring", Catch::CaseSensitive::No));
@ -44,29 +47,29 @@ TEST_CASE("String matchers", "[matchers]" )
REQUIRE_THAT(testStringForMatching(), Matches("^.* 'ABC' .*$", Catch::CaseSensitive::No));
}
TEST_CASE("Contains string matcher", "[.][failing][matchers]")
{
CHECK_THAT( testStringForMatching(), Contains( "not there" ) );
TEST_CASE("Contains string matcher", "[.][failing][matchers]") {
CHECK_THAT( testStringForMatching(), Contains( "not there", Catch::CaseSensitive::No ) );
CHECK_THAT( testStringForMatching(), Contains( "STRING" ));
}
TEST_CASE("StartsWith string matcher", "[.][failing][matchers]")
{
CHECK_THAT( testStringForMatching(), StartsWith( "string" ) );
TEST_CASE("StartsWith string matcher", "[.][failing][matchers]") {
CHECK_THAT( testStringForMatching(), StartsWith( "This String" ));
CHECK_THAT( testStringForMatching(), StartsWith( "string", Catch::CaseSensitive::No ) );
}
TEST_CASE("EndsWith string matcher", "[.][failing][matchers]")
{
CHECK_THAT( testStringForMatching(), EndsWith( "this" ) );
TEST_CASE("EndsWith string matcher", "[.][failing][matchers]") {
CHECK_THAT( testStringForMatching(), EndsWith( "Substring" ));
CHECK_THAT( testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) );
}
TEST_CASE("Equals string matcher", "[.][failing][matchers]")
{
CHECK_THAT( testStringForMatching(), Equals( "something else" ) );
TEST_CASE("Equals string matcher", "[.][failing][matchers]") {
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'ABC' as a substring" ) );
CHECK_THAT( testStringForMatching(), Equals( "something else", Catch::CaseSensitive::No ));
}
TEST_CASE("Equals", "[matchers]")
{
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) );
TEST_CASE("Equals", "[matchers]") {
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ));
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'ABC' as a substring", Catch::CaseSensitive::No ) );
}
TEST_CASE("Regex string matcher", "[matchers][.failing]") {