mirror of
https://github.com/boostorg/core.git
synced 2025-05-11 05:07:39 +00:00
Add sv_copy_test
This commit is contained in:
parent
1aa8341bd7
commit
c65c05c006
@ -251,6 +251,7 @@ run sv_types_test.cpp ;
|
||||
run sv_construct_test.cpp ;
|
||||
run sv_element_access_test.cpp ;
|
||||
run sv_modifiers_test.cpp ;
|
||||
run sv_copy_test.cpp ;
|
||||
|
||||
use-project /boost/core/swap : ./swap ;
|
||||
build-project ./swap ;
|
||||
|
50
test/sv_copy_test.cpp
Normal file
50
test/sv_copy_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_EQ( sv.copy( 0, 0 ), 0 );
|
||||
BOOST_TEST_EQ( sv.copy( 0, 0, 0 ), 0 );
|
||||
BOOST_TEST_THROWS( sv.copy( 0, 0, 1 ), std::out_of_range );
|
||||
BOOST_TEST_THROWS( sv.copy( 0, 0, boost::core::string_view::npos ), std::out_of_range );
|
||||
}
|
||||
|
||||
{
|
||||
boost::core::string_view sv( "12345" );
|
||||
char buffer[ 8 ] = {};
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 0 ), 0 );
|
||||
BOOST_TEST_EQ( buffer[0], 0 );
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 0, 0 ), 0 );
|
||||
BOOST_TEST_EQ( buffer[0], 0 );
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 0, 1 ), 0 );
|
||||
BOOST_TEST_EQ( buffer[0], 0 );
|
||||
|
||||
BOOST_TEST_THROWS( sv.copy( buffer, 0, boost::core::string_view::npos ), std::out_of_range );
|
||||
BOOST_TEST_EQ( buffer[0], 0 );
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 1 ), 1 );
|
||||
BOOST_TEST_EQ( buffer[0], '1' );
|
||||
BOOST_TEST_EQ( buffer[1], 0 );
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 1, 1 ), 1 );
|
||||
BOOST_TEST_EQ( buffer[0], '2' );
|
||||
BOOST_TEST_EQ( buffer[1], 0 );
|
||||
|
||||
BOOST_TEST_EQ( sv.copy( buffer, 8 ), 5 );
|
||||
BOOST_TEST_CSTR_EQ( buffer, "12345" );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user