mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Remove fixture of tests in test_matcher
The fixture is not really required and can be replaced by definitions in each test which even improves readability. Also the tests are partially redundant due to implicit conversions so add test in test_function for actual usage testing of string comparisons.
This commit is contained in:
parent
fa29eec0bb
commit
700ceb9f4d
2 changed files with 63 additions and 20 deletions
|
|
@ -33,46 +33,39 @@ BOOST_AUTO_TEST_CASE(ref_to_int_and_int_can_be_compared)
|
|||
BOOST_CHECK(!match(4, std::cref(i)));
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct fixture
|
||||
{
|
||||
fixture() : text("same text"), actual(text.c_str())
|
||||
{
|
||||
const char* static_string = "same text";
|
||||
BOOST_REQUIRE(actual != static_string);
|
||||
BOOST_REQUIRE(actual == std::string(static_string));
|
||||
}
|
||||
std::string text;
|
||||
const char* actual;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture)
|
||||
BOOST_AUTO_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared)
|
||||
{
|
||||
const char* expected = "same text";
|
||||
const char* actual = "same text";
|
||||
BOOST_REQUIRE(expected != actual); // Different pointer values
|
||||
BOOST_CHECK(match(expected, actual));
|
||||
const char* unexpected = "different text";
|
||||
BOOST_CHECK(!match(actual, unexpected));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_string_literal_can_be_compared, fixture)
|
||||
BOOST_AUTO_TEST_CASE(const_char_pointer_and_string_literal_can_be_compared)
|
||||
{
|
||||
const char* actual = "same text";
|
||||
BOOST_CHECK(match("same text", actual));
|
||||
BOOST_CHECK(!match("different text", actual));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_array_can_be_compared, fixture)
|
||||
BOOST_AUTO_TEST_CASE(const_char_pointer_and_const_char_array_can_be_compared)
|
||||
{
|
||||
const char expected[10] = "same text";
|
||||
const char* actual = "same text";
|
||||
const char expected[] = "same text";
|
||||
BOOST_CHECK(match(expected, actual));
|
||||
const char unexpected[15] = "different text";
|
||||
const char unexpected[] = "different text";
|
||||
BOOST_CHECK(!match(unexpected, actual));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_std_string_can_be_compared, fixture)
|
||||
BOOST_AUTO_TEST_CASE(const_char_pointer_and_std_string_can_be_compared)
|
||||
{
|
||||
const char* actual = "same text";
|
||||
BOOST_CHECK(match(std::string("same text"), actual));
|
||||
BOOST_CHECK(match(actual, std::string("same text")));
|
||||
BOOST_CHECK(!match(std::string("different text"), actual));
|
||||
BOOST_CHECK(!match(actual, std::string("different text")));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(null_const_char_pointers_can_be_compared)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue