diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
commit | 3e519524c118651123eecf60c2bbc5d65ad9bac3 (patch) | |
tree | b2dd4168cfe448920a602cd7d2e40f95da187153 /libcxx/test/strings/basic.string/string.modifiers/string::assign | |
parent | 9132c59d43b6c590c9bb33496eebf9f192d6857a (diff) | |
download | bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.tar.gz bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.zip |
libcxx initial import
llvm-svn: 103490
Diffstat (limited to 'libcxx/test/strings/basic.string/string.modifiers/string::assign')
8 files changed, 404 insertions, 0 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 new file mode 100644 index 00000000000..61bab9c54e2 --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/initializer_list.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string& assign(initializer_list<charT> il); + +#include <string> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::string s("123"); + s.assign({'a', 'b', 'c'}); + assert(s == "abc"); + } +#endif +} 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 new file mode 100644 index 00000000000..b305674141e --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/iterator.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// template<class InputIterator> +// basic_string& assign(InputIterator first, InputIterator last); + +#include <string> +#include <cassert> + +#include "../../input_iterator.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")); +} 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 new file mode 100644 index 00000000000..62c1ce395ff --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& assign(const charT* s); + +#include <string> +#include <stdexcept> +#include <cassert> + +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")); +} 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 new file mode 100644 index 00000000000..7e90b241be1 --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer_size.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(const charT* s, size_type n); + +#include <string> +#include <stdexcept> +#include <cassert> + +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")); +} 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 new file mode 100644 index 00000000000..e62152c5f95 --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/rv_string.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(basic_string<charT,traits>&& str); + +#include <string> +#include <cassert> + +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")); +} 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 new file mode 100644 index 00000000000..eb4eaadf2fe --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/size_char.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(size_type n, charT c); + +#include <string> +#include <cassert> + +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')); +} 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 new file mode 100644 index 00000000000..d9dccb3f791 --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(const basic_string<charT,traits>& str); + +#include <string> +#include <cassert> + +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")); +} 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 new file mode 100644 index 00000000000..d5bfc390aeb --- /dev/null +++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string_size_size.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <string> + +// basic_string<charT,traits,Allocator>& +// assign(const basic_string<charT,traits>& str, size_type pos, size_type n); + +#include <string> +#include <stdexcept> +#include <cassert> + +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()); + } +} + +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")); +} |