forked from boostorg/core
Add sv_starts_with_test
This commit is contained in:
@ -563,6 +563,18 @@ public:
|
|||||||
{
|
{
|
||||||
return find( s ) != npos;
|
return find( s ) != npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// relational operators
|
||||||
|
|
||||||
|
BOOST_CONSTEXPR friend bool operator==( basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT
|
||||||
|
{
|
||||||
|
return sv1.compare( sv2 ) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CONSTEXPR friend bool operator!=( basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT
|
||||||
|
{
|
||||||
|
return sv1.compare( sv2 ) != 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
|
||||||
|
@ -254,6 +254,7 @@ run sv_modifiers_test.cpp ;
|
|||||||
run sv_copy_test.cpp ;
|
run sv_copy_test.cpp ;
|
||||||
run sv_substr_test.cpp ;
|
run sv_substr_test.cpp ;
|
||||||
run sv_compare_test.cpp ;
|
run sv_compare_test.cpp ;
|
||||||
|
run sv_starts_with_test.cpp ;
|
||||||
|
|
||||||
use-project /boost/core/swap : ./swap ;
|
use-project /boost/core/swap : ./swap ;
|
||||||
build-project ./swap ;
|
build-project ./swap ;
|
||||||
|
50
test/sv_starts_with_test.cpp
Normal file
50
test/sv_starts_with_test.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// 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 <stdexcept>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::core::string_view sv( "" );
|
||||||
|
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view() ) );
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view( "" ) ) );
|
||||||
|
BOOST_TEST( sv.starts_with( "" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( !sv.starts_with( boost::core::string_view( "1" ) ) );
|
||||||
|
BOOST_TEST( !sv.starts_with( '1' ) );
|
||||||
|
BOOST_TEST( !sv.starts_with( "1" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::core::string_view sv( "123" );
|
||||||
|
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view() ) );
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view( "" ) ) );
|
||||||
|
BOOST_TEST( sv.starts_with( "" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view( "1" ) ) );
|
||||||
|
BOOST_TEST( sv.starts_with( '1' ) );
|
||||||
|
BOOST_TEST( sv.starts_with( "1" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view( "12" ) ) );
|
||||||
|
BOOST_TEST( sv.starts_with( "12" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( sv.starts_with( boost::core::string_view( "123" ) ) );
|
||||||
|
BOOST_TEST( sv.starts_with( "123" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( !sv.starts_with( boost::core::string_view( "1234" ) ) );
|
||||||
|
BOOST_TEST( !sv.starts_with( "1234" ) );
|
||||||
|
|
||||||
|
BOOST_TEST( !sv.starts_with( boost::core::string_view( "2" ) ) );
|
||||||
|
BOOST_TEST( !sv.starts_with( '2' ) );
|
||||||
|
BOOST_TEST( !sv.starts_with( "2" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user