mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Strings are surrounded with " by mock::format
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@11 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
1bee70f758
commit
a03f8d7ceb
6 changed files with 35 additions and 15 deletions
|
|
@ -46,7 +46,7 @@ namespace detail
|
||||||
BOOST_DEDUCED_TYPENAME detail::is_functor< T >::type
|
BOOST_DEDUCED_TYPENAME detail::is_functor< T >::type
|
||||||
>::type* = 0 )
|
>::type* = 0 )
|
||||||
: functor_( equal( t ).functor_ )
|
: functor_( equal( t ).functor_ )
|
||||||
, desc_ ( detail::format( t ) )
|
, desc_ ( mock::format( t ) )
|
||||||
{
|
{
|
||||||
if( !functor_ )
|
if( !functor_ )
|
||||||
std::invalid_argument( "invalid functor" );
|
std::invalid_argument( "invalid functor" );
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace mock
|
||||||
const T& t )
|
const T& t )
|
||||||
{
|
{
|
||||||
return detail::placeholder< Functor >( f,
|
return detail::placeholder< Functor >( f,
|
||||||
name + "( " + detail::format( t ) + " )" );
|
name + "( " + format( t ) + " )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,9 @@ namespace mock
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_PARAMETER(z, n, d) BOOST_PP_COMMA_IF(n) const_cast< A##n & >( a##n )
|
#define MOCK_EXPECTATION_PARAMETER(z, n, d) BOOST_PP_COMMA_IF(n) const_cast< A##n & >( a##n )
|
||||||
#define MOCK_EXPECTATION_DETAIL(z, n, d) + ", " + detail::format( a##n )
|
#define MOCK_EXPECTATION_DETAIL(z, n, d) + ", " + format( a##n )
|
||||||
#define MOCK_EXPECTATION_PARAMETERS(n) \
|
#define MOCK_EXPECTATION_PARAMETERS(n) \
|
||||||
detail::format( a0 ) BOOST_PP_REPEAT_FROM_TO(1, n, MOCK_EXPECTATION_DETAIL, BOOST_PP_EMPTY)
|
format( a0 ) BOOST_PP_REPEAT_FROM_TO(1, n, MOCK_EXPECTATION_DETAIL, BOOST_PP_EMPTY)
|
||||||
#define MOCK_EXPECTATION_OPERATOR(z, n, d) \
|
#define MOCK_EXPECTATION_OPERATOR(z, n, d) \
|
||||||
template< BOOST_PP_ENUM_PARAMS(n, typename A) > \
|
template< BOOST_PP_ENUM_PARAMS(n, typename A) > \
|
||||||
result_type operator()( BOOST_PP_ENUM_BINARY_PARAMS(n, const A, & a) ) const \
|
result_type operator()( BOOST_PP_ENUM_BINARY_PARAMS(n, const A, & a) ) const \
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,20 @@ namespace detail
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
std::string format( const T& t )
|
||||||
|
{
|
||||||
|
return detail::format( t );
|
||||||
|
}
|
||||||
|
inline std::string format( const std::string& s )
|
||||||
|
{
|
||||||
|
return '"' + s + '"';
|
||||||
|
}
|
||||||
|
inline std::string format( const char* s )
|
||||||
|
{
|
||||||
|
return '"' + std::string( s ) + '"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef MOCK_FORMAT_HPP_INCLUDED
|
#endif // #ifndef MOCK_FORMAT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -608,8 +608,8 @@ BOOST_AUTO_TEST_CASE( expectation_can_be_serialized_to_be_human_readable )
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << e;
|
s << e;
|
||||||
const std::string expected = "?\n"
|
const std::string expected = "?\n"
|
||||||
"v expect( never() ).with( less( first ) )\n"
|
"v expect( never() ).with( less( \"first\" ) )\n"
|
||||||
". expect( exactly( 1/2 ) ).with( second )";
|
". expect( exactly( 1/2 ) ).with( \"second\" )";
|
||||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||||
}
|
}
|
||||||
BOOST_CHECK_NO_THROW( e( "second" ) );
|
BOOST_CHECK_NO_THROW( e( "second" ) );
|
||||||
|
|
@ -617,8 +617,8 @@ BOOST_AUTO_TEST_CASE( expectation_can_be_serialized_to_be_human_readable )
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << e;
|
s << e;
|
||||||
const std::string expected = "?\n"
|
const std::string expected = "?\n"
|
||||||
"v expect( never() ).with( less( first ) )\n"
|
"v expect( never() ).with( less( \"first\" ) )\n"
|
||||||
"v expect( exactly( 2/2 ) ).with( second )";
|
"v expect( exactly( 2/2 ) ).with( \"second\" )";
|
||||||
BOOST_CHECK_EQUAL( expected, s.str() );
|
BOOST_CHECK_EQUAL( expected, s.str() );
|
||||||
}
|
}
|
||||||
e.reset();
|
e.reset();
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,17 @@ namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( type_not_serializable_in_standard_stream_yields_an_interrogation_mark_when_serialized )
|
BOOST_AUTO_TEST_CASE( type_not_serializable_in_standard_stream_yields_an_interrogation_mark_when_serialized )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "?", mock::detail::format( non_serializable_type() ) );
|
BOOST_CHECK_EQUAL( "?", mock::format( non_serializable_type() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( base_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
BOOST_AUTO_TEST_CASE( base_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "42", mock::detail::format( 42 ) );
|
BOOST_CHECK_EQUAL( "42", mock::format( 42 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
BOOST_AUTO_TEST_CASE( custom_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "serializable_type", mock::detail::format( serializable_type() ) );
|
BOOST_CHECK_EQUAL( "serializable_type", mock::format( serializable_type() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -49,7 +49,7 @@ namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_base_type_yields_its_value_when_serialized )
|
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_base_type_yields_its_value_when_serialized )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "0", mock::detail::format( convertible_to_int() ) );
|
BOOST_CHECK_EQUAL( "0", mock::format( convertible_to_int() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -69,11 +69,17 @@ namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_another_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_another_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "serializable", mock::detail::format( convertible_to_serializable() ) );
|
BOOST_CHECK_EQUAL( "serializable", mock::format( convertible_to_serializable() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_booleans )
|
BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_booleans )
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( "true", mock::detail::format( true ) );
|
BOOST_CHECK_EQUAL( "true", mock::format( true ) );
|
||||||
BOOST_CHECK_EQUAL( "false", mock::detail::format( false ) );
|
BOOST_CHECK_EQUAL( "false", mock::format( false ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( strings_are_surrounded_with_double_quotes )
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL( "\"string\"", mock::format( "string" ) );
|
||||||
|
BOOST_CHECK_EQUAL( "\"string\"", mock::format( std::string( "string" ) ) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue