Add tests to make sure that <string_view> provides std::size/data/empty in C++17 mode. This is LWG#3009, coming up for a vote in JAX - but we already do it, just don't have tests

llvm-svn: 323719
This commit is contained in:
Marshall Clow 2018-01-30 00:47:43 +00:00
parent ee4e2e718d
commit aafb3151a8
5 changed files with 40 additions and 1 deletions

View File

@ -23,6 +23,10 @@
#include "test_macros.h"
#if TEST_STD_VER > 14
#include <string_view>
#endif
template<typename C>
void test_const_container( const C& c )
{
@ -72,6 +76,12 @@ int main()
test_const_container ( a );
test_const_container ( il );
#if TEST_STD_VER > 14
std::string_view sv{"ABC"};
test_container ( sv );
test_const_container ( sv );
#endif
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}

View File

@ -23,6 +23,10 @@
#include "test_macros.h"
#if TEST_STD_VER > 14
#include <string_view>
#endif
template<typename C>
void test_const_container( const C& c )
{
@ -74,6 +78,12 @@ int main()
test_const_container ( a );
test_const_container ( il );
#if TEST_STD_VER > 14
std::string_view sv{"ABC"};
test_container ( sv );
test_const_container ( sv );
#endif
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}

View File

@ -22,6 +22,11 @@
#include "test_macros.h"
#if TEST_STD_VER > 14
#include <string_view>
#endif
template<typename C>
void test_const_container( const C& c )
{
@ -65,7 +70,6 @@ int main()
std::list<int> l; l.push_back(2);
std::array<int, 1> a; a[0] = 3;
std::initializer_list<int> il = { 4 };
test_container ( v );
test_container ( l );
test_container ( a );
@ -76,6 +80,12 @@ int main()
test_const_container ( a );
test_const_container ( il );
#if TEST_STD_VER > 14
std::string_view sv{"ABC"};
test_container ( sv );
test_const_container ( sv );
#endif
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}

View File

@ -22,6 +22,10 @@ void test ( const CharT *s, size_t len ) {
std::basic_string_view<CharT> sv ( s, len );
assert ( sv.length() == len );
assert ( sv.data() == s );
#if TEST_STD_VER > 14
// make sure we pick up std::data, too!
assert ( sv.data() == std::data(sv));
#endif
}
int main () {

View File

@ -55,6 +55,11 @@ void test2 ( const CharT *s, size_t len ) {
assert ( sv1.empty() == (len == 0));
assert ( sv1.size() == sv1.length());
assert ( sv1.max_size() > sv1.size());
#if TEST_STD_VER > 14
// make sure we pick up std::size, too!
assert ( sv1.size() == std::size(sv1));
assert ( sv1.empty() == std::empty(sv1));
#endif
}
}