libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
44
test/strings/basic.string/string.cons/alloc.pass.cpp
Normal file
44
test/strings/basic.string/string.cons/alloc.pass.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// explicit basic_string(const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test()
|
||||
{
|
||||
{
|
||||
S s;
|
||||
assert(s.__invariants());
|
||||
assert(s.data());
|
||||
assert(s.size() == 0);
|
||||
assert(s.capacity() >= s.size());
|
||||
assert(s.get_allocator() == typename S::allocator_type());
|
||||
}
|
||||
{
|
||||
S s(typename S::allocator_type(5));
|
||||
assert(s.__invariants());
|
||||
assert(s.data());
|
||||
assert(s.size() == 0);
|
||||
assert(s.capacity() >= s.size());
|
||||
assert(s.get_allocator() == typename S::allocator_type(5));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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>& operator=(charT c);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1, typename S::value_type s2)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
s1 = s2;
|
||||
assert(s1.__invariants());
|
||||
assert(s1.size() == 1);
|
||||
assert(T::eq(s1[0], s2));
|
||||
assert(s1.capacity() >= s1.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 'a');
|
||||
test(S("1"), 'a');
|
||||
test(S("123456789"), 'a');
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
|
||||
}
|
37
test/strings/basic.string/string.cons/copy.pass.cpp
Normal file
37
test/strings/basic.string/string.cons/copy.pass.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(const basic_string<charT,traits,Allocator>& str);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1)
|
||||
{
|
||||
S s2 = s1;
|
||||
assert(s2.__invariants());
|
||||
assert(s2 == s1);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
assert(s2.get_allocator() == s1.get_allocator());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
test(S(A(3)));
|
||||
test(S("1", A(5)));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
|
||||
}
|
37
test/strings/basic.string/string.cons/copy_alloc.pass.cpp
Normal file
37
test/strings/basic.string/string.cons/copy_alloc.pass.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(const basic_string& str, const Allocator& alloc);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1, const typename S::allocator_type& a)
|
||||
{
|
||||
S s2(s1, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2 == s1);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
assert(s2.get_allocator() == a);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
test(S(), A(3));
|
||||
test(S("1"), A(5));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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>&
|
||||
// operator=(const basic_string<charT,traits,Allocator>& str);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1, const S& s2)
|
||||
{
|
||||
s1 = s2;
|
||||
assert(s1.__invariants());
|
||||
assert(s1 == s2);
|
||||
assert(s1.capacity() >= s1.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), S());
|
||||
test(S("1"), S());
|
||||
test(S(), S("1"));
|
||||
test(S("1"), S("2"));
|
||||
test(S("1"), S("2"));
|
||||
|
||||
test(S(),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::string s = {'a', 'b', 'c'};
|
||||
assert(s == "abc");
|
||||
}
|
||||
{
|
||||
std::wstring s;
|
||||
s = {L'a', L'b', L'c'};
|
||||
assert(s == L"abc");
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string& operator=(initializer_list<charT> il);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::string s;
|
||||
s = {'a', 'b', 'c'};
|
||||
assert(s == "abc");
|
||||
}
|
||||
#endif
|
||||
}
|
87
test/strings/basic.string/string.cons/iter_alloc.pass.cpp
Normal file
87
test/strings/basic.string/string.cons/iter_alloc.pass.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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(InputIterator begin, InputIterator end,
|
||||
// const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
#include "../input_iterator.h"
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It first, It last)
|
||||
{
|
||||
typedef typename std::iterator_traits<It>::value_type charT;
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(first, last);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == std::distance(first, last));
|
||||
unsigned i = 0;
|
||||
for (It it = first; it != last; ++it, ++i)
|
||||
assert(s2[i] == *it);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It first, It last, const test_allocator<typename std::iterator_traits<It>::value_type>& a)
|
||||
{
|
||||
typedef typename std::iterator_traits<It>::value_type charT;
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(first, last, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == std::distance(first, last));
|
||||
unsigned i = 0;
|
||||
for (It it = first; it != last; ++it, ++i)
|
||||
assert(s2[i] == *it);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
const char* s = "12345678901234567890123456789012345678901234567890";
|
||||
|
||||
test(s, s);
|
||||
test(s, s, A(2));
|
||||
|
||||
test(s, s+1);
|
||||
test(s, s+1, A(2));
|
||||
|
||||
test(s, s+10);
|
||||
test(s, s+10, A(2));
|
||||
|
||||
test(s, s+50);
|
||||
test(s, s+50, A(2));
|
||||
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s));
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s), A(2));
|
||||
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1));
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A(2));
|
||||
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10));
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A(2));
|
||||
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50));
|
||||
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A(2));
|
||||
}
|
45
test/strings/basic.string/string.cons/move.pass.cpp
Normal file
45
test/strings/basic.string/string.cons/move.pass.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(basic_string<charT,traits,Allocator>&& str);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s0)
|
||||
{
|
||||
S s1 = s0;
|
||||
S s2 = std::move(s0);
|
||||
assert(s2.__invariants());
|
||||
assert(s0.__invariants());
|
||||
assert(s2 == s1);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
assert(s2.get_allocator() == s1.get_allocator());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
test(S(A(3)));
|
||||
test(S("1", A(5)));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
|
||||
#endif
|
||||
}
|
45
test/strings/basic.string/string.cons/move_alloc.pass.cpp
Normal file
45
test/strings/basic.string/string.cons/move_alloc.pass.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(basic_string&& str, const Allocator& alloc);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s0, const typename S::allocator_type& a)
|
||||
{
|
||||
S s1 = s0;
|
||||
S s2(std::move(s0), a);
|
||||
assert(s2.__invariants());
|
||||
assert(s0.__invariants());
|
||||
assert(s2 == s1);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
assert(s2.get_allocator() == a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
test(S(), A(3));
|
||||
test(S("1"), A(5));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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>&
|
||||
// operator=(basic_string<charT,traits,Allocator>&& str);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1, S s2)
|
||||
{
|
||||
S s0 = s2;
|
||||
s1 = std::move(s2);
|
||||
assert(s1.__invariants());
|
||||
assert(s2.__invariants());
|
||||
assert(s1 == s0);
|
||||
assert(s1.capacity() >= s1.size());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
typedef std::string S;
|
||||
test(S(), S());
|
||||
test(S("1"), S());
|
||||
test(S(), S("1"));
|
||||
test(S("1"), S("2"));
|
||||
test(S("1"), S("2"));
|
||||
|
||||
test(S(),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
#endif
|
||||
}
|
69
test/strings/basic.string/string.cons/pointer_alloc.pass.cpp
Normal file
69
test/strings/basic.string/string.cons/pointer_alloc.pass.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(const charT* s, const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(const charT* s)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
unsigned n = T::length(s);
|
||||
S s2(s);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
assert(T::compare(s2.data(), s, n) == 0);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(const charT* s, const test_allocator<charT>& a)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
unsigned n = T::length(s);
|
||||
S s2(s, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
assert(T::compare(s2.data(), s, n) == 0);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
test("");
|
||||
test("", A(2));
|
||||
|
||||
test("1");
|
||||
test("1", A(2));
|
||||
|
||||
test("1234567980");
|
||||
test("1234567980", A(2));
|
||||
|
||||
test("123456798012345679801234567980123456798012345679801234567980");
|
||||
test("123456798012345679801234567980123456798012345679801234567980", A(2));
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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>&
|
||||
// operator=(const charT* s);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s1, const typename S::value_type* s2)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
s1 = s2;
|
||||
assert(s1.__invariants());
|
||||
assert(s1.size() == T::length(s2));
|
||||
assert(T::compare(s1.data(), s2, s1.size()) == 0);
|
||||
assert(s1.capacity() >= s1.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), "");
|
||||
test(S("1"), "");
|
||||
test(S(), "1");
|
||||
test(S("1"), "2");
|
||||
test(S("1"), "2");
|
||||
|
||||
test(S(),
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
test(S("123456789"),
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(const charT* s, unsigned n)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(s, n);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
assert(T::compare(s2.data(), s, n) == 0);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(const charT* s, unsigned n, const test_allocator<charT>& a)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(s, n, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
assert(T::compare(s2.data(), s, n) == 0);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
test("", 0);
|
||||
test("", 0, A(2));
|
||||
|
||||
test("1", 1);
|
||||
test("1", 1, A(2));
|
||||
|
||||
test("1234567980", 10);
|
||||
test("1234567980", 10, A(2));
|
||||
|
||||
test("123456798012345679801234567980123456798012345679801234567980", 60);
|
||||
test("123456798012345679801234567980123456798012345679801234567980", 60, A(2));
|
||||
}
|
106
test/strings/basic.string/string.cons/size_char_alloc.pass.cpp
Normal file
106
test/strings/basic.string/string.cons/size_char_alloc.pass.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(size_type n, charT c, const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(unsigned n, charT c)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(n, c);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
assert(s2[i] == c);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class charT>
|
||||
void
|
||||
test(unsigned n, charT c, const test_allocator<charT>& a)
|
||||
{
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(n, c, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
assert(s2[i] == c);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class Tp>
|
||||
void
|
||||
test(Tp n, Tp c)
|
||||
{
|
||||
typedef char charT;
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(n, c);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
assert(s2[i] == c);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
template <class Tp>
|
||||
void
|
||||
test(Tp n, Tp c, const test_allocator<char>& a)
|
||||
{
|
||||
typedef char charT;
|
||||
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
S s2(n, c, a);
|
||||
assert(s2.__invariants());
|
||||
assert(s2.size() == n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
assert(s2[i] == c);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
test(0, 'a');
|
||||
test(0, 'a', A(2));
|
||||
|
||||
test(1, 'a');
|
||||
test(1, 'a', A(2));
|
||||
|
||||
test(10, 'a');
|
||||
test(10, 'a', A(2));
|
||||
|
||||
test(100, 'a');
|
||||
test(100, 'a', A(2));
|
||||
|
||||
test(100, 65);
|
||||
test(100, 65, A(3));
|
||||
}
|
130
test/strings/basic.string/string.cons/substr.pass.cpp
Normal file
130
test/strings/basic.string/string.cons/substr.pass.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// basic_string(const basic_string<charT,traits,Allocator>& str,
|
||||
// size_type pos, size_type n = npos,
|
||||
// const Allocator& a = Allocator());
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S str, unsigned pos)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
try
|
||||
{
|
||||
S s2(str, pos);
|
||||
assert(s2.__invariants());
|
||||
assert(pos <= str.size());
|
||||
unsigned rlen = str.size() - pos;
|
||||
assert(s2.size() == rlen);
|
||||
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S str, unsigned pos, unsigned n)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
try
|
||||
{
|
||||
S s2(str, pos, n);
|
||||
assert(s2.__invariants());
|
||||
assert(pos <= str.size());
|
||||
unsigned rlen = std::min(str.size() - pos, n);
|
||||
assert(s2.size() == rlen);
|
||||
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
|
||||
assert(s2.get_allocator() == A());
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
|
||||
{
|
||||
typedef typename S::traits_type T;
|
||||
typedef typename S::allocator_type A;
|
||||
try
|
||||
{
|
||||
S s2(str, pos, n, a);
|
||||
assert(s2.__invariants());
|
||||
assert(pos <= str.size());
|
||||
unsigned rlen = std::min(str.size() - pos, n);
|
||||
assert(s2.size() == rlen);
|
||||
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
|
||||
assert(s2.get_allocator() == a);
|
||||
assert(s2.capacity() >= s2.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
test(S(A(3)), 0);
|
||||
test(S(A(3)), 1);
|
||||
test(S("1", A(5)), 0);
|
||||
test(S("1", A(5)), 1);
|
||||
test(S("1", A(5)), 2);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 0);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 5);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 500);
|
||||
|
||||
test(S(A(3)), 0, 0);
|
||||
test(S(A(3)), 0, 1);
|
||||
test(S(A(3)), 1, 0);
|
||||
test(S(A(3)), 1, 1);
|
||||
test(S(A(3)), 1, 2);
|
||||
test(S("1", A(5)), 0, 0);
|
||||
test(S("1", A(5)), 0, 1);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100);
|
||||
|
||||
test(S(A(3)), 0, 0, A(4));
|
||||
test(S(A(3)), 0, 1, A(4));
|
||||
test(S(A(3)), 1, 0, A(4));
|
||||
test(S(A(3)), 1, 1, A(4));
|
||||
test(S(A(3)), 1, 2, A(4));
|
||||
test(S("1", A(5)), 0, 0, A(6));
|
||||
test(S("1", A(5)), 0, 1, A(6));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0, A(8));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1, A(8));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8));
|
||||
}
|
Reference in New Issue
Block a user