1
0
forked from boostorg/core

Add sv_starts_with_test

This commit is contained in:
Peter Dimov
2021-10-06 04:35:37 +03:00
parent 93c18fb937
commit c7dfa29f29
3 changed files with 63 additions and 0 deletions

View File

@ -563,6 +563,18 @@ public:
{
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)

View File

@ -254,6 +254,7 @@ run sv_modifiers_test.cpp ;
run sv_copy_test.cpp ;
run sv_substr_test.cpp ;
run sv_compare_test.cpp ;
run sv_starts_with_test.cpp ;
use-project /boost/core/swap : ./swap ;
build-project ./swap ;

View 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();
}