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:
48
test/strings/basic.string/string.capacity/capacity.pass.cpp
Normal file
48
test/strings/basic.string/string.capacity/capacity.pass.cpp
Normal file
@@ -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>
|
||||
|
||||
// size_type capacity() const;
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s)
|
||||
{
|
||||
S::allocator_type::throw_after = 0;
|
||||
try
|
||||
{
|
||||
while (s.size() < s.capacity())
|
||||
s.push_back(typename S::value_type());
|
||||
assert(s.size() == s.capacity());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
S::allocator_type::throw_after = INT_MAX;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
|
||||
S s;
|
||||
test(s);
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
38
test/strings/basic.string/string.capacity/clear.pass.cpp
Normal file
38
test/strings/basic.string/string.capacity/clear.pass.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// void clear();
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s)
|
||||
{
|
||||
s.clear();
|
||||
assert(s.size() == 0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
30
test/strings/basic.string/string.capacity/empty.pass.cpp
Normal file
30
test/strings/basic.string/string.capacity/empty.pass.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// bool empty() const;
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.empty() == (s.size() == 0));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
30
test/strings/basic.string/string.capacity/length.pass.cpp
Normal file
30
test/strings/basic.string/string.capacity/length.pass.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// size_type length() const;
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.length() == s.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
30
test/strings/basic.string/string.capacity/max_size.pass.cpp
Normal file
30
test/strings/basic.string/string.capacity/max_size.pass.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// size_type max_size() const;
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s)
|
||||
{
|
||||
assert(s.max_size() >= s.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S());
|
||||
test(S("123"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"));
|
||||
}
|
81
test/strings/basic.string/string.capacity/reserve.pass.cpp
Normal file
81
test/strings/basic.string/string.capacity/reserve.pass.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// void reserve(size_type res_arg=0);
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s)
|
||||
{
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.reserve();
|
||||
assert(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s, typename S::size_type res_arg)
|
||||
{
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
try
|
||||
{
|
||||
s.reserve(res_arg);
|
||||
assert(res_arg <= s.max_size());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() >= res_arg);
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(res_arg > s.max_size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
{
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
||||
{
|
||||
S s;
|
||||
test(s, 5);
|
||||
test(s, 10);
|
||||
test(s, 50);
|
||||
}
|
||||
{
|
||||
S s(100, 'a');
|
||||
s.erase(50);
|
||||
test(s, 5);
|
||||
test(s, 10);
|
||||
test(s, 50);
|
||||
test(s, 100);
|
||||
test(s, S::npos);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// void resize(size_type n);
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s, typename S::size_type n, S expected)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.resize(n);
|
||||
assert(s.__invariants());
|
||||
assert(n <= s.max_size());
|
||||
assert(s == expected);
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, S());
|
||||
test(S(), 1, S(1, '\0'));
|
||||
test(S(), 10, S(10, '\0'));
|
||||
test(S(), 100, S(100, '\0'));
|
||||
test(S("12345"), 0, S());
|
||||
test(S("12345"), 2, S("12"));
|
||||
test(S("12345"), 5, S("12345"));
|
||||
test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10,
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50,
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60,
|
||||
S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
|
||||
test(S(), S::npos, S("not going to happen"));
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// void resize(size_type n, charT c);
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s, typename S::size_type n, typename S::value_type c, S expected)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.resize(n, c);
|
||||
assert(s.__invariants());
|
||||
assert(n <= s.max_size());
|
||||
assert(s == expected);
|
||||
}
|
||||
catch (std::length_error&)
|
||||
{
|
||||
assert(n > s.max_size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0, 'a', S());
|
||||
test(S(), 1, 'a', S("a"));
|
||||
test(S(), 10, 'a', S(10, 'a'));
|
||||
test(S(), 100, 'a', S(100, 'a'));
|
||||
test(S("12345"), 0, 'a', S());
|
||||
test(S("12345"), 2, 'a', S("12"));
|
||||
test(S("12345"), 5, 'a', S("12345"));
|
||||
test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
|
||||
S("1234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890"));
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
|
||||
S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
|
||||
test(S(), S::npos, 'a', S("not going to happen"));
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// void shrink_to_fit();
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s)
|
||||
{
|
||||
typename S::size_type old_cap = s.capacity();
|
||||
S s0 = s;
|
||||
s.shrink_to_fit();
|
||||
assert(s.__invariants());
|
||||
assert(s == s0);
|
||||
assert(s.capacity() <= old_cap);
|
||||
assert(s.capacity() >= s.size());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
S s;
|
||||
test(s);
|
||||
|
||||
s.assign(10, 'a');
|
||||
s.erase(5);
|
||||
test(s);
|
||||
|
||||
s.assign(100, 'a');
|
||||
s.erase(50);
|
||||
test(s);
|
||||
}
|
30
test/strings/basic.string/string.capacity/size.pass.cpp
Normal file
30
test/strings/basic.string/string.capacity/size.pass.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
|
||||
// size_type size() const;
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(const S& s, typename S::size_type c)
|
||||
{
|
||||
assert(s.size() == c);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef std::string S;
|
||||
test(S(), 0);
|
||||
test(S("123"), 3);
|
||||
test(S("12345678901234567890123456789012345678901234567890"), 50);
|
||||
}
|
Reference in New Issue
Block a user