diff options
author | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2014-12-20 01:40:03 +0000 |
commit | 5a83710e371fe68a06e6e3876c6a2c8b820a8976 (patch) | |
tree | afde4c82ad6704681781c5cd49baa3fbd05c85db /libcxx/test/strings/basic.string/string.modifiers/string_assign | |
parent | f11e8eab527fba316c64112f6e05de1a79693a3e (diff) | |
download | bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.tar.gz bcm5719-llvm-5a83710e371fe68a06e6e3876c6a2c8b820a8976.zip |
Move test into test/std subdirectory.
llvm-svn: 224658
Diffstat (limited to 'libcxx/test/strings/basic.string/string.modifiers/string_assign')
8 files changed, 0 insertions, 660 deletions
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp deleted file mode 100644 index 2dae1074596..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string& assign(initializer_list<charT> il); - -#include <string> -#include <cassert> - -#include "min_allocator.h" - -int main() -{ -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - { - std::string s("123"); - s.assign({'a', 'b', 'c'}); - assert(s == "abc"); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - S s("123"); - s.assign({'a', 'b', 'c'}); - assert(s == "abc"); - } -#endif -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp deleted file mode 100644 index 83b5dd14b3f..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp +++ /dev/null @@ -1,150 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// template<class InputIterator> -// basic_string& assign(InputIterator first, InputIterator last); - -#include <string> -#include <cassert> - -#include "../../input_iterator.h" -#include "min_allocator.h" - -template <class S, class It> -void -test(S s, It first, It last, S expected) -{ - s.assign(first, last); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - test(S(), s, s, S()); - test(S(), s, s+1, S("A")); - test(S(), s, s+10, S("ABCDEFGHIJ")); - test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345"), s, s, S()); - test(S("12345"), s, s+1, S("A")); - test(S("12345"), s, s+10, S("ABCDEFGHIJ")); - test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("1234567890"), s, s, S()); - test(S("1234567890"), s, s+1, S("A")); - test(S("1234567890"), s, s+10, S("ABCDEFGHIJ")); - test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345678901234567890"), s, s, S()); - test(S("12345678901234567890"), s, s+1, S("A")); - test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ")); - test(S("12345678901234567890"), s, s+52, - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S()); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A")); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - test(S(), s, s, S()); - test(S(), s, s+1, S("A")); - test(S(), s, s+10, S("ABCDEFGHIJ")); - test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345"), s, s, S()); - test(S("12345"), s, s+1, S("A")); - test(S("12345"), s, s+10, S("ABCDEFGHIJ")); - test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("1234567890"), s, s, S()); - test(S("1234567890"), s, s+1, S("A")); - test(S("1234567890"), s, s+10, S("ABCDEFGHIJ")); - test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345678901234567890"), s, s, S()); - test(S("12345678901234567890"), s, s+1, S("A")); - test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ")); - test(S("12345678901234567890"), s, s+52, - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S()); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A")); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), - S()); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), - S("A")); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), - S("ABCDEFGHIJ")); - test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), - S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp deleted file mode 100644 index adf24ac4987..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& assign(const charT* s); - -#include <string> -#include <stdexcept> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, const typename S::value_type* str, S expected) -{ - s.assign(str); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - test(S(), "", S()); - test(S(), "12345", S("12345")); - test(S(), "12345678901234567890", S("12345678901234567890")); - - test(S("12345"), "", S()); - test(S("12345"), "12345", S("12345")); - test(S("12345"), "1234567890", S("1234567890")); - - test(S("12345678901234567890"), "", S()); - test(S("12345678901234567890"), "12345", S("12345")); - test(S("12345678901234567890"), "12345678901234567890", - S("12345678901234567890")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), "", S()); - test(S(), "12345", S("12345")); - test(S(), "12345678901234567890", S("12345678901234567890")); - - test(S("12345"), "", S()); - test(S("12345"), "12345", S("12345")); - test(S("12345"), "1234567890", S("1234567890")); - - test(S("12345678901234567890"), "", S()); - test(S("12345678901234567890"), "12345", S("12345")); - test(S("12345678901234567890"), "12345678901234567890", - S("12345678901234567890")); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp deleted file mode 100644 index 476fe963de7..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& -// assign(const charT* s, size_type n); - -#include <string> -#include <stdexcept> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, const typename S::value_type* str, typename S::size_type n, S expected) -{ - s.assign(str, n); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - test(S(), "", 0, S()); - test(S(), "12345", 3, S("123")); - test(S(), "12345", 4, S("1234")); - test(S(), "12345678901234567890", 0, S()); - test(S(), "12345678901234567890", 1, S("1")); - test(S(), "12345678901234567890", 3, S("123")); - test(S(), "12345678901234567890", 20, S("12345678901234567890")); - - test(S("12345"), "", 0, S()); - test(S("12345"), "12345", 5, S("12345")); - test(S("12345"), "1234567890", 10, S("1234567890")); - - test(S("12345678901234567890"), "", 0, S()); - test(S("12345678901234567890"), "12345", 5, S("12345")); - test(S("12345678901234567890"), "12345678901234567890", 20, - S("12345678901234567890")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), "", 0, S()); - test(S(), "12345", 3, S("123")); - test(S(), "12345", 4, S("1234")); - test(S(), "12345678901234567890", 0, S()); - test(S(), "12345678901234567890", 1, S("1")); - test(S(), "12345678901234567890", 3, S("123")); - test(S(), "12345678901234567890", 20, S("12345678901234567890")); - - test(S("12345"), "", 0, S()); - test(S("12345"), "12345", 5, S("12345")); - test(S("12345"), "1234567890", 10, S("1234567890")); - - test(S("12345678901234567890"), "", 0, S()); - test(S("12345678901234567890"), "12345", 5, S("12345")); - test(S("12345678901234567890"), "12345678901234567890", 20, - S("12345678901234567890")); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp deleted file mode 100644 index ac0e535eea2..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& -// assign(basic_string<charT,traits>&& str); - -#include <string> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, S str, S expected) -{ - s.assign(std::move(str)); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - test(S(), S(), S()); - test(S(), S("12345"), S("12345")); - test(S(), S("1234567890"), S("1234567890")); - test(S(), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345"), S(), S()); - test(S("12345"), S("12345"), S("12345")); - test(S("12345"), S("1234567890"), S("1234567890")); - test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("1234567890"), S(), S()); - test(S("1234567890"), S("12345"), S("12345")); - test(S("1234567890"), S("1234567890"), S("1234567890")); - test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345678901234567890"), S(), S()); - test(S("12345678901234567890"), S("12345"), S("12345")); - test(S("12345678901234567890"), S("1234567890"), S("1234567890")); - test(S("12345678901234567890"), S("12345678901234567890"), - S("12345678901234567890")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), S(), S()); - test(S(), S("12345"), S("12345")); - test(S(), S("1234567890"), S("1234567890")); - test(S(), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345"), S(), S()); - test(S("12345"), S("12345"), S("12345")); - test(S("12345"), S("1234567890"), S("1234567890")); - test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("1234567890"), S(), S()); - test(S("1234567890"), S("12345"), S("12345")); - test(S("1234567890"), S("1234567890"), S("1234567890")); - test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345678901234567890"), S(), S()); - test(S("12345678901234567890"), S("12345"), S("12345")); - test(S("12345678901234567890"), S("1234567890"), S("1234567890")); - test(S("12345678901234567890"), S("12345678901234567890"), - S("12345678901234567890")); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp deleted file mode 100644 index a8f747091c6..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& -// assign(size_type n, charT c); - -#include <string> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, typename S::size_type n, typename S::value_type c, S expected) -{ - s.assign(n, c); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - test(S(), 0, 'a', S()); - test(S(), 1, 'a', S(1, 'a')); - test(S(), 10, 'a', S(10, 'a')); - test(S(), 100, 'a', S(100, 'a')); - - test(S("12345"), 0, 'a', S()); - test(S("12345"), 1, 'a', S(1, 'a')); - test(S("12345"), 10, 'a', S(10, 'a')); - - test(S("12345678901234567890"), 0, 'a', S()); - test(S("12345678901234567890"), 1, 'a', S(1, 'a')); - test(S("12345678901234567890"), 10, 'a', S(10, 'a')); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), 0, 'a', S()); - test(S(), 1, 'a', S(1, 'a')); - test(S(), 10, 'a', S(10, 'a')); - test(S(), 100, 'a', S(100, 'a')); - - test(S("12345"), 0, 'a', S()); - test(S("12345"), 1, 'a', S(1, 'a')); - test(S("12345"), 10, 'a', S(10, 'a')); - - test(S("12345678901234567890"), 0, 'a', S()); - test(S("12345678901234567890"), 1, 'a', S(1, 'a')); - test(S("12345678901234567890"), 10, 'a', S(10, 'a')); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/string.pass.cpp deleted file mode 100644 index d7ddb77b8e0..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string.pass.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& -// assign(const basic_string<charT,traits>& str); - -#include <string> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, S str, S expected) -{ - s.assign(str); - assert(s.__invariants()); - assert(s == expected); -} - -int main() -{ - { - typedef std::string S; - test(S(), S(), S()); - test(S(), S("12345"), S("12345")); - test(S(), S("1234567890"), S("1234567890")); - test(S(), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345"), S(), S()); - test(S("12345"), S("12345"), S("12345")); - test(S("12345"), S("1234567890"), S("1234567890")); - test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("1234567890"), S(), S()); - test(S("1234567890"), S("12345"), S("12345")); - test(S("1234567890"), S("1234567890"), S("1234567890")); - test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345678901234567890"), S(), S()); - test(S("12345678901234567890"), S("12345"), S("12345")); - test(S("12345678901234567890"), S("1234567890"), S("1234567890")); - test(S("12345678901234567890"), S("12345678901234567890"), - S("12345678901234567890")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), S(), S()); - test(S(), S("12345"), S("12345")); - test(S(), S("1234567890"), S("1234567890")); - test(S(), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345"), S(), S()); - test(S("12345"), S("12345"), S("12345")); - test(S("12345"), S("1234567890"), S("1234567890")); - test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("1234567890"), S(), S()); - test(S("1234567890"), S("12345"), S("12345")); - test(S("1234567890"), S("1234567890"), S("1234567890")); - test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); - - test(S("12345678901234567890"), S(), S()); - test(S("12345678901234567890"), S("12345"), S("12345")); - test(S("12345678901234567890"), S("1234567890"), S("1234567890")); - test(S("12345678901234567890"), S("12345678901234567890"), - S("12345678901234567890")); - } -#endif -} diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp deleted file mode 100644 index 5f5983e76c9..00000000000 --- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp +++ /dev/null @@ -1,118 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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> - -// basic_string<charT,traits,Allocator>& -// assign(const basic_string<charT,traits>& str, size_type pos, size_type n=npos); -// the =npos was added for C++14 - -#include <string> -#include <stdexcept> -#include <cassert> - -#include "min_allocator.h" - -template <class S> -void -test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) -{ - try - { - s.assign(str, pos, n); - assert(s.__invariants()); - assert(pos <= str.size()); - assert(s == expected); - } - catch (std::out_of_range&) - { - assert(pos > str.size()); - } -} - -template <class S> -void -test_npos(S s, S str, typename S::size_type pos, S expected) -{ - try - { - s.assign(str, pos); - assert(s.__invariants()); - assert(pos <= str.size()); - assert(s == expected); - } - catch (std::out_of_range&) - { - assert(pos > str.size()); - } -} - -int main() -{ - { - typedef std::string S; - test(S(), S(), 0, 0, S()); - test(S(), S(), 1, 0, S()); - test(S(), S("12345"), 0, 3, S("123")); - test(S(), S("12345"), 1, 4, S("2345")); - test(S(), S("12345"), 3, 15, S("45")); - test(S(), S("12345"), 5, 15, S("")); - test(S(), S("12345"), 6, 15, S("not happening")); - test(S(), S("12345678901234567890"), 0, 0, S()); - test(S(), S("12345678901234567890"), 1, 1, S("2")); - test(S(), S("12345678901234567890"), 2, 3, S("345")); - test(S(), S("12345678901234567890"), 12, 13, S("34567890")); - test(S(), S("12345678901234567890"), 21, 13, S("not happening")); - - test(S("12345"), S(), 0, 0, S()); - test(S("12345"), S("12345"), 2, 2, S("34")); - test(S("12345"), S("1234567890"), 0, 100, S("1234567890")); - - test(S("12345678901234567890"), S(), 0, 0, S()); - test(S("12345678901234567890"), S("12345"), 1, 3, S("234")); - test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, - S("6789012345")); - } -#if __cplusplus >= 201103L - { - typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; - test(S(), S(), 0, 0, S()); - test(S(), S(), 1, 0, S()); - test(S(), S("12345"), 0, 3, S("123")); - test(S(), S("12345"), 1, 4, S("2345")); - test(S(), S("12345"), 3, 15, S("45")); - test(S(), S("12345"), 5, 15, S("")); - test(S(), S("12345"), 6, 15, S("not happening")); - test(S(), S("12345678901234567890"), 0, 0, S()); - test(S(), S("12345678901234567890"), 1, 1, S("2")); - test(S(), S("12345678901234567890"), 2, 3, S("345")); - test(S(), S("12345678901234567890"), 12, 13, S("34567890")); - test(S(), S("12345678901234567890"), 21, 13, S("not happening")); - - test(S("12345"), S(), 0, 0, S()); - test(S("12345"), S("12345"), 2, 2, S("34")); - test(S("12345"), S("1234567890"), 0, 100, S("1234567890")); - - test(S("12345678901234567890"), S(), 0, 0, S()); - test(S("12345678901234567890"), S("12345"), 1, 3, S("234")); - test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, - S("6789012345")); - } -#endif - { - typedef std::string S; - test_npos(S(), S(), 0, S()); - test_npos(S(), S(), 1, S()); - test_npos(S(), S("12345"), 0, S("12345")); - test_npos(S(), S("12345"), 1, S("2345")); - test_npos(S(), S("12345"), 3, S("45")); - test_npos(S(), S("12345"), 5, S("")); - test_npos(S(), S("12345"), 6, S("not happening")); - } -} |