Review corrections

Corrected stylistic mistakes and simplified a couple of the new tests.
This commit is contained in:
Alex Smith 2023-01-03 16:28:27 +00:00
parent dd7340e5f7
commit e55342385e
4 changed files with 6 additions and 7 deletions

View file

@ -41,7 +41,7 @@ public:
explicit matcher(const char* expected) : expected_(expected) {} explicit matcher(const char* expected) : expected_(expected) {}
bool operator()(const char* actual) bool operator()(const char* actual)
{ {
if (nullptr == actual || nullptr == expected_) if(!actual || !expected_)
return actual == expected_; return actual == expected_;
return std::strcmp(actual, expected_) == 0; return std::strcmp(actual, expected_) == 0;
} }

View file

@ -108,7 +108,7 @@ namespace detail {
} }
inline void serialize(stream& s, const char* const str) inline void serialize(stream& s, const char* const str)
{ {
if (nullptr != str) if(str)
s << '"' << str << '"'; s << '"' << str << '"';
else else
s << "nullptr"; s << "nullptr";

View file

@ -93,8 +93,7 @@ BOOST_AUTO_TEST_CASE(null_c_strings_are_serialized_to_nullptr)
{ {
const char* const null_str = nullptr; const char* const null_str = nullptr;
BOOST_CHECK_EQUAL("nullptr", to_string(null_str)); BOOST_CHECK_EQUAL("nullptr", to_string(null_str));
// Note the lack of double quotes in the output, as opposed to when the BOOST_CHECK_EQUAL("\"nullptr\"", to_string("nullptr"));
// string "nullptr" is serialized.
} }
namespace { namespace {

View file

@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(ref_to_int_and_int_can_be_compared)
namespace { namespace {
struct fixture struct fixture
{ {
fixture() : text("same text"), actual(text.c_str()), null_str(nullptr) fixture() : text("same text"), actual(text.c_str())
{ {
const char* static_string = "same text"; const char* static_string = "same text";
BOOST_REQUIRE(actual != static_string); BOOST_REQUIRE(actual != static_string);
@ -44,7 +44,6 @@ struct fixture
} }
std::string text; std::string text;
const char* actual; const char* actual;
const char* null_str;
}; };
} // namespace } // namespace
@ -76,8 +75,9 @@ BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_std_string_can_be_compared, fixtu
BOOST_CHECK(!match(std::string("different text"), actual)); BOOST_CHECK(!match(std::string("different text"), actual));
} }
BOOST_FIXTURE_TEST_CASE(null_const_char_pointers_can_be_compared, fixture) BOOST_AUTO_TEST_CASE(null_const_char_pointers_can_be_compared)
{ {
const char* const null_str = nullptr;
BOOST_CHECK(match(null_str, null_str)); BOOST_CHECK(match(null_str, null_str));
BOOST_CHECK(!match(null_str, "non-null string")); BOOST_CHECK(!match(null_str, "non-null string"));
BOOST_CHECK(!match("non-null string", null_str)); BOOST_CHECK(!match("non-null string", null_str));