summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/experimental/string.view/string.view.cons
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/experimental/string.view/string.view.cons')
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/default.pass.cpp46
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/from_literal.pass.cpp64
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/from_ptr_len.pass.cpp81
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/from_string.pass.cpp54
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/from_string1.fail.cpp32
-rw-r--r--libcxx/test/std/experimental/string.view/string.view.cons/from_string2.fail.cpp32
6 files changed, 309 insertions, 0 deletions
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/default.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/default.pass.cpp
new file mode 100644
index 00000000000..e1d69f4a3df
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/default.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// constexpr basic_string_view () noexcept;
+
+#include <experimental/string_view>
+#include <cassert>
+
+template<typename T>
+void test () {
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr T sv1;
+ static_assert ( sv1.size() == 0, "" );
+ static_assert ( sv1.empty(), "");
+ }
+#endif
+
+ {
+ T sv1;
+ assert ( sv1.size() == 0 );
+ assert ( sv1.empty());
+ }
+}
+
+int main () {
+ typedef std::experimental::string_view string_view;
+ typedef std::experimental::u16string_view u16string_view;
+ typedef std::experimental::u32string_view u32string_view;
+ typedef std::experimental::wstring_view wstring_view;
+
+ test<string_view> ();
+ test<u16string_view> ();
+ test<u32string_view> ();
+ test<wstring_view> ();
+
+}
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/from_literal.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/from_literal.pass.cpp
new file mode 100644
index 00000000000..82d0d795414
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/from_literal.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// constexpr basic_string_view(const _CharT* _s)
+// : __data (_s), __size(_Traits::length(_s)) {}
+
+
+#include <experimental/string_view>
+#include <string>
+#include <cassert>
+
+#include "constexpr_char_traits.hpp"
+
+template<typename CharT>
+size_t StrLen ( const CharT *s ) {
+ size_t retVal = 0;
+ while ( *s != 0 ) { ++retVal; ++s; }
+ return retVal;
+ }
+
+template<typename CharT>
+void test ( const CharT *s ) {
+ std::experimental::basic_string_view<CharT> sv1 ( s );
+ assert ( sv1.size() == StrLen( s ));
+ assert ( sv1.data() == s );
+ }
+
+
+int main () {
+
+ test ( "QBCDE" );
+ test ( "A" );
+ test ( "" );
+
+ test ( L"QBCDE" );
+ test ( L"A" );
+ test ( L"" );
+
+#if __cplusplus >= 201103L
+ test ( u"QBCDE" );
+ test ( u"A" );
+ test ( u"" );
+
+ test ( U"QBCDE" );
+ test ( U"A" );
+ test ( U"" );
+#endif
+
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::experimental::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" );
+ static_assert ( sv1.size() == 5, "");
+ }
+#endif
+}
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/from_ptr_len.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/from_ptr_len.pass.cpp
new file mode 100644
index 00000000000..1038d0484f8
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/from_ptr_len.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// constexpr basic_string_view(const _CharT* _s, size_type _len)
+// : __data (_s), __size(_len) {}
+
+
+#include <experimental/string_view>
+#include <string>
+#include <cassert>
+
+template<typename CharT>
+void test ( const CharT *s, size_t sz ) {
+ {
+ std::experimental::basic_string_view<CharT> sv1 ( s, sz );
+ assert ( sv1.size() == sz );
+ assert ( sv1.data() == s );
+ }
+}
+
+int main () {
+
+ test ( "QBCDE", 5 );
+ test ( "QBCDE", 2 );
+ test ( "", 0 );
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr const char *s = "QBCDE";
+ constexpr std::experimental::basic_string_view<char> sv1 ( s, 2 );
+ static_assert ( sv1.size() == 2, "" );
+ static_assert ( sv1.data() == s, "" );
+ }
+#endif
+
+ test ( L"QBCDE", 5 );
+ test ( L"QBCDE", 2 );
+ test ( L"", 0 );
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr const wchar_t *s = L"QBCDE";
+ constexpr std::experimental::basic_string_view<wchar_t> sv1 ( s, 2 );
+ static_assert ( sv1.size() == 2, "" );
+ static_assert ( sv1.data() == s, "" );
+ }
+#endif
+
+#if __cplusplus >= 201103L
+ test ( u"QBCDE", 5 );
+ test ( u"QBCDE", 2 );
+ test ( u"", 0 );
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr const char16_t *s = u"QBCDE";
+ constexpr std::experimental::basic_string_view<char16_t> sv1 ( s, 2 );
+ static_assert ( sv1.size() == 2, "" );
+ static_assert ( sv1.data() == s, "" );
+ }
+#endif
+
+ test ( U"QBCDE", 5 );
+ test ( U"QBCDE", 2 );
+ test ( U"", 0 );
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr const char32_t *s = U"QBCDE";
+ constexpr std::experimental::basic_string_view<char32_t> sv1 ( s, 2 );
+ static_assert ( sv1.size() == 2, "" );
+ static_assert ( sv1.data() == s, "" );
+ }
+#endif
+#endif
+}
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/from_string.pass.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/from_string.pass.cpp
new file mode 100644
index 00000000000..670c033a653
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/from_string.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// template<class Allocator>
+// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
+
+
+#include <experimental/string_view>
+#include <string>
+#include <cassert>
+
+struct dummy_char_traits : public std::char_traits<char> {};
+
+template<typename CharT, typename Traits>
+void test ( const std::basic_string<CharT, Traits> &str ) {
+ std::experimental::basic_string_view<CharT, Traits> sv1 ( str );
+ assert ( sv1.size() == str.size());
+ assert ( sv1.data() == str.data());
+}
+
+int main () {
+
+ test ( std::string("QBCDE") );
+ test ( std::string("") );
+ test ( std::string() );
+
+ test ( std::wstring(L"QBCDE") );
+ test ( std::wstring(L"") );
+ test ( std::wstring() );
+
+#if __cplusplus >= 201103L
+ test ( std::u16string{u"QBCDE"} );
+ test ( std::u16string{u""} );
+ test ( std::u16string{} );
+
+ test ( std::u32string{U"QBCDE"} );
+ test ( std::u32string{U""} );
+ test ( std::u32string{} );
+#endif
+
+ test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
+ test ( std::basic_string<char, dummy_char_traits>("") );
+ test ( std::basic_string<char, dummy_char_traits>() );
+
+}
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/from_string1.fail.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/from_string1.fail.cpp
new file mode 100644
index 00000000000..6ef4b9669bf
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/from_string1.fail.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// template<class Allocator>
+// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
+
+#include <experimental/string_view>
+#include <string>
+#include <cassert>
+
+struct dummy_char_traits : public std::char_traits<char> {};
+
+int main () {
+ using string_view = std::experimental::basic_string_view<char>;
+ using string = std:: basic_string <char, dummy_char_traits>;
+
+ {
+ string s{"QBCDE"};
+ string_view sv1 ( s );
+ assert ( sv1.size() == s.size());
+ assert ( sv1.data() == s.data());
+ }
+} \ No newline at end of file
diff --git a/libcxx/test/std/experimental/string.view/string.view.cons/from_string2.fail.cpp b/libcxx/test/std/experimental/string.view/string.view.cons/from_string2.fail.cpp
new file mode 100644
index 00000000000..6c77a3f99a2
--- /dev/null
+++ b/libcxx/test/std/experimental/string.view/string.view.cons/from_string2.fail.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+// <string_view>
+
+// template<class Allocator>
+// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
+
+#include <experimental/string_view>
+#include <string>
+#include <cassert>
+
+struct dummy_char_traits : public std::char_traits<char> {};
+
+int main () {
+ using string_view = std::experimental::basic_string_view<char, dummy_char_traits>;
+ using string = std:: basic_string <char>;
+
+ {
+ string s{"QBCDE"};
+ string_view sv1 ( s );
+ assert ( sv1.size() == s.size());
+ assert ( sv1.data() == s.data());
+ }
+}
OpenPOWER on IntegriCloud