From 09870f0739d99dcf2a51f50e73a658d2c02c40d6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 8 Oct 2021 05:39:24 +0300 Subject: [PATCH] Add sv_find_first_of_test --- include/boost/core/string_view.hpp | 2 +- test/Jamfile.v2 | 1 + test/sv_find_first_of_test.cpp | 161 +++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 test/sv_find_first_of_test.cpp diff --git a/include/boost/core/string_view.hpp b/include/boost/core/string_view.hpp index 096970e..f564316 100644 --- a/include/boost/core/string_view.hpp +++ b/include/boost/core/string_view.hpp @@ -563,7 +563,7 @@ public: BOOST_CONSTEXPR bool contains( Ch c ) const BOOST_NOEXCEPT { - return traits_type::find( data(), size(), c ) == 0; + return traits_type::find( data(), size(), c ) != 0; } BOOST_CONSTEXPR bool contains( Ch const* s ) const BOOST_NOEXCEPT diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 11bbea6..fcd33ea 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -259,6 +259,7 @@ run sv_starts_with_test.cpp ; run sv_ends_with_test.cpp ; run sv_find_test.cpp ; run sv_rfind_test.cpp ; +run sv_find_first_of_test.cpp ; use-project /boost/core/swap : ./swap ; build-project ./swap ; diff --git a/test/sv_find_first_of_test.cpp b/test/sv_find_first_of_test.cpp new file mode 100644 index 0000000..c32c23e --- /dev/null +++ b/test/sv_find_first_of_test.cpp @@ -0,0 +1,161 @@ +// Copyright 2021 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +int main() +{ + std::size_t const npos = boost::core::string_view::npos; + + { + boost::core::string_view sv( "" ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view() ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ) ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ) ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( '1' ), npos ); + BOOST_TEST_EQ( sv.find_first_of( '1', 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "" ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "", 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "1" ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "1", 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "12", 0, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "12", 1, 0 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "12", 0, 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "12", 1, 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "12", 0, 2 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "12", 1, 2 ), npos ); + } + + { + boost::core::string_view sv( "123123" ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view() ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view(), 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ) ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "" ), 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ) ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 2 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 3 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 4 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 5 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "1" ), 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ) ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "4" ), 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ) ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 1 ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 2 ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 3 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 4 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 5 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( boost::core::string_view( "23" ), 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( '1' ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( '1', 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( '1', 2 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( '1', 3 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( '1', 4 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( '1', 5 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( '1', 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( '1', 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( '3' ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 1 ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 2 ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 3 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 4 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 5 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( '3', 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( '3', 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( '9' ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "" ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "", 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "", 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "", 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "1" ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( "1", 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "1", 2 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "1", 3 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "1", 4 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "1", 5 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "1", 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "1", 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "23" ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 1 ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 2 ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 3 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 4 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 5 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( "23", 6 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "23", 7 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "123", 0, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 1, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 2, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 3, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 4, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 5, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 6, 0 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 7, 0 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "123", 0, 1 ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 1, 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 2, 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 3, 1 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 4, 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 5, 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 6, 1 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 7, 1 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "123", 0, 2 ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 1, 2 ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 2, 2 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 3, 2 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 4, 2 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 5, 2 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 6, 2 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 7, 2 ), npos ); + + BOOST_TEST_EQ( sv.find_first_of( "123", 0, 3 ), 0 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 1, 3 ), 1 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 2, 3 ), 2 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 3, 3 ), 3 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 4, 3 ), 4 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 5, 3 ), 5 ); + BOOST_TEST_EQ( sv.find_first_of( "123", 6, 3 ), npos ); + BOOST_TEST_EQ( sv.find_first_of( "123", 7, 3 ), npos ); + } + + return boost::report_errors(); +}