mirror of
https://github.com/boostorg/core.git
synced 2025-05-11 13:13:55 +00:00
Add sv_eq_test
This commit is contained in:
parent
62e9d9b868
commit
db15c7419d
@ -26,6 +26,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
#include <iosfwd>
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
@ -905,6 +906,12 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<class Ch> std::basic_ostream<Ch>& operator<<( std::basic_ostream<Ch>& os, basic_string_view<Ch> str )
|
||||
{
|
||||
os.write( str.data(), str.size() );
|
||||
return os;
|
||||
}
|
||||
|
||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||
template<class Ch> BOOST_CONSTEXPR_OR_CONST std::size_t basic_string_view<Ch>::npos;
|
||||
#endif
|
||||
|
@ -264,6 +264,7 @@ run sv_find_last_of_test.cpp ;
|
||||
run sv_find_first_not_of_test.cpp ;
|
||||
run sv_find_last_not_of_test.cpp ;
|
||||
run sv_contains_test.cpp ;
|
||||
run sv_eq_test.cpp ;
|
||||
|
||||
use-project /boost/core/swap : ./swap ;
|
||||
build-project ./swap ;
|
||||
|
84
test/sv_eq_test.cpp
Normal file
84
test/sv_eq_test.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/string_view.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <cstddef>
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
|
||||
#define TEST_EQ(x, y) BOOST_TEST_EQ(x, y); BOOST_TEST_NOT((x) != (y))
|
||||
#define TEST_NE(x, y) BOOST_TEST_NE(x, y); BOOST_TEST_NOT((x) == (y))
|
||||
|
||||
int main()
|
||||
{
|
||||
std::size_t const npos = boost::core::string_view::npos;
|
||||
|
||||
{
|
||||
boost::core::string_view sv1( "" );
|
||||
boost::core::string_view sv2( "" );
|
||||
boost::core::string_view sv3( "123" );
|
||||
boost::core::string_view sv4( "123" );
|
||||
boost::core::string_view sv5( "12345" );
|
||||
boost::core::string_view sv6( "12345" );
|
||||
|
||||
TEST_EQ( sv1, sv1 );
|
||||
TEST_EQ( sv1, sv2 );
|
||||
TEST_NE( sv1, sv3 );
|
||||
TEST_NE( sv1, sv5 );
|
||||
|
||||
TEST_EQ( sv3, sv3 );
|
||||
TEST_EQ( sv3, sv4 );
|
||||
TEST_NE( sv3, sv1 );
|
||||
TEST_NE( sv3, sv5 );
|
||||
|
||||
TEST_EQ( sv5, sv5 );
|
||||
TEST_EQ( sv5, sv6 );
|
||||
TEST_NE( sv5, sv1 );
|
||||
TEST_NE( sv5, sv3 );
|
||||
|
||||
BOOST_TEST_EQ( sv1, std::string( "" ) );
|
||||
BOOST_TEST_EQ( std::string( "" ), sv1 );
|
||||
|
||||
BOOST_TEST_NE( sv1, std::string( "1" ) );
|
||||
BOOST_TEST_NE( std::string( "1" ), sv1 );
|
||||
|
||||
BOOST_TEST_EQ( sv3, std::string( "123" ) );
|
||||
BOOST_TEST_EQ( std::string( "123" ), sv3 );
|
||||
|
||||
BOOST_TEST_NE( sv3, std::string( "122" ) );
|
||||
BOOST_TEST_NE( std::string( "122" ), sv3 );
|
||||
|
||||
BOOST_TEST_EQ( sv1, "" );
|
||||
BOOST_TEST_EQ( "", sv1 );
|
||||
|
||||
BOOST_TEST_NE( sv1, "1" );
|
||||
BOOST_TEST_NE( "1", sv1 );
|
||||
|
||||
BOOST_TEST_EQ( sv3, "123" );
|
||||
BOOST_TEST_EQ( "123", sv3 );
|
||||
|
||||
BOOST_TEST_NE( sv3, "122" );
|
||||
BOOST_TEST_NE( "122", sv3 );
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
BOOST_TEST_EQ( sv1, std::string_view( "" ) );
|
||||
BOOST_TEST_EQ( std::string_view( "" ), sv1 );
|
||||
|
||||
BOOST_TEST_NE( sv1, std::string_view( "1" ) );
|
||||
BOOST_TEST_NE( std::string_view( "1" ), sv1 );
|
||||
|
||||
BOOST_TEST_EQ( sv3, std::string_view( "123" ) );
|
||||
BOOST_TEST_EQ( std::string_view( "123" ), sv3 );
|
||||
|
||||
BOOST_TEST_NE( sv3, std::string_view( "122" ) );
|
||||
BOOST_TEST_NE( std::string_view( "122" ), sv3 );
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user