[libcxx] r224658 - Move test into test/std subdirectory.

Eric Fiselier eric at efcs.ca
Fri Dec 19 17:40:31 PST 2014


Added: libcxx/trunk/test/std/re/re.regex/re.regex.operations/tested_elsewhere.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.operations/tested_elsewhere.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/re.regex.operations/tested_elsewhere.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.operations/tested_elsewhere.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}

Added: libcxx/trunk/test/std/re/re.regex/re.regex.swap/swap.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.swap/swap.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/re.regex.swap/swap.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.swap/swap.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT, class traits = regex_traits<charT>> class basic_regex;
+
+// void swap(basic_regex& e);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    std::regex r1("(a([bc]))");
+    std::regex r2;
+    r2.swap(r1);
+    assert(r1.flags() == std::regex::ECMAScript);
+    assert(r1.mark_count() == 0);
+    assert(r2.flags() == std::regex::ECMAScript);
+    assert(r2.mark_count() == 2);
+}

Added: libcxx/trunk/test/std/re/re.regex/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/types.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/types.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.regex/types.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT, class traits = regex_traits<charT>>
+// class basic_regex
+// {
+// public:
+//     // types:
+//     typedef charT                               value_type;
+//     typedef regex_constants::syntax_option_type flag_type;
+//     typedef typename traits::locale_type        locale_type;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::basic_regex<char>::value_type, char>::value), "");
+    static_assert((std::is_same<std::basic_regex<char>::flag_type,
+                                std::regex_constants::syntax_option_type>::value), "");
+    static_assert((std::is_same<std::basic_regex<char>::locale_type, std::locale>::value), "");
+
+    static_assert((std::is_same<std::basic_regex<wchar_t>::value_type, wchar_t>::value), "");
+    static_assert((std::is_same<std::basic_regex<wchar_t>::flag_type,
+                                std::regex_constants::syntax_option_type>::value), "");
+    static_assert((std::is_same<std::basic_regex<wchar_t>::locale_type, std::locale>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.req/nothing_to_do.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.req/nothing_to_do.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.req/nothing_to_do.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.req/nothing_to_do.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/begin_end.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/begin_end.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/begin_end.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/begin_end.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// const_iterator begin() const;
+// const_iterator end() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+    std::match_results<const char*>::const_iterator i = m.begin();
+    std::match_results<const char*>::const_iterator e = m.end();
+
+    assert(e - i == m.size());
+    for (int j = 0; i != e; ++i, ++j)
+        assert(*i == m[j]);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/cbegin_cend.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/cbegin_cend.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/cbegin_cend.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/cbegin_cend.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// const_iterator cbegin() const;
+// const_iterator cend() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+    std::match_results<const char*>::const_iterator i = m.cbegin();
+    std::match_results<const char*>::const_iterator e = m.cend();
+
+    assert(e - i == m.size());
+    for (int j = 0; i != e; ++i, ++j)
+        assert(*i == m[j]);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/index.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/index.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/index.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// const_reference operator[](size_type n) const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+    assert(m[0].first == s+2);
+    assert(m[0].second == s+9);
+    assert(m[0].matched == true);
+
+    assert(m[1].first == s+4);
+    assert(m[1].second == s+7);
+    assert(m[1].matched == true);
+
+    assert(m[2].first == s+4);
+    assert(m[2].second == s+5);
+    assert(m[2].matched == true);
+
+    assert(m[3].first == s+11);
+    assert(m[3].second == s+11);
+    assert(m[3].matched == false);
+
+    assert(m[4].first == s+11);
+    assert(m[4].second == s+11);
+    assert(m[4].matched == false);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/length.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/length.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/length.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/length.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// difference_type length(size_type sub = 0) const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+    assert(m.length() == m[0].length());
+    assert(m.length(0) == m[0].length());
+    assert(m.length(1) == m[1].length());
+    assert(m.length(2) == m[2].length());
+    assert(m.length(3) == m[3].length());
+    assert(m.length(4) == m[4].length());
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/position.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/position.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/position.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/position.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// difference_type position(size_type sub = 0) const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+    assert(m.position() == std::distance(s, m[0].first));
+    assert(m.position(0) == std::distance(s, m[0].first));
+    assert(m.position(1) == std::distance(s, m[1].first));
+    assert(m.position(2) == std::distance(s, m[2].first));
+    assert(m.position(3) == std::distance(s, m[3].first));
+    assert(m.position(4) == std::distance(s, m[4].first));
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/prefix.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/prefix.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/prefix.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/prefix.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// const_reference prefix() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+    assert(m.prefix().first == s);
+    assert(m.prefix().second == s+2);
+    assert(m.prefix().matched == true);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/str.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/str.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/str.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/str.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// string_type str(size_type sub = 0) const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+    assert(m.str() == std::string(m[0]));
+    assert(m.str(0) == std::string(m[0]));
+    assert(m.str(1) == std::string(m[1]));
+    assert(m.str(2) == std::string(m[2]));
+    assert(m.str(3) == std::string(m[3]));
+    assert(m.str(4) == std::string(m[4]));
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.acc/suffix.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.acc/suffix.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.acc/suffix.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.acc/suffix.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// const_reference suffix() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+    assert(m.suffix().first == s+9);
+    assert(m.suffix().second == s+11);
+    assert(m.suffix().matched == true);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// allocator_type get_allocator() const;
+
+#include <regex>
+#include <cassert>
+
+#include "test_allocator.h"
+
+template <class CharT, class Allocator>
+void
+test(const Allocator& a)
+{
+    std::match_results<const CharT*, Allocator> m(a);
+    assert(m.size() == 0);
+    assert(m.str() == std::basic_string<CharT>());
+    assert(m.get_allocator() == a);
+}
+
+int main()
+{
+    test<char>(test_allocator<std::sub_match<const char*> >(3));
+    test<wchar_t>(test_allocator<std::sub_match<const wchar_t*> >(3));
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// match_results(const Allocator& a = Allocator());
+
+#include <regex>
+#include <cassert>
+
+#include "test_allocator.h"
+
+template <class CharT, class Allocator>
+void
+test(const Allocator& a)
+{
+    std::match_results<const CharT*, Allocator> m(a);
+    assert(m.size() == 0);
+    assert(m.str() == std::basic_string<CharT>());
+    assert(m.get_allocator() == a);
+}
+
+int main()
+{
+    test<char>(test_allocator<std::sub_match<const char*> >(3));
+    test<wchar_t>(test_allocator<std::sub_match<const wchar_t*> >(3));
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// match_results(const Allocator& a = Allocator());
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test()
+{
+    std::match_results<const CharT*> m;
+    assert(m.size() == 0);
+    assert(m.str() == std::basic_string<CharT>());
+    assert(m.get_allocator() == std::allocator<std::sub_match<const CharT*> >());
+}
+
+int main()
+{
+    test<char>();
+    test<wchar_t>();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.form/form1.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// template <class OutputIter>
+//   OutputIter
+//   format(OutputIter out, const char_type* fmt_first, const char_type* fmt_last,
+//          regex_constants::match_flag_type flags = regex_constants::format_default) const;
+
+#include <regex>
+#include <cassert>
+
+#include "test_iterators.h"
+
+int main()
+{
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        char* r = m.format(output_iterator<char*>(out),
+                    fmt, fmt + std::char_traits<char>::length(fmt)).base();
+        assert(r == out + 58);
+        assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        char* r = m.format(output_iterator<char*>(out),
+                    fmt, fmt + std::char_traits<char>::length(fmt),
+                    std::regex_constants::format_sed).base();
+        assert(r == out + 59);
+        assert(std::string(out) == "prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2";
+        char* r = m.format(output_iterator<char*>(out),
+                    fmt, fmt + std::char_traits<char>::length(fmt),
+                    std::regex_constants::format_sed).base();
+        assert(r == out + 34);
+        assert(std::string(out) == "match: cdefghi, m[1]: efg, m[2]: e");
+    }
+
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        const wchar_t fmt[] = L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out),
+                    fmt, fmt + std::char_traits<wchar_t>::length(fmt)).base();
+        assert(r == out + 58);
+        assert(std::wstring(out) == L"prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        const wchar_t fmt[] = L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out),
+                    fmt, fmt + std::char_traits<wchar_t>::length(fmt),
+                    std::regex_constants::format_sed).base();
+        assert(r == out + 59);
+        assert(std::wstring(out) == L"prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        const wchar_t fmt[] = L"match: &, m[1]: \\1, m[2]: \\2";
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out),
+                    fmt, fmt + std::char_traits<wchar_t>::length(fmt),
+                    std::regex_constants::format_sed).base();
+        assert(r == out + 34);
+        assert(std::wstring(out) == L"match: cdefghi, m[1]: efg, m[2]: e");
+    }
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.form/form2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.form/form2.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.form/form2.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.form/form2.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,102 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// template <class OutputIter, class ST, class SA>
+//   OutputIter
+//   format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
+//          regex_constants::match_flag_type flags = regex_constants::format_default) const;
+
+#include <iostream>
+
+#include <regex>
+#include <cassert>
+
+#include "test_iterators.h"
+#include "test_allocator.h"
+
+int main()
+{
+    typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > nstr;
+    typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t> > wstr;
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        nstr fmt("prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        char* r = m.format(output_iterator<char*>(out), fmt).base();
+        assert(r == out + 58);
+        assert(std::string(out) == "prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        nstr fmt("prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        char* r = m.format(output_iterator<char*>(out),
+                    fmt, std::regex_constants::format_sed).base();
+        assert(r == out + 59);
+        assert(std::string(out) == "prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        char out[100] = {0};
+        nstr fmt("match: &, m[1]: \\1, m[2]: \\2");
+        char* r = m.format(output_iterator<char*>(out),
+                    fmt, std::regex_constants::format_sed).base();
+        assert(r == out + 34);
+        assert(std::string(out) == "match: cdefghi, m[1]: efg, m[2]: e");
+    }
+
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        wstr fmt(L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out), fmt).base();
+        assert(r == out + 58);
+        assert(std::wstring(out) == L"prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        wstr fmt(L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out),
+                    fmt, std::regex_constants::format_sed).base();
+        assert(r == out + 59);
+        assert(std::wstring(out) == L"prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wchar_t out[100] = {0};
+        wstr fmt(L"match: &, m[1]: \\1, m[2]: \\2");
+        wchar_t* r = m.format(output_iterator<wchar_t*>(out),
+                    fmt, std::regex_constants::format_sed).base();
+        assert(r == out + 34);
+        assert(std::wstring(out) == L"match: cdefghi, m[1]: efg, m[2]: e");
+    }
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.form/form3.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.form/form3.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.form/form3.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.form/form3.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// template <class ST, class SA>
+//   basic_string<char_type, ST, SA>
+//   format(const basic_string<char_type, ST, SA>& fmt,
+//          regex_constants::match_flag_type flags = regex_constants::format_default) const;
+
+#include <iostream>
+
+#include <regex>
+#include <cassert>
+
+#include "test_allocator.h"
+
+int main()
+{
+    typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > nstr;
+    typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t> > wstr;
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        nstr fmt("prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        nstr out = m.format(fmt);
+        assert(out == "prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        nstr fmt("prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        nstr out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == "prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        nstr fmt("match: &, m[1]: \\1, m[2]: \\2");
+        nstr out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == "match: cdefghi, m[1]: efg, m[2]: e");
+    }
+
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wstr fmt(L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        wstr out = m.format(fmt);
+        assert(out == L"prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wstr fmt(L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2");
+        wstr out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == L"prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        wstr fmt(L"match: &, m[1]: \\1, m[2]: \\2");
+        wstr out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == L"match: cdefghi, m[1]: efg, m[2]: e");
+    }
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.form/form4.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.form/form4.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.form/form4.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.form/form4.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// string_type
+//   format(const char_type* fmt,
+//          regex_constants::match_flag_type flags = regex_constants::format_default) const;
+
+#include <iostream>
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        std::string out = m.format(fmt);
+        assert(out == "prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        const char fmt[] = "prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        std::string out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == "prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const char*> m;
+        const char s[] = "abcdefghijk";
+        assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+
+        const char fmt[] = "match: &, m[1]: \\1, m[2]: \\2";
+        std::string out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == "match: cdefghi, m[1]: efg, m[2]: e");
+    }
+
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        const wchar_t fmt[] = L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        std::wstring out = m.format(fmt);
+        assert(out == L"prefix: ab, match: cdefghi, suffix: jk, m[1]: efg, m[2]: e");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        const wchar_t fmt[] = L"prefix: $`, match: $&, suffix: $', m[1]: $1, m[2]: $2";
+        std::wstring out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == L"prefix: $`, match: $cdefghi, suffix: $', m[1]: $1, m[2]: $2");
+    }
+    {
+        std::match_results<const wchar_t*> m;
+        const wchar_t s[] = L"abcdefghijk";
+        assert(std::regex_search(s, m, std::wregex(L"cd((e)fg)hi")));
+
+        const wchar_t fmt[] = L"match: &, m[1]: \\1, m[2]: \\2";
+        std::wstring out = m.format(fmt, std::regex_constants::format_sed);
+        assert(out == L"match: cdefghi, m[1]: efg, m[2]: e");
+    }
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.nonmember/equal.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.nonmember/equal.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.nonmember/equal.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.nonmember/equal.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// template <class BidirectionalIterator, class Allocator>
+//    bool
+//    operator==(const match_results<BidirectionalIterator, Allocator>& m1,
+//               const match_results<BidirectionalIterator, Allocator>& m2);
+
+// template <class BidirectionalIterator, class Allocator>
+//    bool
+//    operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
+//               const match_results<BidirectionalIterator, Allocator>& m2);
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m1;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m1, std::regex("cd((e)fg)hi")));
+    std::match_results<const char*> m2;
+
+    assert(m1 == m1);
+    assert(m1 != m2);
+
+    m2 = m1;
+
+    assert(m1 == m2);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.size/empty.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.size/empty.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.size/empty.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.size/empty.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// size_type size() const;
+// bool empty() const;
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test()
+{
+    std::match_results<const CharT*> m;
+    assert(m.empty());
+    assert(m.size() == 0);
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m, std::regex("cd((e)fg)hi")));
+    assert(!m.empty());
+    assert(m.size() == 3);
+}
+
+int main()
+{
+    test<char>();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.size/max_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.size/max_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.size/max_size.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.size/max_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// size_type max_size() const;
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test()
+{
+    std::match_results<const CharT*> m;
+    assert(m.max_size() > 0);
+}
+
+int main()
+{
+    test<char>();
+    test<wchar_t>();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.state/ready.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.state/ready.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.state/ready.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.state/ready.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// bool ready() const;
+
+#include <regex>
+#include <cassert>
+
+void
+test1()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(m.ready() == false);
+    std::regex_search(s, m, std::regex("cd((e)fg)hi"));
+    assert(m.ready() == true);
+}
+
+void
+test2()
+{
+    std::match_results<const char*> m;
+    const char s[] = "abcdefghijk";
+    assert(m.ready() == false);
+    std::regex_search(s, m, std::regex("z"));
+    assert(m.ready() == true);
+}
+
+int main()
+{
+    test1();
+    test2();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.swap/member_swap.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.swap/member_swap.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.swap/member_swap.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.swap/member_swap.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// void swap(match_results& that);
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m1;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m1, std::regex("cd((e)fg)hi")));
+    std::match_results<const char*> m2;
+
+    std::match_results<const char*> m1_save = m1;
+    std::match_results<const char*> m2_save = m2;
+
+    m1.swap(m2);
+
+    assert(m1 == m2_save);
+    assert(m2 == m1_save);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/re.results.swap/non_member_swap.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.swap/non_member_swap.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.swap/non_member_swap.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/re.results.swap/non_member_swap.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// class match_results<BidirectionalIterator, Allocator>
+
+// template <class BidirectionalIterator, class Allocator>
+//    void swap(match_results<BidirectionalIterator, Allocator>& m1,
+//              match_results<BidirectionalIterator, Allocator>& m2);
+
+#include <regex>
+#include <cassert>
+
+void
+test()
+{
+    std::match_results<const char*> m1;
+    const char s[] = "abcdefghijk";
+    assert(std::regex_search(s, m1, std::regex("cd((e)fg)hi")));
+    std::match_results<const char*> m2;
+
+    std::match_results<const char*> m1_save = m1;
+    std::match_results<const char*> m2_save = m2;
+
+    swap(m1, m2);
+
+    assert(m1 == m2_save);
+    assert(m2 == m1_save);
+}
+
+int main()
+{
+    test();
+}

Added: libcxx/trunk/test/std/re/re.results/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/types.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.results/types.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.results/types.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator,
+//           class Allocator = allocator<sub_match<BidirectionalIterator>>>
+// class match_results
+// {
+// public:
+//     typedef sub_match<BidirectionalIterator>                  value_type;
+//     typedef const value_type&                                 const_reference;
+//     typedef const_reference                                   reference;
+//     typedef /implementation-defined/                          const_iterator;
+//     typedef const_iterator                                    iterator;
+//     typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
+//     typedef typename allocator_traits<Allocator>::size_type   size_type;
+//     typedef Allocator                                         allocator_type;
+//     typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
+//     typedef basic_string<char_type>                           string_type;
+
+#include <regex>
+#include <type_traits>
+
+template <class CharT>
+void
+test()
+{
+    typedef std::match_results<CharT*> MR;
+    static_assert((std::is_same<typename MR::value_type, std::sub_match<CharT*> >::value), "");
+    static_assert((std::is_same<typename MR::const_reference, const std::sub_match<CharT*>& >::value), "");
+    static_assert((std::is_same<typename MR::reference, std::sub_match<CharT*>& >::value), "");
+    static_assert((!std::is_same<typename MR::const_iterator, void>::value), "");
+    static_assert((std::is_same<typename MR::difference_type, std::ptrdiff_t>::value), "");
+    static_assert((std::is_same<typename MR::size_type, std::size_t>::value), "");
+    static_assert((std::is_same<typename MR::allocator_type, std::allocator<std::sub_match<CharT*> > >::value), "");
+    static_assert((std::is_same<typename MR::char_type, CharT>::value), "");
+    static_assert((std::is_same<typename MR::string_type, std::basic_string<CharT> >::value), "");
+}
+
+int main()
+{
+    test<char>();
+    test<wchar_t>();
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_string_type.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// int compare(const string_type& s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        typedef SM::string_type string;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(string()) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(string()) > 0);
+        assert(sm.compare(string("123")) == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        typedef SM::string_type string;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(string()) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(string()) > 0);
+        assert(sm.compare(string(L"123")) == 0);
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_sub_match.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// int compare(const sub_match& s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(sm2) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(sm2) > 0);
+        sm2.first = s;
+        sm2.second = s + 3;
+        sm2.matched = true;
+        assert(sm.compare(sm2) == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(sm2) == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(sm2) > 0);
+        sm2.first = s;
+        sm2.second = s + 3;
+        sm2.matched = true;
+        assert(sm.compare(sm2) == 0);
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/compare_value_type_ptr.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// int compare(const value_type* s) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare("") == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare("") > 0);
+        assert(sm.compare("123") == 0);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM sm2 = SM();
+        assert(sm.compare(L"") == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.compare(L"") > 0);
+        assert(sm.compare(L"123") == 0);
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/default.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/default.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/default.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// constexpr sub_match();
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm;
+        assert(sm.matched == false);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm;
+        assert(sm.matched == false);
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/length.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/length.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/length.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/length.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// difference_type length() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        assert(sm.length() == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.length() == 3);
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        assert(sm.length() == 0);
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        assert(sm.length() == 3);
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/operator_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/operator_string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/operator_string.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/operator_string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// operator string_type() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm;
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm;
+        assert(str == std::string("123"));
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm;
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm;
+        assert(str == std::wstring(L"123"));
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.members/str.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.members/str.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.members/str.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.members/str.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// string_type str() const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef char CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm.str();
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm.str();
+        assert(str == std::string("123"));
+    }
+    {
+        typedef wchar_t CharT;
+        typedef std::sub_match<const CharT*> SM;
+        SM sm = SM();
+        SM::string_type str = sm.str();
+        assert(str.empty());
+        const CharT s[] = {'1', '2', '3', 0};
+        sm.first = s;
+        sm.second = s + 3;
+        sm.matched = true;
+        str = sm.str();
+        assert(str == std::wstring(L"123"));
+    }
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.op/compare.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.op/compare.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.op/compare.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.op/compare.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,287 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                     const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool operator>(const sub_match<BiIter>& lhs,
+//                    const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter, class ST, class SA>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator==(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<(typename iterator_traits<BiIter>::value_type const* lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>(typename iterator_traits<BiIter>::value_type const* lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const* rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator==(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<(typename iterator_traits<BiIter>::value_type const& lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>(typename iterator_traits<BiIter>::value_type const& lhs,
+//               const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
+//                const sub_match<BiIter>& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator==(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator!=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>(const sub_match<BiIter>& lhs,
+//               typename iterator_traits<BiIter>::value_type const& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator>=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+//
+// template <class BiIter>
+//     bool
+//     operator<=(const sub_match<BiIter>& lhs,
+//                typename iterator_traits<BiIter>::value_type const& rhs);
+
+#include <regex>
+#include <cassert>
+
+template <class CharT>
+void
+test(const std::basic_string<CharT>& x, const std::basic_string<CharT>& y, bool doCStrTests = true)
+{
+    typedef std::basic_string<CharT> string;
+    typedef std::sub_match<typename string::const_iterator> sub_match;
+    sub_match sm1;
+    sm1.first = x.begin();
+    sm1.second = x.end();
+    sm1.matched = true;
+    sub_match sm2;
+    sm2.first = y.begin();
+    sm2.second = y.end();
+    sm2.matched = true;
+    assert((sm1 == sm2) == (x == y));
+    assert((sm1 != sm2) == (x != y));
+    assert((sm1 < sm2) == (x < y));
+    assert((sm1 > sm2) == (x > y));
+    assert((sm1 <= sm2) == (x <= y));
+    assert((sm1 >= sm2) == (x >= y));
+    assert((x == sm2) == (x == y));
+    assert((x != sm2) == (x != y));
+    assert((x < sm2) == (x < y));
+    assert((x > sm2) == (x > y));
+    assert((x <= sm2) == (x <= y));
+    assert((x >= sm2) == (x >= y));
+    assert((sm1 == y) == (x == y));
+    assert((sm1 != y) == (x != y));
+    assert((sm1 < y) == (x < y));
+    assert((sm1 > y) == (x > y));
+    assert((sm1 <= y) == (x <= y));
+    assert((sm1 >= y) == (x >= y));
+    if (doCStrTests) {
+        assert((x.c_str() == sm2) == (x == y));
+        assert((x.c_str() != sm2) == (x != y));
+        assert((x.c_str() < sm2) == (x < y));
+        assert((x.c_str() > sm2) == (x > y));
+        assert((x.c_str() <= sm2) == (x <= y));
+        assert((x.c_str() >= sm2) == (x >= y));
+        assert((sm1 == y.c_str()) == (x == y));
+        assert((sm1 != y.c_str()) == (x != y));
+        assert((sm1 < y.c_str()) == (x < y));
+        assert((sm1 > y.c_str()) == (x > y));
+        assert((sm1 <= y.c_str()) == (x <= y));
+        assert((sm1 >= y.c_str()) == (x >= y));
+        }
+    assert((x[0] == sm2) == (string(1, x[0]) == y));
+    assert((x[0] != sm2) == (string(1, x[0]) != y));
+    assert((x[0] < sm2) == (string(1, x[0]) < y));
+    assert((x[0] > sm2) == (string(1, x[0]) > y));
+    assert((x[0] <= sm2) == (string(1, x[0]) <= y));
+    assert((x[0] >= sm2) == (string(1, x[0]) >= y));
+    assert((sm1 == y[0]) == (x == string(1, y[0])));
+    assert((sm1 != y[0]) == (x != string(1, y[0])));
+    assert((sm1 < y[0]) == (x < string(1, y[0])));
+    assert((sm1 > y[0]) == (x > string(1, y[0])));
+    assert((sm1 <= y[0]) == (x <= string(1, y[0])));
+    assert((sm1 >= y[0]) == (x >= string(1, y[0])));
+}
+
+int main()
+{
+    test(std::string("123"), std::string("123"));
+    test(std::string("1234"), std::string("123"));
+    test(std::wstring(L"123"), std::wstring(L"123"));
+    test(std::wstring(L"1234"), std::wstring(L"123"));
+    test(std::string("123\00056", 6), std::string("123\00056", 6), false);
+    test(std::wstring(L"123\00056", 6), std::wstring(L"123\00056", 6), false);
+}

Added: libcxx/trunk/test/std/re/re.submatch/re.submatch.op/stream.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/re.submatch.op/stream.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/re.submatch.op/stream.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/re.submatch.op/stream.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator> class sub_match;
+
+// template <class charT, class ST, class BiIter>
+//     basic_ostream<charT, ST>&
+//     operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
+
+#include <regex>
+#include <sstream>
+#include <cassert>
+
+template <class CharT>
+void
+test(const std::basic_string<CharT>& s)
+{
+    typedef std::basic_string<CharT> string;
+    typedef std::sub_match<typename string::const_iterator> SM;
+    typedef std::basic_ostringstream<CharT> ostringstream;
+    SM sm;
+    sm.first = s.begin();
+    sm.second = s.end();
+    sm.matched = true;
+    ostringstream os;
+    os << sm;
+    assert(os.str() == s);
+}
+
+int main()
+{
+    test(std::string("123"));
+    test(std::wstring(L"123"));
+}

Added: libcxx/trunk/test/std/re/re.submatch/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.submatch/types.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.submatch/types.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.submatch/types.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class BidirectionalIterator>
+// class sub_match
+//     : public pair<BidirectionalIterator, BidirectionalIterator>
+// {
+// public:
+//     typedef BidirectionalIterator                               iterator;
+//     typedef typename iterator_traits<iterator>::value_type      value_type;
+//     typedef typename iterator_traits<iterator>::difference_type difference_type;
+//     typedef basic_string<value_type>                            string_type;
+//
+//     bool matched;
+//     ...
+// };
+
+#include <regex>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::sub_match<char*> SM;
+        static_assert((std::is_same<SM::iterator, char*>::value), "");
+        static_assert((std::is_same<SM::value_type, char>::value), "");
+        static_assert((std::is_same<SM::difference_type, std::ptrdiff_t>::value), "");
+        static_assert((std::is_same<SM::string_type, std::string>::value), "");
+        static_assert((std::is_convertible<SM*, std::pair<char*, char*>*>::value), "");
+
+        SM sm;
+        sm.first = nullptr;
+        sm.second = nullptr;
+        sm.matched = false;
+    }
+    {
+        typedef std::sub_match<wchar_t*> SM;
+        static_assert((std::is_same<SM::iterator, wchar_t*>::value), "");
+        static_assert((std::is_same<SM::value_type, wchar_t>::value), "");
+        static_assert((std::is_same<SM::difference_type, std::ptrdiff_t>::value), "");
+        static_assert((std::is_same<SM::string_type, std::wstring>::value), "");
+        static_assert((std::is_convertible<SM*, std::pair<wchar_t*, wchar_t*>*>::value), "");
+
+        SM sm;
+        sm.first = nullptr;
+        sm.second = nullptr;
+        sm.matched = false;
+    }
+    {
+        static_assert((std::is_same<std::csub_match, std::sub_match<const char*> >::value), "");
+        static_assert((std::is_same<std::wcsub_match, std::sub_match<const wchar_t*> >::value), "");
+        static_assert((std::is_same<std::ssub_match, std::sub_match<std::string::const_iterator> >::value), "");
+        static_assert((std::is_same<std::wssub_match, std::sub_match<std::wstring::const_iterator> >::value), "");
+    }
+}

Added: libcxx/trunk/test/std/re/re.syn/cmatch.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/cmatch.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/cmatch.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/cmatch.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef match_results<const char*>   cmatch;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::match_results<const char*>, std::cmatch>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/cregex_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/cregex_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/cregex_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/cregex_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_iterator<const char*>   cregex_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_iterator<const char*>, std::cregex_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/cregex_token_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/cregex_token_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/cregex_token_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/cregex_token_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_token_iterator<const char*>   cregex_token_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_token_iterator<const char*>, std::cregex_token_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/csub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/csub_match.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/csub_match.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/csub_match.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef sub_match<const char*>   csub_match;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::sub_match<const char*>, std::csub_match>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/regex.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/regex.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/regex.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/regex.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef basic_regex<char>    regex;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::basic_regex<char>, std::regex>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/smatch.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/smatch.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/smatch.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/smatch.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef match_results<string::const_iterator>   smatch;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::match_results<std::string::const_iterator>, std::smatch>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/sregex_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/sregex_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/sregex_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/sregex_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_iterator<string::const_iterator>   sregex_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_iterator<std::string::const_iterator>, std::sregex_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/sregex_token_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/sregex_token_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/sregex_token_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/sregex_token_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_token_iterator<string::const_iterator>   sregex_token_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_token_iterator<std::string::const_iterator>, std::sregex_token_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/ssub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/ssub_match.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/ssub_match.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/ssub_match.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef sub_match<string::const_iterator>   ssub_match;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::sub_match<std::string::const_iterator>, std::ssub_match>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wcmatch.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wcmatch.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wcmatch.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wcmatch.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef match_results<const wchar_t*>   wcmatch;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::match_results<const wchar_t*>, std::wcmatch>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wcregex_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wcregex_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wcregex_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wcregex_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_iterator<const wchar_t*>   wcregex_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_iterator<const wchar_t*>, std::wcregex_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wcregex_token_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wcregex_token_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wcregex_token_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wcregex_token_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_token_iterator<const wchar_t*>   wcregex_token_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_token_iterator<const wchar_t*>, std::wcregex_token_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wcsub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wcsub_match.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wcsub_match.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wcsub_match.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef sub_match<const wchar_t*>   wcsub_match;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::sub_match<const wchar_t*>, std::wcsub_match>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wregex.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wregex.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wregex.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wregex.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef basic_regex<wchar_t> wregex;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::basic_regex<wchar_t>, std::wregex>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wsmatch.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wsmatch.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wsmatch.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wsmatch.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef match_results<wstring::const_iterator>   wsmatch;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::match_results<std::wstring::const_iterator>, std::wsmatch>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wsregex_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wsregex_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wsregex_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wsregex_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_iterator<wstring::const_iterator>   wsregex_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_iterator<std::wstring::const_iterator>, std::wsregex_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wsregex_token_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wsregex_token_iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wsregex_token_iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wsregex_token_iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef regex_token_iterator<wstring::const_iterator>   wsregex_token_iterator;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_token_iterator<std::wstring::const_iterator>, std::wsregex_token_iterator>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.syn/wssub_match.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.syn/wssub_match.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.syn/wssub_match.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.syn/wssub_match.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// typedef sub_match<wstring::const_iterator>   wssub_match;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::sub_match<std::wstring::const_iterator>, std::wssub_match>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.traits/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/default.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/default.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/default.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// regex_traits();
+
+#include <regex>
+#include <cassert>
+
+#include "platform_support.h" // locale name macros
+
+int main()
+{
+    {
+        std::regex_traits<char> t1;
+        assert(t1.getloc().name() == "C");
+        std::regex_traits<wchar_t> t2;
+        assert(t2.getloc().name() == "C");
+    }
+    {
+        std::locale::global(std::locale(LOCALE_en_US_UTF_8));
+        std::regex_traits<char> t1;
+        assert(t1.getloc().name() == LOCALE_en_US_UTF_8);
+        std::regex_traits<wchar_t> t2;
+        assert(t2.getloc().name() == LOCALE_en_US_UTF_8);
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/getloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/getloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/getloc.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/getloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// locale_type getloc()const;
+
+#include <regex>
+#include <cassert>
+
+#include "platform_support.h" // locale name macros
+
+int main()
+{
+    {
+        std::regex_traits<char> t1;
+        assert(t1.getloc().name() == "C");
+        std::regex_traits<wchar_t> t2;
+        assert(t2.getloc().name() == "C");
+    }
+    {
+        std::locale::global(std::locale(LOCALE_en_US_UTF_8));
+        std::regex_traits<char> t1;
+        assert(t1.getloc().name() == LOCALE_en_US_UTF_8);
+        std::regex_traits<wchar_t> t2;
+        assert(t2.getloc().name() == LOCALE_en_US_UTF_8);
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/imbue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/imbue.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/imbue.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/imbue.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// locale_type imbue(locale_type l);
+
+#include <regex>
+#include <locale>
+#include <cassert>
+
+#include "platform_support.h" // locale name macros
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+        std::locale loc = t.imbue(std::locale(LOCALE_en_US_UTF_8));
+        assert(loc.name() == "C");
+        assert(t.getloc().name() == LOCALE_en_US_UTF_8);
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/isctype.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/isctype.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/isctype.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/isctype.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,279 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// bool isctype(charT c, char_class_type f) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+
+        std::string s("w");
+        assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "alnum";
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "alpha";
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "blank";
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "cntrl";
+        assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "digit";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "graph";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "lower";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "print";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "punct";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "space";
+        assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "upper";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+
+        s = "xdigit";
+        assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
+    }
+    {
+        std::regex_traits<wchar_t> t;
+
+        std::wstring s(L"w");
+        assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"alnum";
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"alpha";
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"blank";
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"cntrl";
+        assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"digit";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"graph";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"lower";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"print";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"punct";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"space";
+        assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"upper";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+
+        s = L"xdigit";
+        assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
+        assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
+        assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/length.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/length.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/length.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/length.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,31 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// static std::size_t length(const char_type* p);
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    assert(std::regex_traits<char>::length("") == 0);
+    assert(std::regex_traits<char>::length("1") == 1);
+    assert(std::regex_traits<char>::length("12") == 2);
+    assert(std::regex_traits<char>::length("123") == 3);
+
+    assert(std::regex_traits<wchar_t>::length(L"") == 0);
+    assert(std::regex_traits<wchar_t>::length(L"1") == 1);
+    assert(std::regex_traits<wchar_t>::length(L"12") == 2);
+    assert(std::regex_traits<wchar_t>::length(L"123") == 3);
+}

Added: libcxx/trunk/test/std/re/re.traits/lookup_classname.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/lookup_classname.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/lookup_classname.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/lookup_classname.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,211 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// template <class ForwardIterator>
+//   char_class_type
+//   lookup_classname(ForwardIterator first, ForwardIterator last,
+//                    bool icase = false) const;
+
+#include <regex>
+#include <cassert>
+#include "test_iterators.h"
+
+template <class char_type>
+void
+test(const char_type* A,
+     typename std::regex_traits<char_type>::char_class_type expected,
+     bool icase = false)
+{
+    std::regex_traits<char_type> t;
+    typedef forward_iterator<const char_type*> F;
+    assert(t.lookup_classname(F(A), F(A + t.length(A)), icase) == expected);
+}
+
+int main()
+{
+    test("d", std::ctype_base::digit);
+    test("D", std::ctype_base::digit);
+    test("d", std::ctype_base::digit, true);
+    test("D", std::ctype_base::digit, true);
+
+    test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower);
+    test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower);
+    test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower, true);
+    test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower, true);
+
+    test("s", std::ctype_base::space);
+    test("S", std::ctype_base::space);
+    test("s", std::ctype_base::space, true);
+    test("S", std::ctype_base::space, true);
+
+    test("alnum", std::ctype_base::alnum);
+    test("AlNum", std::ctype_base::alnum);
+    test("alnum", std::ctype_base::alnum, true);
+    test("AlNum", std::ctype_base::alnum, true);
+
+    test("alpha", std::ctype_base::alpha);
+    test("Alpha", std::ctype_base::alpha);
+    test("alpha", std::ctype_base::alpha, true);
+    test("Alpha", std::ctype_base::alpha, true);
+
+    test("blank", std::ctype_base::blank);
+    test("Blank", std::ctype_base::blank);
+    test("blank", std::ctype_base::blank, true);
+    test("Blank", std::ctype_base::blank, true);
+
+    test("cntrl", std::ctype_base::cntrl);
+    test("Cntrl", std::ctype_base::cntrl);
+    test("cntrl", std::ctype_base::cntrl, true);
+    test("Cntrl", std::ctype_base::cntrl, true);
+
+    test("digit", std::ctype_base::digit);
+    test("Digit", std::ctype_base::digit);
+    test("digit", std::ctype_base::digit, true);
+    test("Digit", std::ctype_base::digit, true);
+
+    test("digit", std::ctype_base::digit);
+    test("DIGIT", std::ctype_base::digit);
+    test("digit", std::ctype_base::digit, true);
+    test("Digit", std::ctype_base::digit, true);
+
+    test("graph", std::ctype_base::graph);
+    test("GRAPH", std::ctype_base::graph);
+    test("graph", std::ctype_base::graph, true);
+    test("Graph", std::ctype_base::graph, true);
+
+    test("lower", std::ctype_base::lower);
+    test("LOWER", std::ctype_base::lower);
+    test("lower", std::ctype_base::lower | std::ctype_base::alpha, true);
+    test("Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
+
+    test("print", std::ctype_base::print);
+    test("PRINT", std::ctype_base::print);
+    test("print", std::ctype_base::print, true);
+    test("Print", std::ctype_base::print, true);
+
+    test("punct", std::ctype_base::punct);
+    test("PUNCT", std::ctype_base::punct);
+    test("punct", std::ctype_base::punct, true);
+    test("Punct", std::ctype_base::punct, true);
+
+    test("space", std::ctype_base::space);
+    test("SPACE", std::ctype_base::space);
+    test("space", std::ctype_base::space, true);
+    test("Space", std::ctype_base::space, true);
+
+    test("upper", std::ctype_base::upper);
+    test("UPPER", std::ctype_base::upper);
+    test("upper", std::ctype_base::upper | std::ctype_base::alpha, true);
+    test("Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
+
+    test("xdigit", std::ctype_base::xdigit);
+    test("XDIGIT", std::ctype_base::xdigit);
+    test("xdigit", std::ctype_base::xdigit, true);
+    test("Xdigit", std::ctype_base::xdigit, true);
+
+    test("dig", std::ctype_base::mask());
+    test("", std::ctype_base::mask());
+    test("digits", std::ctype_base::mask());
+
+    test(L"d", std::ctype_base::digit);
+    test(L"D", std::ctype_base::digit);
+    test(L"d", std::ctype_base::digit, true);
+    test(L"D", std::ctype_base::digit, true);
+
+    test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower);
+    test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower);
+    test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower, true);
+    test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
+                      | std::ctype_base::upper | std::ctype_base::lower, true);
+
+    test(L"s", std::ctype_base::space);
+    test(L"S", std::ctype_base::space);
+    test(L"s", std::ctype_base::space, true);
+    test(L"S", std::ctype_base::space, true);
+
+    test(L"alnum", std::ctype_base::alnum);
+    test(L"AlNum", std::ctype_base::alnum);
+    test(L"alnum", std::ctype_base::alnum, true);
+    test(L"AlNum", std::ctype_base::alnum, true);
+
+    test(L"alpha", std::ctype_base::alpha);
+    test(L"Alpha", std::ctype_base::alpha);
+    test(L"alpha", std::ctype_base::alpha, true);
+    test(L"Alpha", std::ctype_base::alpha, true);
+
+    test(L"blank", std::ctype_base::blank);
+    test(L"Blank", std::ctype_base::blank);
+    test(L"blank", std::ctype_base::blank, true);
+    test(L"Blank", std::ctype_base::blank, true);
+
+    test(L"cntrl", std::ctype_base::cntrl);
+    test(L"Cntrl", std::ctype_base::cntrl);
+    test(L"cntrl", std::ctype_base::cntrl, true);
+    test(L"Cntrl", std::ctype_base::cntrl, true);
+
+    test(L"digit", std::ctype_base::digit);
+    test(L"Digit", std::ctype_base::digit);
+    test(L"digit", std::ctype_base::digit, true);
+    test(L"Digit", std::ctype_base::digit, true);
+
+    test(L"digit", std::ctype_base::digit);
+    test(L"DIGIT", std::ctype_base::digit);
+    test(L"digit", std::ctype_base::digit, true);
+    test(L"Digit", std::ctype_base::digit, true);
+
+    test(L"graph", std::ctype_base::graph);
+    test(L"GRAPH", std::ctype_base::graph);
+    test(L"graph", std::ctype_base::graph, true);
+    test(L"Graph", std::ctype_base::graph, true);
+
+    test(L"lower", std::ctype_base::lower);
+    test(L"LOWER", std::ctype_base::lower);
+    test(L"lower", std::ctype_base::lower | std::ctype_base::alpha, true);
+    test(L"Lower", std::ctype_base::lower | std::ctype_base::alpha, true);
+
+    test(L"print", std::ctype_base::print);
+    test(L"PRINT", std::ctype_base::print);
+    test(L"print", std::ctype_base::print, true);
+    test(L"Print", std::ctype_base::print, true);
+
+    test(L"punct", std::ctype_base::punct);
+    test(L"PUNCT", std::ctype_base::punct);
+    test(L"punct", std::ctype_base::punct, true);
+    test(L"Punct", std::ctype_base::punct, true);
+
+    test(L"space", std::ctype_base::space);
+    test(L"SPACE", std::ctype_base::space);
+    test(L"space", std::ctype_base::space, true);
+    test(L"Space", std::ctype_base::space, true);
+
+    test(L"upper", std::ctype_base::upper);
+    test(L"UPPER", std::ctype_base::upper);
+    test(L"upper", std::ctype_base::upper | std::ctype_base::alpha, true);
+    test(L"Upper", std::ctype_base::upper | std::ctype_base::alpha, true);
+
+    test(L"xdigit", std::ctype_base::xdigit);
+    test(L"XDIGIT", std::ctype_base::xdigit);
+    test(L"xdigit", std::ctype_base::xdigit, true);
+    test(L"Xdigit", std::ctype_base::xdigit, true);
+
+    test(L"dig", std::ctype_base::mask());
+    test(L"", std::ctype_base::mask());
+    test(L"digits", std::ctype_base::mask());
+}

Added: libcxx/trunk/test/std/re/re.traits/lookup_collatename.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/lookup_collatename.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/lookup_collatename.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/lookup_collatename.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,190 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: locale.cs_CZ.ISO8859-2
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// template <class ForwardIterator>
+//   string_type
+//   lookup_collatename(ForwardIterator first, ForwardIterator last) const;
+
+// TODO: investigation needed
+// XFAIL: linux-gnu
+
+#include <regex>
+#include <iterator>
+#include <cassert>
+#include "test_iterators.h"
+
+template <class char_type>
+void
+test(const char_type* A, const std::basic_string<char_type>& expected)
+{
+    std::regex_traits<char_type> t;
+    typedef forward_iterator<const char_type*> F;
+    assert(t.lookup_collatename(F(A), F(A + t.length(A))) == expected);
+}
+
+int main()
+{
+    test("NUL", std::string("\x00", 1));
+    test("alert", std::string("\x07"));
+    test("backspace", std::string("\x08"));
+    test("tab", std::string("\x09"));
+    test("carriage-return", std::string("\x0D"));
+    test("newline", std::string("\x0A"));
+    test("vertical-tab", std::string("\x0B"));
+    test("form-feed", std::string("\x0C"));
+    test("space", std::string(" "));
+    test("exclamation-mark", std::string("!"));
+    test("quotation-mark", std::string("\""));
+    test("number-sign", std::string("#"));
+    test("dollar-sign", std::string("$"));
+    test("percent-sign", std::string("%"));
+    test("ampersand", std::string("&"));
+    test("apostrophe", std::string("\'"));
+    test("left-parenthesis", std::string("("));
+    test("right-parenthesis", std::string(")"));
+    test("asterisk", std::string("*"));
+    test("plus-sign", std::string("+"));
+    test("comma", std::string(","));
+    test("hyphen-minus", std::string("-"));
+    test("hyphen", std::string("-"));
+    test("full-stop", std::string("."));
+    test("period", std::string("."));
+    test("slash", std::string("/"));
+    test("solidus", std::string("/"));
+    test("zero", std::string("0"));
+    test("one", std::string("1"));
+    test("two", std::string("2"));
+    test("three", std::string("3"));
+    test("four", std::string("4"));
+    test("five", std::string("5"));
+    test("six", std::string("6"));
+    test("seven", std::string("7"));
+    test("eight", std::string("8"));
+    test("nine", std::string("9"));
+    test("colon", std::string(":"));
+    test("semicolon", std::string(";"));
+    test("less-than-sign", std::string("<"));
+    test("equals-sign", std::string("="));
+    test("greater-than-sign", std::string(">"));
+    test("question-mark", std::string("?"));
+    test("commercial-at", std::string("@"));
+    for (char c = 'A'; c <= 'Z'; ++c)
+    {
+        const char a[2] = {c};
+        test(a, std::string(a));
+    }
+    test("left-square-bracket", std::string("["));
+    test("backslash", std::string("\\"));
+    test("reverse-solidus", std::string("\\"));
+    test("right-square-bracket", std::string("]"));
+    test("circumflex-accent", std::string("^"));
+    test("circumflex", std::string("^"));
+    test("low-line", std::string("_"));
+    test("underscore", std::string("_"));
+    test("grave-accent", std::string("`"));
+    for (char c = 'a'; c <= 'z'; ++c)
+    {
+        const char a[2] = {c};
+        test(a, std::string(a));
+    }
+    test("left-brace", std::string("{"));
+    test("left-curly-bracket", std::string("{"));
+    test("vertical-line", std::string("|"));
+    test("right-brace", std::string("}"));
+    test("right-curly-bracket", std::string("}"));
+    test("tilde", std::string("~"));
+
+    test("tild", std::string(""));
+    test("ch", std::string(""));
+    std::locale::global(std::locale("cs_CZ.ISO8859-2"));
+    test("ch", std::string("ch"));
+    std::locale::global(std::locale("C"));
+
+    test(L"NUL", std::wstring(L"\x00", 1));
+    test(L"alert", std::wstring(L"\x07"));
+    test(L"backspace", std::wstring(L"\x08"));
+    test(L"tab", std::wstring(L"\x09"));
+    test(L"carriage-return", std::wstring(L"\x0D"));
+    test(L"newline", std::wstring(L"\x0A"));
+    test(L"vertical-tab", std::wstring(L"\x0B"));
+    test(L"form-feed", std::wstring(L"\x0C"));
+    test(L"space", std::wstring(L" "));
+    test(L"exclamation-mark", std::wstring(L"!"));
+    test(L"quotation-mark", std::wstring(L"\""));
+    test(L"number-sign", std::wstring(L"#"));
+    test(L"dollar-sign", std::wstring(L"$"));
+    test(L"percent-sign", std::wstring(L"%"));
+    test(L"ampersand", std::wstring(L"&"));
+    test(L"apostrophe", std::wstring(L"\'"));
+    test(L"left-parenthesis", std::wstring(L"("));
+    test(L"right-parenthesis", std::wstring(L")"));
+    test(L"asterisk", std::wstring(L"*"));
+    test(L"plus-sign", std::wstring(L"+"));
+    test(L"comma", std::wstring(L","));
+    test(L"hyphen-minus", std::wstring(L"-"));
+    test(L"hyphen", std::wstring(L"-"));
+    test(L"full-stop", std::wstring(L"."));
+    test(L"period", std::wstring(L"."));
+    test(L"slash", std::wstring(L"/"));
+    test(L"solidus", std::wstring(L"/"));
+    test(L"zero", std::wstring(L"0"));
+    test(L"one", std::wstring(L"1"));
+    test(L"two", std::wstring(L"2"));
+    test(L"three", std::wstring(L"3"));
+    test(L"four", std::wstring(L"4"));
+    test(L"five", std::wstring(L"5"));
+    test(L"six", std::wstring(L"6"));
+    test(L"seven", std::wstring(L"7"));
+    test(L"eight", std::wstring(L"8"));
+    test(L"nine", std::wstring(L"9"));
+    test(L"colon", std::wstring(L":"));
+    test(L"semicolon", std::wstring(L";"));
+    test(L"less-than-sign", std::wstring(L"<"));
+    test(L"equals-sign", std::wstring(L"="));
+    test(L"greater-than-sign", std::wstring(L">"));
+    test(L"question-mark", std::wstring(L"?"));
+    test(L"commercial-at", std::wstring(L"@"));
+    for (wchar_t c = L'A'; c <= L'Z'; ++c)
+    {
+        const wchar_t a[2] = {c};
+        test(a, std::wstring(a));
+    }
+    test(L"left-square-bracket", std::wstring(L"["));
+    test(L"backslash", std::wstring(L"\\"));
+    test(L"reverse-solidus", std::wstring(L"\\"));
+    test(L"right-square-bracket", std::wstring(L"]"));
+    test(L"circumflex-accent", std::wstring(L"^"));
+    test(L"circumflex", std::wstring(L"^"));
+    test(L"low-line", std::wstring(L"_"));
+    test(L"underscore", std::wstring(L"_"));
+    test(L"grave-accent", std::wstring(L"`"));
+    for (wchar_t c = L'a'; c <= L'z'; ++c)
+    {
+        const wchar_t a[2] = {c};
+        test(a, std::wstring(a));
+    }
+    test(L"left-brace", std::wstring(L"{"));
+    test(L"left-curly-bracket", std::wstring(L"{"));
+    test(L"vertical-line", std::wstring(L"|"));
+    test(L"right-brace", std::wstring(L"}"));
+    test(L"right-curly-bracket", std::wstring(L"}"));
+    test(L"tilde", std::wstring(L"~"));
+
+    test(L"tild", std::wstring(L""));
+    test(L"ch", std::wstring(L""));
+    std::locale::global(std::locale("cs_CZ.ISO8859-2"));
+    test(L"ch", std::wstring(L"ch"));
+    std::locale::global(std::locale("C"));
+}

Added: libcxx/trunk/test/std/re/re.traits/transform.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/transform.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/transform.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/transform.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: locale.cs_CZ.ISO8859-2
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// template <class ForwardIterator>
+//   string_type transform(ForwardIterator first, ForwardIterator last) const;
+
+#include <regex>
+#include <cassert>
+#include "test_iterators.h"
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+        const char a[] = "a";
+        const char B[] = "B";
+        typedef forward_iterator<const char*> F;
+        assert(t.transform(F(a), F(a+1)) > t.transform(F(B), F(B+1)));
+        t.imbue(std::locale("cs_CZ.ISO8859-2"));
+        assert(t.transform(F(a), F(a+1)) < t.transform(F(B), F(B+1)));
+    }
+    {
+        std::regex_traits<wchar_t> t;
+        const wchar_t a[] = L"a";
+        const wchar_t B[] = L"B";
+        typedef forward_iterator<const wchar_t*> F;
+        assert(t.transform(F(a), F(a+1)) > t.transform(F(B), F(B+1)));
+        t.imbue(std::locale("cs_CZ.ISO8859-2"));
+        assert(t.transform(F(a), F(a+1)) < t.transform(F(B), F(B+1)));
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/transform_primary.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/transform_primary.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/transform_primary.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/transform_primary.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: locale.cs_CZ.ISO8859-2
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// template <class ForwardIterator>
+//   string_type
+//   transform_primary(ForwardIterator first, ForwardIterator last) const;
+
+#include <regex>
+#include <cassert>
+#include "test_iterators.h"
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+        const char A[] = "A";
+        const char Aacute[] = "\xC1";
+        typedef forward_iterator<const char*> F;
+        assert(t.transform_primary(F(A), F(A+1)) !=
+               t.transform_primary(F(Aacute), F(Aacute+1)));
+        t.imbue(std::locale("cs_CZ.ISO8859-2"));
+        assert(t.transform_primary(F(A), F(A+1)) ==
+               t.transform_primary(F(Aacute), F(Aacute+1)));
+    }
+    {
+        std::regex_traits<wchar_t> t;
+        const wchar_t A[] = L"A";
+        const wchar_t Aacute[] = L"\xC1";
+        typedef forward_iterator<const wchar_t*> F;
+        assert(t.transform_primary(F(A), F(A+1)) !=
+               t.transform_primary(F(Aacute), F(Aacute+1)));
+        t.imbue(std::locale("cs_CZ.ISO8859-2"));
+        assert(t.transform_primary(F(A), F(A+1)) ==
+               t.transform_primary(F(Aacute), F(Aacute+1)));
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/translate.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/translate.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/translate.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/translate.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// charT translate(charT c) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+        assert(t.translate('a') == 'a');
+        assert(t.translate('B') == 'B');
+        assert(t.translate('c') == 'c');
+    }
+    {
+        std::regex_traits<wchar_t> t;
+        assert(t.translate(L'a') == L'a');
+        assert(t.translate(L'B') == L'B');
+        assert(t.translate(L'c') == L'c');
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/translate_nocase.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/translate_nocase.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/translate_nocase.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/translate_nocase.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// charT translate_nocase(charT c) const;
+
+// REQUIRES: locale.en_US.UTF-8
+
+// XFAIL: with_system_lib=x86_64-apple-darwin11
+// XFAIL: with_system_lib=x86_64-apple-darwin12
+
+// TODO: investigation needed
+// XFAIL: linux-gnu
+
+#include <regex>
+#include <cassert>
+
+#include "platform_support.h"
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+        assert(t.translate_nocase(' ') == ' ');
+        assert(t.translate_nocase('A') == 'a');
+        assert(t.translate_nocase('\x07') == '\x07');
+        assert(t.translate_nocase('.') == '.');
+        assert(t.translate_nocase('a') == 'a');
+        assert(t.translate_nocase('1') == '1');
+        assert(t.translate_nocase('\xDA') == '\xDA');
+        assert(t.translate_nocase('\xFA') == '\xFA');
+        t.imbue(std::locale(LOCALE_en_US_UTF_8));
+        assert(t.translate_nocase(' ') == ' ');
+        assert(t.translate_nocase('A') == 'a');
+        assert(t.translate_nocase('\x07') == '\x07');
+        assert(t.translate_nocase('.') == '.');
+        assert(t.translate_nocase('a') == 'a');
+        assert(t.translate_nocase('1') == '1');
+        assert(t.translate_nocase('\xDA') == '\xFA');
+        assert(t.translate_nocase('\xFA') == '\xFA');
+    }
+    {
+        std::regex_traits<wchar_t> t;
+        assert(t.translate_nocase(L' ') == L' ');
+        assert(t.translate_nocase(L'A') == L'a');
+        assert(t.translate_nocase(L'\x07') == L'\x07');
+        assert(t.translate_nocase(L'.') == L'.');
+        assert(t.translate_nocase(L'a') == L'a');
+        assert(t.translate_nocase(L'1') == L'1');
+        assert(t.translate_nocase(L'\xDA') == L'\xDA');
+        assert(t.translate_nocase(L'\xFA') == L'\xFA');
+        t.imbue(std::locale(LOCALE_en_US_UTF_8));
+        assert(t.translate_nocase(L' ') == L' ');
+        assert(t.translate_nocase(L'A') == L'a');
+        assert(t.translate_nocase(L'\x07') == L'\x07');
+        assert(t.translate_nocase(L'.') == L'.');
+        assert(t.translate_nocase(L'a') == L'a');
+        assert(t.translate_nocase(L'1') == L'1');
+        assert(t.translate_nocase(L'\xDA') == L'\xFA');
+        assert(t.translate_nocase(L'\xFA') == L'\xFA');
+    }
+}

Added: libcxx/trunk/test/std/re/re.traits/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/types.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/types.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/types.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,32 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT>
+// struct regex_traits
+// {
+// public:
+//     typedef charT                   char_type;
+//     typedef basic_string<char_type> string_type;
+//     typedef locale                  locale_type;
+
+#include <regex>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::regex_traits<char>::char_type, char>::value), "");
+    static_assert((std::is_same<std::regex_traits<char>::string_type, std::string>::value), "");
+    static_assert((std::is_same<std::regex_traits<char>::locale_type, std::locale>::value), "");
+    static_assert((std::is_same<std::regex_traits<wchar_t>::char_type, wchar_t>::value), "");
+    static_assert((std::is_same<std::regex_traits<wchar_t>::string_type, std::wstring>::value), "");
+    static_assert((std::is_same<std::regex_traits<wchar_t>::locale_type, std::locale>::value), "");
+}

Added: libcxx/trunk/test/std/re/re.traits/value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.traits/value.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.traits/value.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.traits/value.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,125 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT> struct regex_traits;
+
+// int value(charT ch, int radix) const;
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+        std::regex_traits<char> t;
+
+        for (char c = 0; c < '0'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (char c = '0'; c < '8'; ++c)
+        {
+            assert(t.value(c, 8) == c - '0');
+            assert(t.value(c, 10) == c - '0');
+            assert(t.value(c, 16) == c - '0');
+        }
+        for (char c = '8'; c < ':'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == c - '0');
+            assert(t.value(c, 16) == c - '0');
+        }
+        for (char c = ':'; c < 'A'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (char c = 'A'; c < 'G'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == c - 'A' +10);
+        }
+        for (char c = 'G'; c < 'a'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (char c = 'a'; c < 'g'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == c - 'a' +10);
+        }
+        for (int c = 'g'; c < 256; ++c)
+        {
+            assert(t.value(char(c), 8) == -1);
+            assert(t.value(char(c), 10) == -1);
+            assert(t.value(char(c), 16) == -1);
+        }
+    }
+    {
+        std::regex_traits<wchar_t> t;
+
+        for (wchar_t c = 0; c < '0'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (wchar_t c = '0'; c < '8'; ++c)
+        {
+            assert(t.value(c, 8) == c - '0');
+            assert(t.value(c, 10) == c - '0');
+            assert(t.value(c, 16) == c - '0');
+        }
+        for (wchar_t c = '8'; c < ':'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == c - '0');
+            assert(t.value(c, 16) == c - '0');
+        }
+        for (wchar_t c = ':'; c < 'A'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (wchar_t c = 'A'; c < 'G'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == c - 'A' +10);
+        }
+        for (wchar_t c = 'G'; c < 'a'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+        for (wchar_t c = 'a'; c < 'g'; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == c - 'a' +10);
+        }
+        for (int c = 'g'; c < 0xFFFF; ++c)
+        {
+            assert(t.value(c, 8) == -1);
+            assert(t.value(c, 10) == -1);
+            assert(t.value(c, 16) == -1);
+        }
+    }
+}

Added: libcxx/trunk/test/std/strings/basic.string.hash/strings.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.hash/strings.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.hash/strings.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.hash/strings.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// template <class T>
+// struct hash
+//     : public unary_function<T, size_t>
+// {
+//     size_t operator()(T val) const;
+// };
+
+// Not very portable
+
+#include <string>
+#include <cassert>
+#include <type_traits>
+
+template <class T>
+void
+test()
+{
+    typedef std::hash<T> H;
+    static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
+                                   H>::value), "");
+    H h;
+    std::string g1 = "1234567890";
+    std::string g2 = "1234567891";
+    T s1(g1.begin(), g1.end());
+    T s2(g2.begin(), g2.end());
+    assert(h(s1) != h(s2));
+}
+
+int main()
+{
+    test<std::string>();
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    test<std::u16string>();
+    test<std::u32string>();
+#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
+    test<std::wstring>();
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    using namespace std::literals::string_literals;
+
+    static_assert ( std::is_same<decltype(   "Hi"s), std::string>::value, "" );
+    static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
+    static_assert ( std::is_same<decltype(  L"Hi"s), std::wstring>::value, "" );
+    static_assert ( std::is_same<decltype(  u"Hi"s), std::u16string>::value, "" );
+    static_assert ( std::is_same<decltype(  U"Hi"s), std::u32string>::value, "" );
+    
+    std::string foo;
+    std::wstring Lfoo;
+    std::u16string ufoo;
+    std::u32string Ufoo;
+    
+    foo  =   ""s;     assert( foo.size() == 0);
+    foo  = u8""s;     assert( foo.size() == 0);
+    Lfoo =  L""s;     assert(Lfoo.size() == 0);
+    ufoo =  u""s;     assert(ufoo.size() == 0);
+    Ufoo =  U""s;     assert(Ufoo.size() == 0);
+    
+    foo  =   " "s;     assert( foo.size() == 1);
+    foo  = u8" "s;     assert( foo.size() == 1);
+    Lfoo =  L" "s;     assert(Lfoo.size() == 1);
+    ufoo =  u" "s;     assert(ufoo.size() == 1);
+    Ufoo =  U" "s;     assert(Ufoo.size() == 1);
+    
+    foo  =   "ABC"s;     assert( foo ==   "ABC");   assert( foo == std::string   (  "ABC"));
+    foo  = u8"ABC"s;     assert( foo == u8"ABC");   assert( foo == std::string   (u8"ABC"));
+    Lfoo =  L"ABC"s;     assert(Lfoo ==  L"ABC");   assert(Lfoo == std::wstring  ( L"ABC"));
+    ufoo =  u"ABC"s;     assert(ufoo ==  u"ABC");   assert(ufoo == std::u16string( u"ABC"));
+    Ufoo =  U"ABC"s;     assert(Ufoo ==  U"ABC");   assert(Ufoo == std::u32string( U"ABC"));
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal1.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal1.fail.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal1.fail.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal1.fail.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,22 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    using std::string;
+
+    string foo  =   ""s;  // should fail w/conversion operator not found
+#else
+#error
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal1.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal1.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal1.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    using namespace std::literals;
+
+    std::string foo  =   ""s;
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal2.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal2.fail.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal2.fail.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal2.fail.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    std::string foo  =   ""s;  // should fail w/conversion operator not found
+#else
+#error
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal2.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal2.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal2.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    using namespace std::literals::string_literals;
+
+    std::string foo  =   ""s;
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string.literals/literal3.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string.literals/literal3.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string.literals/literal3.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string.literals/literal3.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,20 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11 
+    using namespace std;
+
+    string foo  =   ""s;
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/input_iterator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/input_iterator.h?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/input_iterator.h (added)
+++ libcxx/trunk/test/std/strings/basic.string/input_iterator.h Fri Dec 19 19:40:03 2014
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef INPUT_ITERATOR_H
+#define INPUT_ITERATOR_H
+
+#include <iterator>
+
+template <class It>
+class input_iterator
+{
+    It it_;
+public:
+    typedef typename std::input_iterator_tag                   iterator_category;
+    typedef typename std::iterator_traits<It>::value_type      value_type;
+    typedef typename std::iterator_traits<It>::difference_type difference_type;
+    typedef It                                                 pointer;
+    typedef typename std::iterator_traits<It>::reference       reference;
+
+    input_iterator() : it_() {}
+    explicit input_iterator(It it) : it_(it) {}
+
+    reference operator*() const {return *it_;}
+    pointer operator->() const {return it_;}
+
+    input_iterator& operator++() {++it_; return *this;}
+    input_iterator operator++(int) {input_iterator tmp(*this); ++(*this); return tmp;}
+
+    friend bool operator==(const input_iterator& x, const input_iterator& y)
+        {return x.it_ == y.it_;}
+    friend bool operator!=(const input_iterator& x, const input_iterator& y)
+        {return !(x == y);}
+};
+
+#endif  // INPUT_ITERATOR_H

Added: libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/at.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_reference at(size_type pos) const;
+//       reference at(size_type pos);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos)
+{
+    try
+    {
+        const S& cs = s;
+        assert(s.at(pos) == s[pos]);
+        assert(cs.at(pos) == cs[pos]);
+        assert(pos < cs.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos >= s.size());
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(), 0);
+    test(S("123"), 0);
+    test(S("123"), 1);
+    test(S("123"), 2);
+    test(S("123"), 3);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(), 0);
+    test(S("123"), 0);
+    test(S("123"), 1);
+    test(S("123"), 2);
+    test(S("123"), 3);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/back.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const charT& back() const;
+//       charT& back();
+
+#ifdef _LIBCPP_DEBUG
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    assert(&cs.back() == &cs[cs.size()-1]);
+    assert(&s.back() == &s[cs.size()-1]);
+    s.back() = typename S::value_type('z');
+    assert(s.back() == typename S::value_type('z'));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S("1"));
+    test(S("1234567890123456789012345678901234567890"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S("1"));
+    test(S("1234567890123456789012345678901234567890"));
+    }
+#endif
+#ifdef _LIBCPP_DEBUG
+    {
+        std::string s;
+        char c = s.back();
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_back.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_back.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_back.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// Call back() on empty container.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s(1, '\0');
+    assert(s.back() == 0);
+    s.clear();
+    assert(s.back() == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s(1, '\0');
+    assert(s.back() == 0);
+    s.clear();
+    assert(s.back() == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_cback.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_cback.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_cback.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_cback.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call back() on empty const container.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    const S s;
+    assert(s.back() == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    const S s;
+    assert(s.back() == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_cfront.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_cfront.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_cfront.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_cfront.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call front() on empty const container.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    const S s;
+    assert(s.front() == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    const S s;
+    assert(s.front() == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_cindex.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_cindex.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_cindex.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_cindex.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Index const string out of bounds.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    const S s;
+    assert(s[0] == 0);
+    assert(s[1] == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    const S s;
+    assert(s[0] == 0);
+    assert(s[1] == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_front.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_front.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_front.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_front.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// Call front() on empty container.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s(1, '\0');
+    assert(s.front() == 0);
+    s.clear();
+    assert(s.front() == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s(1, '\0');
+    assert(s.front() == 0);
+    s.clear();
+    assert(s.front() == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/db_index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/db_index.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/db_index.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/db_index.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Index string out of bounds.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s;
+    assert(s[0] == 0);
+    assert(s[1] == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s;
+    assert(s[0] == 0);
+    assert(s[1] == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/front.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const charT& front() const;
+//       charT& front();
+
+#ifdef _LIBCPP_DEBUG
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    assert(&cs.front() == &cs[0]);
+    assert(&s.front() == &s[0]);
+    s.front() = typename S::value_type('z');
+    assert(s.front() == typename S::value_type('z'));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S("1"));
+    test(S("1234567890123456789012345678901234567890"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S("1"));
+    test(S("1234567890123456789012345678901234567890"));
+    }
+#endif
+#ifdef _LIBCPP_DEBUG
+    {
+        std::string s;
+        char c = s.front();
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_reference operator[](size_type pos) const;
+//       reference operator[](size_type pos);
+
+#ifdef _LIBCPP_DEBUG
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s("0123456789");
+    const S& cs = s;
+    for (S::size_type i = 0; i < cs.size(); ++i)
+    {
+        assert(s[i] == '0' + i);
+        assert(cs[i] == s[i]);
+    }
+    assert(cs[cs.size()] == '\0');
+    const S s2 = S();
+    assert(s2[0] == '\0');
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s("0123456789");
+    const S& cs = s;
+    for (S::size_type i = 0; i < cs.size(); ++i)
+    {
+        assert(s[i] == '0' + i);
+        assert(cs[i] == s[i]);
+    }
+    assert(cs[cs.size()] == '\0');
+    const S s2 = S();
+    assert(s2[0] == '\0');
+    }
+#endif
+#ifdef _LIBCPP_DEBUG
+    {
+        std::string s;
+        char c = s[0];
+        assert(c == '\0');
+        c = s[1];
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type capacity() const;
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s;
+    assert(s.capacity() > 0);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/clear.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/clear.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/clear.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/clear.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void clear();
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_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);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/empty.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/empty.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/empty.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/empty.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// bool empty() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/length.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/length.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/length.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/length.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type length() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/max_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/max_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/max_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/max_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type max_size() const;
+
+// NOTE: asan and msan will fail for one of two reasons
+// 1. If allocator_may_return_null=0 then they will fail because the allocation
+//    returns null.
+// 2. If allocator_may_return_null=1 then they will fail because the allocation
+//    is too large to succeed.
+// UNSUPPORTED: asan, msan
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test1(const S& s)
+{
+    S s2(s);
+    const size_t sz = s2.max_size() - 1;
+    try { s2.resize(sz, 'x'); }
+    catch ( const std::bad_alloc & ) { return ; }
+    assert ( s2.size() ==  sz );
+}
+
+template <class S>
+void
+test2(const S& s)
+{
+    S s2(s);
+    const size_t sz = s2.max_size();
+    try { s2.resize(sz, 'x'); }
+    catch ( const std::bad_alloc & ) { return ; }
+    assert ( s.size() ==  sz );
+}
+
+template <class S>
+void
+test(const S& s)
+{
+    assert(s.max_size() >= s.size());
+    test1(s);
+    test2(s);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type max_size() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(const S& s)
+{
+    assert(s.max_size() >= s.size());
+    S s2(s);
+    const size_t sz = s2.max_size() + 1;
+    try { s2.resize(sz, 'x'); }
+    catch ( const std::length_error & ) { return ; }
+    assert ( false );
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/reserve.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,117 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void reserve(size_type res_arg=0);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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);
+    }
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_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);
+    }
+    {
+    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);
+    }
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void resize(size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> 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"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void resize(size_type n, charT c);
+
+#include <string>
+#include <stdexcept>
+#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)
+{
+    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"));
+    }
+#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("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"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void shrink_to_fit();
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_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);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.capacity/size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type size() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(), 0);
+    test(S("123"), 3);
+    test(S("12345678901234567890123456789012345678901234567890"), 50);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// explicit basic_string(const Allocator& a = Allocator());
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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));
+    }
+}
+
+#if __cplusplus >= 201103L
+
+template <class S>
+void
+test2()
+{
+    {
+    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{});
+    assert(s.__invariants());
+    assert(s.data());
+    assert(s.size() == 0);
+    assert(s.capacity() >= s.size());
+    assert(s.get_allocator() == typename S::allocator_type());
+    }
+}
+
+#endif
+
+int main()
+{
+    test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
+#if __cplusplus >= 201103L
+    test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/char_assignment.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>& operator=(charT c);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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');
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(), 'a');
+    test(S("1"), 'a');
+    test(S("123456789"), 'a');
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/copy.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/copy.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/copy.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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)));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(A{}));
+    test(S("1", A()));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(const basic_string& str, const Allocator& alloc);
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(), A());
+    test(S("1"), A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   operator=(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> 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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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()
+//        noexcept(is_nothrow_default_constructible<allocator_type>::value);
+
+// This tests a conforming extension
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+};
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::string C;
+        static_assert(std::is_nothrow_default_constructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
+        static_assert(std::is_nothrow_default_constructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+        static_assert(!std::is_nothrow_default_constructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/dtor_noexcept.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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() // implied noexcept;
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+
+#if __has_feature(cxx_noexcept)
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+    ~some_alloc() noexcept(false);
+};
+
+#endif
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::string C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
+        static_assert(std::is_nothrow_destructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+        static_assert(!std::is_nothrow_destructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+    {
+        std::string s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+    {
+        std::wstring s;
+        s = {L'a', L'b', L'c'};
+        assert(s == L"abc");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+    {
+        typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
+        S s;
+        s = {L'a', L'b', L'c'};
+        assert(s == L"abc");
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& operator=(initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+    {
+        std::string s;
+        s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s;
+        s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/iter_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,119 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(InputIterator begin, InputIterator end,
+//   const Allocator& a = Allocator());
+
+#include <string>
+#include <iterator>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "../input_iterator.h"
+#include "min_allocator.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, class A>
+void
+test(It first, It last, const A& a)
+{
+    typedef typename std::iterator_traits<It>::value_type charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, A> S;
+    typedef typename S::traits_type T;
+    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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    const char* s = "12345678901234567890123456789012345678901234567890";
+
+    test(s, s);
+    test(s, s, A());
+
+    test(s, s+1);
+    test(s, s+1, A());
+
+    test(s, s+10);
+    test(s, s+10, A());
+
+    test(s, s+50);
+    test(s, s+50, A());
+
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s));
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s), A());
+
+    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());
+
+    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());
+
+    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());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(basic_string<charT,traits,Allocator>&& str);
+
+#include <string>
+#include <cassert>
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#include "test_allocator.h"
+#include "min_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  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    {
+    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)));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(A{}));
+    test(S("1", A()));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(basic_string&& str, const Allocator& alloc);
+
+#include <string>
+#include <cassert>
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#include "test_allocator.h"
+#include "min_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  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    {
+    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));
+    }
+
+    int alloc_count = test_alloc_base::alloc_count;
+    {
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
+    S s2 (std::move(s1), A(1));
+    }
+    assert ( test_alloc_base::alloc_count == alloc_count );
+    
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(), A());
+    test(S("1"), A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_assign_noexcept.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& operator=(basic_string&& c)
+//     noexcept(
+//          allocator_type::propagate_on_container_move_assignment::value &&
+//          is_nothrow_move_assignable<allocator_type>::value);
+
+// This tests a conforming extension
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+};
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::string C;
+        static_assert(std::is_nothrow_move_assignable<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
+        static_assert(!std::is_nothrow_move_assignable<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+        static_assert(!std::is_nothrow_move_assignable<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_assignment.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   operator=(basic_string<charT,traits,Allocator>&& str);
+
+#include <string>
+#include <cassert>
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+#include "test_allocator.h"
+#include "min_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  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+    {
+    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"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> 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
+#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(basic_string&&)
+//        noexcept(is_nothrow_move_constructible<allocator_type>::value);
+
+// This tests a conforming extension
+
+#include <string>
+#include <cassert>
+
+#include "test_allocator.h"
+
+template <class T>
+struct some_alloc
+{
+    typedef T value_type;
+    some_alloc(const some_alloc&);
+};
+
+int main()
+{
+#if __has_feature(cxx_noexcept)
+    {
+        typedef std::string C;
+        static_assert(std::is_nothrow_move_constructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
+        static_assert(std::is_nothrow_move_constructible<C>::value, "");
+    }
+    {
+        typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+        static_assert(!std::is_nothrow_move_constructible<C>::value, "");
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(const charT* s, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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, class A>
+void
+test(const charT* s, const A& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, A> S;
+    typedef typename S::traits_type T;
+    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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test("");
+    test("", A());
+
+    test("1");
+    test("1", A());
+
+    test("1234567980");
+    test("1234567980", A());
+
+    test("123456798012345679801234567980123456798012345679801234567980");
+    test("123456798012345679801234567980123456798012345679801234567980", A());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   operator=(const charT* s);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+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");
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> 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");
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(const charT* s, size_type n, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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, class A>
+void
+test(const charT* s, unsigned n, const A& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, A> S;
+    typedef typename S::traits_type T;
+    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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test("", 0);
+    test("", 0, A());
+
+    test("1", 1);
+    test("1", 1, A());
+
+    test("1234567980", 10);
+    test("1234567980", 10, A());
+
+    test("123456798012345679801234567980123456798012345679801234567980", 60);
+    test("123456798012345679801234567980123456798012345679801234567980", 60, A());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,128 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(size_type n, charT c, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "test_allocator.h"
+#include "min_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, class A>
+void
+test(unsigned n, charT c, const A& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, A> S;
+    typedef typename S::traits_type T;
+    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, class A>
+void
+test(Tp n, Tp c, const A& a)
+{
+    typedef char charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, A> S;
+    typedef typename S::traits_type T;
+    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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test(0, 'a');
+    test(0, 'a', A());
+
+    test(1, 'a');
+    test(1, 'a', A());
+
+    test(10, 'a');
+    test(10, 'a', A());
+
+    test(100, 'a');
+    test(100, 'a', A());
+
+    test(100, 65);
+    test(100, 65, A());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/substr.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,173 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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(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"
+#include "min_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<unsigned>(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<unsigned>(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));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef min_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test(S(A()), 0);
+    test(S(A()), 1);
+    test(S("1", A()), 0);
+    test(S("1", A()), 1);
+    test(S("1", A()), 2);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 0);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 5);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 500);
+
+    test(S(A()), 0, 0);
+    test(S(A()), 0, 1);
+    test(S(A()), 1, 0);
+    test(S(A()), 1, 1);
+    test(S(A()), 1, 2);
+    test(S("1", A()), 0, 0);
+    test(S("1", A()), 0, 1);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100);
+
+    test(S(A()), 0, 0, A());
+    test(S(A()), 0, 1, A());
+    test(S(A()), 1, 0, A());
+    test(S(A()), 1, 1, A());
+    test(S(A()), 1, 2, A());
+    test(S("1", A()), 0, 0, A());
+    test(S("1", A()), 0, 1, A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0, A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1, A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A());
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/begin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/begin.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/begin.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/begin.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+//       iterator begin();
+// const_iterator begin() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    typename S::iterator b = s.begin();
+    typename S::const_iterator cb = cs.begin();
+    if (!s.empty())
+    {
+        assert(*b == s[0]);
+    }
+    assert(b == cb);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/cbegin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/cbegin.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/cbegin.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/cbegin.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_iterator cbegin() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(const S& s)
+{
+    typename S::const_iterator cb = s.cbegin();
+    if (!s.empty())
+    {
+        assert(*cb == s[0]);
+    }
+    assert(cb == s.begin());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/cend.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/cend.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/cend.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/cend.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_iterator cend() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(const S& s)
+{
+    typename S::const_iterator ce = s.cend();
+    assert(ce == s.end());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/crbegin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/crbegin.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/crbegin.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/crbegin.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_reverse_iterator crbegin() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(const S& s)
+{
+    typename S::const_reverse_iterator cb = s.crbegin();
+    if (!s.empty())
+    {
+        assert(*cb == s.back());
+    }
+    assert(cb == s.rbegin());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/crend.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/crend.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/crend.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/crend.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// const_reverse_iterator crend() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(const S& s)
+{
+    typename S::const_reverse_iterator ce = s.crend();
+    assert(ce == s.rend());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_2.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_2.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_2.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Compare iterators from different containers with <.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s1;
+    S s2;
+    bool b = s1.begin() < s2.begin();
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s1;
+    S s2;
+    bool b = s1.begin() < s2.begin();
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_3.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_3.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_3.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_3.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Subtract iterators from different containers with <.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s1;
+    S s2;
+    int i = s1.begin() - s2.begin();
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s1;
+    S s2;
+    int i = s1.begin() - s2.begin();
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_4.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_4.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_4.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_4.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// Index iterator out of bounds.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    assert(i[0] == 0);
+    assert(i[1] == 0);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    assert(i[0] == 0);
+    assert(i[1] == 0);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_5.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_5.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_5.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_5.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Add to iterator out of bounds.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    i += 1;
+    assert(i == c.end());
+    i = c.begin();
+    i += 2;
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    i += 1;
+    assert(i == c.end());
+    i = c.begin();
+    i += 2;
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_6.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_6.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_6.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_6.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Decrement iterator prior to begin.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string C;
+    C c(1, '\0');
+    C::iterator i = c.end();
+    --i;
+    assert(i == c.begin());
+    --i;
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> C;
+    C c(1, '\0');
+    C::iterator i = c.end();
+    --i;
+    assert(i == c.begin());
+    --i;
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_7.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_7.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_7.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_7.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Increment iterator past end.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    ++i;
+    assert(i == c.end());
+    ++i;
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> C;
+    C c(1, '\0');
+    C::iterator i = c.begin();
+    ++i;
+    assert(i == c.end());
+    ++i;
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_8.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_8.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_8.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/db_iterators_8.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Dereference non-dereferenceable iterator.
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <iterator>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    typedef std::string C;
+    C c(1, '\0');
+    C::iterator i = c.end();
+    char j = *i;
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> C;
+    C c(1, '\0');
+    C::iterator i = c.end();
+    char j = *i;
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/end.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/end.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/end.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/end.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+//       iterator end();
+// const_iterator end() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    typename S::iterator e = s.end();
+    typename S::const_iterator ce = cs.end();
+    if (s.empty())
+    {
+        assert(e == s.begin());
+        assert(ce == cs.begin());
+    }
+    assert(e - s.begin() == s.size());
+    assert(ce - cs.begin() == cs.size());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/iterators.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/iterators.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/iterators.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/iterators.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// iterator       begin();
+// iterator       end();
+// const_iterator begin()  const;
+// const_iterator end()    const;
+// const_iterator cbegin() const;
+// const_iterator cend()   const;
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+    { // N3644 testing
+        typedef std::string C;
+        C::iterator ii1{}, ii2{};
+        C::iterator ii4 = ii1;
+        C::const_iterator cii{};
+        assert ( ii1 == ii2 );
+        assert ( ii1 == ii4 );
+        assert ( ii1 == cii );
+        assert ( !(ii1 != ii2 ));
+        assert ( !(ii1 != cii ));
+    }
+
+    { // N3644 testing
+        typedef std::wstring C;
+        C::iterator ii1{}, ii2{};
+        C::iterator ii4 = ii1;
+        C::const_iterator cii{};
+        assert ( ii1 == ii2 );
+        assert ( ii1 == ii4 );        
+        assert ( ii1 == cii );
+        assert ( !(ii1 != ii2 ));
+        assert ( !(ii1 != cii ));
+    }
+
+    { // N3644 testing
+        typedef std::u16string C;
+        C::iterator ii1{}, ii2{};
+        C::iterator ii4 = ii1;
+        C::const_iterator cii{};
+        assert ( ii1 == ii2 );
+        assert ( ii1 == ii4 );
+        assert ( ii1 == cii );
+        assert ( !(ii1 != ii2 ));
+        assert ( !(ii1 != cii ));
+    }
+
+    { // N3644 testing
+        typedef std::u32string C;
+        C::iterator ii1{}, ii2{};
+        C::iterator ii4 = ii1;
+        C::const_iterator cii{};
+        assert ( ii1 == ii2 );
+        assert ( ii1 == ii4 );
+        assert ( ii1 == cii );
+        assert ( !(ii1 != ii2 ));
+        assert ( !(ii1 != cii ));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/rbegin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/rbegin.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/rbegin.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/rbegin.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+//       reverse_iterator rbegin();
+// const_reverse_iterator rbegin() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    typename S::reverse_iterator b = s.rbegin();
+    typename S::const_reverse_iterator cb = cs.rbegin();
+    if (!s.empty())
+    {
+        assert(*b == s.back());
+    }
+    assert(b == cb);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.iterators/rend.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.iterators/rend.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.iterators/rend.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.iterators/rend.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+//       reverse_iterator rend();
+// const_reverse_iterator rend() const;
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    const S& cs = s;
+    typename S::reverse_iterator e = s.rend();
+    typename S::const_reverse_iterator ce = cs.rend();
+    if (s.empty())
+    {
+        assert(e == s.rbegin());
+        assert(ce == cs.rbegin());
+    }
+    assert(e - s.rbegin() == s.size());
+    assert(ce - cs.rbegin() == cs.size());
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S());
+    test(S("123"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& append(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.append({'a', 'b', 'c'});
+        assert(s == "123abc");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s("123");
+        s.append({'a', 'b', 'c'});
+        assert(s == "123abc");
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& append(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.append(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("12345"));
+    test(S("12345"), s, s+1, S("12345A"));
+    test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
+    test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), s, s, S("1234567890"));
+    test(S("1234567890"), s, s+1, S("1234567890A"));
+    test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), s, s, S("12345678901234567890"));
+    test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
+    test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
+    test(S("12345678901234567890"), s, s+52,
+         S("12345678901234567890""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("12345"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("12345A"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("12345ABCDEFGHIJ"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S("1234567890"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("1234567890A"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S("12345678901234567890"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("12345678901234567890""A"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("12345678901234567890""ABCDEFGHIJ"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345678901234567890""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("12345"));
+    test(S("12345"), s, s+1, S("12345A"));
+    test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
+    test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), s, s, S("1234567890"));
+    test(S("1234567890"), s, s+1, S("1234567890A"));
+    test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), s, s, S("12345678901234567890"));
+    test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
+    test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
+    test(S("12345678901234567890"), s, s+52,
+         S("12345678901234567890""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("12345"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("12345A"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("12345ABCDEFGHIJ"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S("1234567890"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("1234567890A"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S("12345678901234567890"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("12345678901234567890""A"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("12345678901234567890""ABCDEFGHIJ"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>& append(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.append(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("12345"));
+    test(S("12345"), "12345", S("1234512345"));
+    test(S("12345"), "1234567890", S("123451234567890"));
+
+    test(S("12345678901234567890"), "", S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "12345678901234567890",
+         S("1234567890123456789012345678901234567890"));
+    }
+#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("12345"));
+    test(S("12345"), "12345", S("1234512345"));
+    test(S("12345"), "1234567890", S("123451234567890"));
+
+    test(S("12345678901234567890"), "", S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "12345678901234567890",
+         S("1234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   append(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.append(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("12345"));
+    test(S("12345"), "12345", 5, S("1234512345"));
+    test(S("12345"), "1234567890", 10, S("123451234567890"));
+
+    test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "12345678901234567890", 20,
+         S("1234567890123456789012345678901234567890"));
+    }
+#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("12345"));
+    test(S("12345"), "12345", 5, S("1234512345"));
+    test(S("12345"), "1234567890", 10, S("123451234567890"));
+
+    test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "12345678901234567890", 20,
+         S("1234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void push_back(charT c)
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::value_type c, S expected)
+{
+    s.push_back(c);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(), 'a', S(1, 'a'));
+    test(S("12345"), 'a', S("12345a"));
+    test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(), 'a', S(1, 'a'));
+    test(S("12345"), 'a', S("12345a"));
+    test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   append(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.append(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("12345"));
+    test(S("12345"), 1, 'a', S("12345a"));
+    test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
+
+    test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
+    test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
+    test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
+    }
+#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("12345"));
+    test(S("12345"), 1, 'a', S("12345a"));
+    test(S("12345"), 10, 'a', S("12345aaaaaaaaaa"));
+
+    test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
+    test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
+    test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   append(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.append(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("12345"));
+    test(S("12345"), S("12345"), S("1234512345"));
+    test(S("12345"), S("1234567890"), S("123451234567890"));
+    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+    test(S("1234567890"), S(), S("1234567890"));
+    test(S("1234567890"), S("12345"), S("123456789012345"));
+    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("1234567890123456789012345678901234567890"));
+    }
+#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("12345"));
+    test(S("12345"), S("12345"), S("1234512345"));
+    test(S("12345"), S("1234567890"), S("123451234567890"));
+    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+    test(S("1234567890"), S(), S("1234567890"));
+    test(S("1234567890"), S("12345"), S("123456789012345"));
+    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("1234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,118 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   append(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.append(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.append(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("12345"));
+    test(S("12345"), S("12345"), 2, 2, S("1234534"));
+    test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
+
+    test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
+    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
+         S("123456789012345678906789012345"));
+    }
+#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("12345"));
+    test(S("12345"), S("12345"), 2, 2, S("1234534"));
+    test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
+
+    test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
+    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
+         S("123456789012345678906789012345"));
+    }
+#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"));
+    }
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/rv_string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,118 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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"));
+    }
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,170 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// size_type copy(charT* s, size_type n, size_type pos = 0) const;
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S str, typename S::value_type* s, typename S::size_type n,
+     typename S::size_type pos)
+{
+    try
+    {
+        const S& cs = str;
+        typename S::size_type r = cs.copy(s, n, pos);
+        assert(pos <= cs.size());
+        typename S::size_type rlen = std::min(n, cs.size() - pos);
+        assert(r == rlen);
+        for (r = 0; r < rlen; ++r)
+            assert(S::traits_type::eq(cs[pos+r], s[r]));
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    char s[50];
+    test(S(""), s, 0, 0);
+    test(S(""), s, 0, 1);
+    test(S(""), s, 1, 0);
+    test(S("abcde"), s, 0, 0);
+    test(S("abcde"), s, 0, 1);
+    test(S("abcde"), s, 0, 2);
+    test(S("abcde"), s, 0, 4);
+    test(S("abcde"), s, 0, 5);
+    test(S("abcde"), s, 0, 6);
+    test(S("abcde"), s, 1, 0);
+    test(S("abcde"), s, 1, 1);
+    test(S("abcde"), s, 1, 2);
+    test(S("abcde"), s, 1, 4);
+    test(S("abcde"), s, 1, 5);
+    test(S("abcde"), s, 2, 0);
+    test(S("abcde"), s, 2, 1);
+    test(S("abcde"), s, 2, 2);
+    test(S("abcde"), s, 2, 4);
+    test(S("abcde"), s, 4, 0);
+    test(S("abcde"), s, 4, 1);
+    test(S("abcde"), s, 4, 2);
+    test(S("abcde"), s, 5, 0);
+    test(S("abcde"), s, 5, 1);
+    test(S("abcde"), s, 6, 0);
+    test(S("abcdefghijklmnopqrst"), s, 0, 0);
+    test(S("abcdefghijklmnopqrst"), s, 0, 1);
+    test(S("abcdefghijklmnopqrst"), s, 0, 2);
+    test(S("abcdefghijklmnopqrst"), s, 0, 10);
+    test(S("abcdefghijklmnopqrst"), s, 0, 19);
+    test(S("abcdefghijklmnopqrst"), s, 0, 20);
+    test(S("abcdefghijklmnopqrst"), s, 0, 21);
+    test(S("abcdefghijklmnopqrst"), s, 1, 0);
+    test(S("abcdefghijklmnopqrst"), s, 1, 1);
+    test(S("abcdefghijklmnopqrst"), s, 1, 2);
+    test(S("abcdefghijklmnopqrst"), s, 1, 9);
+    test(S("abcdefghijklmnopqrst"), s, 1, 18);
+    test(S("abcdefghijklmnopqrst"), s, 1, 19);
+    test(S("abcdefghijklmnopqrst"), s, 1, 20);
+    test(S("abcdefghijklmnopqrst"), s, 2, 0);
+    test(S("abcdefghijklmnopqrst"), s, 2, 1);
+    test(S("abcdefghijklmnopqrst"), s, 2, 2);
+    test(S("abcdefghijklmnopqrst"), s, 2, 9);
+    test(S("abcdefghijklmnopqrst"), s, 2, 17);
+    test(S("abcdefghijklmnopqrst"), s, 2, 18);
+    test(S("abcdefghijklmnopqrst"), s, 2, 19);
+    test(S("abcdefghijklmnopqrst"), s, 10, 0);
+    test(S("abcdefghijklmnopqrst"), s, 10, 1);
+    test(S("abcdefghijklmnopqrst"), s, 10, 2);
+    test(S("abcdefghijklmnopqrst"), s, 10, 5);
+    test(S("abcdefghijklmnopqrst"), s, 10, 9);
+    test(S("abcdefghijklmnopqrst"), s, 10, 10);
+    test(S("abcdefghijklmnopqrst"), s, 10, 11);
+    test(S("abcdefghijklmnopqrst"), s, 19, 0);
+    test(S("abcdefghijklmnopqrst"), s, 19, 1);
+    test(S("abcdefghijklmnopqrst"), s, 19, 2);
+    test(S("abcdefghijklmnopqrst"), s, 20, 0);
+    test(S("abcdefghijklmnopqrst"), s, 20, 1);
+    test(S("abcdefghijklmnopqrst"), s, 21, 0);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    char s[50];
+    test(S(""), s, 0, 0);
+    test(S(""), s, 0, 1);
+    test(S(""), s, 1, 0);
+    test(S("abcde"), s, 0, 0);
+    test(S("abcde"), s, 0, 1);
+    test(S("abcde"), s, 0, 2);
+    test(S("abcde"), s, 0, 4);
+    test(S("abcde"), s, 0, 5);
+    test(S("abcde"), s, 0, 6);
+    test(S("abcde"), s, 1, 0);
+    test(S("abcde"), s, 1, 1);
+    test(S("abcde"), s, 1, 2);
+    test(S("abcde"), s, 1, 4);
+    test(S("abcde"), s, 1, 5);
+    test(S("abcde"), s, 2, 0);
+    test(S("abcde"), s, 2, 1);
+    test(S("abcde"), s, 2, 2);
+    test(S("abcde"), s, 2, 4);
+    test(S("abcde"), s, 4, 0);
+    test(S("abcde"), s, 4, 1);
+    test(S("abcde"), s, 4, 2);
+    test(S("abcde"), s, 5, 0);
+    test(S("abcde"), s, 5, 1);
+    test(S("abcde"), s, 6, 0);
+    test(S("abcdefghijklmnopqrst"), s, 0, 0);
+    test(S("abcdefghijklmnopqrst"), s, 0, 1);
+    test(S("abcdefghijklmnopqrst"), s, 0, 2);
+    test(S("abcdefghijklmnopqrst"), s, 0, 10);
+    test(S("abcdefghijklmnopqrst"), s, 0, 19);
+    test(S("abcdefghijklmnopqrst"), s, 0, 20);
+    test(S("abcdefghijklmnopqrst"), s, 0, 21);
+    test(S("abcdefghijklmnopqrst"), s, 1, 0);
+    test(S("abcdefghijklmnopqrst"), s, 1, 1);
+    test(S("abcdefghijklmnopqrst"), s, 1, 2);
+    test(S("abcdefghijklmnopqrst"), s, 1, 9);
+    test(S("abcdefghijklmnopqrst"), s, 1, 18);
+    test(S("abcdefghijklmnopqrst"), s, 1, 19);
+    test(S("abcdefghijklmnopqrst"), s, 1, 20);
+    test(S("abcdefghijklmnopqrst"), s, 2, 0);
+    test(S("abcdefghijklmnopqrst"), s, 2, 1);
+    test(S("abcdefghijklmnopqrst"), s, 2, 2);
+    test(S("abcdefghijklmnopqrst"), s, 2, 9);
+    test(S("abcdefghijklmnopqrst"), s, 2, 17);
+    test(S("abcdefghijklmnopqrst"), s, 2, 18);
+    test(S("abcdefghijklmnopqrst"), s, 2, 19);
+    test(S("abcdefghijklmnopqrst"), s, 10, 0);
+    test(S("abcdefghijklmnopqrst"), s, 10, 1);
+    test(S("abcdefghijklmnopqrst"), s, 10, 2);
+    test(S("abcdefghijklmnopqrst"), s, 10, 5);
+    test(S("abcdefghijklmnopqrst"), s, 10, 9);
+    test(S("abcdefghijklmnopqrst"), s, 10, 10);
+    test(S("abcdefghijklmnopqrst"), s, 10, 11);
+    test(S("abcdefghijklmnopqrst"), s, 19, 0);
+    test(S("abcdefghijklmnopqrst"), s, 19, 1);
+    test(S("abcdefghijklmnopqrst"), s, 19, 2);
+    test(S("abcdefghijklmnopqrst"), s, 20, 0);
+    test(S("abcdefghijklmnopqrst"), s, 20, 1);
+    test(S("abcdefghijklmnopqrst"), s, 21, 0);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db1.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db1.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db1.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator position) with end()
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <cstdlib>
+#include <exception>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string::const_iterator i = l1.end();
+    l1.erase(i);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S::const_iterator i = l1.end();
+    l1.erase(i);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db2.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db2.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_db2.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator position) with iterator from another container
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <cstdlib>
+#include <exception>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string l2("123");
+    std::string::const_iterator i = l2.begin();
+    l1.erase(i);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S l2("123");
+    S::const_iterator i = l2.begin();
+    l1.erase(i);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db1.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db1.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db1.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db1.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator first, const_iterator last); with first iterator from another container
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string l2("123");
+    std::string::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S l2("123");
+    S::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db2.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db2.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db2.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db2.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator first, const_iterator last); with second iterator from another container
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string l2("123");
+    std::string::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S l2("123");
+    S::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db3.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db3.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db3.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db3.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator first, const_iterator last); with both iterators from another container
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string l2("123");
+    std::string::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1);
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S l2("123");
+    S::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1);
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db4.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db4.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db4.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/erase_iter_iter_db4.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// Call erase(const_iterator first, const_iterator last); with a bad range
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include <string>
+#include <cassert>
+#include <exception>
+#include <cstdlib>
+
+#include "min_allocator.h"
+
+int main()
+{
+    {
+    std::string l1("123");
+    std::string::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin());
+    assert(false);
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S l1("123");
+    S::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin());
+    assert(false);
+    }
+#endif
+}
+
+#else
+
+int main()
+{
+}
+
+#endif

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// iterator erase(const_iterator p);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::difference_type pos, S expected)
+{
+    typename S::const_iterator p = s.begin() + pos;
+    typename S::iterator i = s.erase(p);
+    assert(s.__invariants());
+    assert(s == expected);
+    assert(i - s.begin() == pos);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S("abcde"), 0, S("bcde"));
+    test(S("abcde"), 1, S("acde"));
+    test(S("abcde"), 2, S("abde"));
+    test(S("abcde"), 4, S("abcd"));
+    test(S("abcdefghij"), 0, S("bcdefghij"));
+    test(S("abcdefghij"), 1, S("acdefghij"));
+    test(S("abcdefghij"), 5, S("abcdeghij"));
+    test(S("abcdefghij"), 9, S("abcdefghi"));
+    test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S("abcde"), 0, S("bcde"));
+    test(S("abcde"), 1, S("acde"));
+    test(S("abcde"), 2, S("abde"));
+    test(S("abcde"), 4, S("abcd"));
+    test(S("abcdefghij"), 0, S("bcdefghij"));
+    test(S("abcdefghij"), 1, S("acdefghij"));
+    test(S("abcdefghij"), 5, S("abcdeghij"));
+    test(S("abcdefghij"), 9, S("abcdefghi"));
+    test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/iter_iter.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,149 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// iterator erase(const_iterator first, const_iterator last);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::difference_type pos, typename S::difference_type n, S expected)
+{
+    typename S::const_iterator first = s.cbegin() + pos;
+    typename S::const_iterator last = s.cbegin() + pos + n;
+    typename S::iterator i = s.erase(first, last);
+    assert(s.__invariants());
+    assert(s == expected);
+    assert(i - s.begin() == pos);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, 0, S(""));
+    test(S("abcde"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 1, S("bcde"));
+    test(S("abcde"), 0, 2, S("cde"));
+    test(S("abcde"), 0, 4, S("e"));
+    test(S("abcde"), 0, 5, S(""));
+    test(S("abcde"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 1, S("acde"));
+    test(S("abcde"), 1, 2, S("ade"));
+    test(S("abcde"), 1, 3, S("ae"));
+    test(S("abcde"), 1, 4, S("a"));
+    test(S("abcde"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, 1, S("abde"));
+    test(S("abcde"), 2, 2, S("abe"));
+    test(S("abcde"), 2, 3, S("ab"));
+    test(S("abcde"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, 1, S("abcd"));
+    test(S("abcde"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S("fghij"));
+    test(S("abcdefghij"), 0, 9, S("j"));
+    test(S("abcdefghij"), 0, 10, S(""));
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 4, S("afghij"));
+    test(S("abcdefghij"), 1, 8, S("aj"));
+    test(S("abcdefghij"), 1, 9, S("a"));
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 2, S("abcdehij"));
+    test(S("abcdefghij"), 5, 4, S("abcdej"));
+    test(S("abcdefghij"), 5, 5, S("abcde"));
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, 0, S(""));
+    test(S("abcde"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 1, S("bcde"));
+    test(S("abcde"), 0, 2, S("cde"));
+    test(S("abcde"), 0, 4, S("e"));
+    test(S("abcde"), 0, 5, S(""));
+    test(S("abcde"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 1, S("acde"));
+    test(S("abcde"), 1, 2, S("ade"));
+    test(S("abcde"), 1, 3, S("ae"));
+    test(S("abcde"), 1, 4, S("a"));
+    test(S("abcde"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, 1, S("abde"));
+    test(S("abcde"), 2, 2, S("abe"));
+    test(S("abcde"), 2, 3, S("ab"));
+    test(S("abcde"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, 1, S("abcd"));
+    test(S("abcde"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S("fghij"));
+    test(S("abcdefghij"), 0, 9, S("j"));
+    test(S("abcdefghij"), 0, 10, S(""));
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 4, S("afghij"));
+    test(S("abcdefghij"), 1, 8, S("aj"));
+    test(S("abcdefghij"), 1, 9, S("a"));
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 2, S("abcdehij"));
+    test(S("abcdefghij"), 5, 4, S("abcdej"));
+    test(S("abcdefghij"), 5, 5, S("abcde"));
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// void pop_back();
+
+#if _LIBCPP_DEBUG >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, S expected)
+{
+    s.pop_back();
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S("abcde"), S("abcd"));
+    test(S("abcdefghij"), S("abcdefghi"));
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S("abcde"), S("abcd"));
+    test(S("abcdefghij"), S("abcdefghi"));
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
+    }
+#endif
+#if _LIBCPP_DEBUG >= 1
+    {
+        std::string s;
+        s.pop_back();
+        assert(false);
+    }
+#endif        
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_erase/size_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,280 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   erase(size_type pos = 0, size_type n = npos);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, typename S::size_type n, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.erase(pos, n);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void
+test(S s, typename S::size_type pos, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.erase(pos);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void
+test(S s, S expected)
+{
+    s.erase();
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, 0, S(""));
+    test(S(""), 0, 1, S(""));
+    test(S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 1, S("bcde"));
+    test(S("abcde"), 0, 2, S("cde"));
+    test(S("abcde"), 0, 4, S("e"));
+    test(S("abcde"), 0, 5, S(""));
+    test(S("abcde"), 0, 6, S(""));
+    test(S("abcde"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 1, S("acde"));
+    test(S("abcde"), 1, 2, S("ade"));
+    test(S("abcde"), 1, 3, S("ae"));
+    test(S("abcde"), 1, 4, S("a"));
+    test(S("abcde"), 1, 5, S("a"));
+    test(S("abcde"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, 1, S("abde"));
+    test(S("abcde"), 2, 2, S("abe"));
+    test(S("abcde"), 2, 3, S("ab"));
+    test(S("abcde"), 2, 4, S("ab"));
+    test(S("abcde"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S("abcd"));
+    test(S("abcde"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("abcde"));
+    test(S("abcde"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S("fghij"));
+    test(S("abcdefghij"), 0, 9, S("j"));
+    test(S("abcdefghij"), 0, 10, S(""));
+    test(S("abcdefghij"), 0, 11, S(""));
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 4, S("afghij"));
+    test(S("abcdefghij"), 1, 8, S("aj"));
+    test(S("abcdefghij"), 1, 9, S("a"));
+    test(S("abcdefghij"), 1, 10, S("a"));
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 2, S("abcdehij"));
+    test(S("abcdefghij"), 5, 4, S("abcdej"));
+    test(S("abcdefghij"), 5, 5, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("abcde"));
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("abcdefghi"));
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"));
+
+    test(S(""), 0, S(""));
+    test(S(""), 1, S("can't happen"));
+    test(S("abcde"), 0, S(""));
+    test(S("abcde"), 1, S("a"));
+    test(S("abcde"), 2, S("ab"));
+    test(S("abcde"), 4, S("abcd"));
+    test(S("abcde"), 5, S("abcde"));
+    test(S("abcde"), 6, S("can't happen"));
+    test(S("abcdefghij"), 0, S(""));
+    test(S("abcdefghij"), 1, S("a"));
+    test(S("abcdefghij"), 5, S("abcde"));
+    test(S("abcdefghij"), 9, S("abcdefghi"));
+    test(S("abcdefghij"), 10, S("abcdefghij"));
+    test(S("abcdefghij"), 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 21, S("can't happen"));
+
+    test(S(""), S(""));
+    test(S("abcde"), S(""));
+    test(S("abcdefghij"), S(""));
+    test(S("abcdefghijklmnopqrst"), S(""));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, 0, S(""));
+    test(S(""), 0, 1, S(""));
+    test(S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 1, S("bcde"));
+    test(S("abcde"), 0, 2, S("cde"));
+    test(S("abcde"), 0, 4, S("e"));
+    test(S("abcde"), 0, 5, S(""));
+    test(S("abcde"), 0, 6, S(""));
+    test(S("abcde"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 1, S("acde"));
+    test(S("abcde"), 1, 2, S("ade"));
+    test(S("abcde"), 1, 3, S("ae"));
+    test(S("abcde"), 1, 4, S("a"));
+    test(S("abcde"), 1, 5, S("a"));
+    test(S("abcde"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, 1, S("abde"));
+    test(S("abcde"), 2, 2, S("abe"));
+    test(S("abcde"), 2, 3, S("ab"));
+    test(S("abcde"), 2, 4, S("ab"));
+    test(S("abcde"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S("abcd"));
+    test(S("abcde"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("abcde"));
+    test(S("abcde"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S("fghij"));
+    test(S("abcdefghij"), 0, 9, S("j"));
+    test(S("abcdefghij"), 0, 10, S(""));
+    test(S("abcdefghij"), 0, 11, S(""));
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 4, S("afghij"));
+    test(S("abcdefghij"), 1, 8, S("aj"));
+    test(S("abcdefghij"), 1, 9, S("a"));
+    test(S("abcdefghij"), 1, 10, S("a"));
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 2, S("abcdehij"));
+    test(S("abcdefghij"), 5, 4, S("abcdej"));
+    test(S("abcdefghij"), 5, 5, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("abcde"));
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("abcdefghi"));
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("can't happen"));
+
+    test(S(""), 0, S(""));
+    test(S(""), 1, S("can't happen"));
+    test(S("abcde"), 0, S(""));
+    test(S("abcde"), 1, S("a"));
+    test(S("abcde"), 2, S("ab"));
+    test(S("abcde"), 4, S("abcd"));
+    test(S("abcde"), 5, S("abcde"));
+    test(S("abcde"), 6, S("can't happen"));
+    test(S("abcdefghij"), 0, S(""));
+    test(S("abcdefghij"), 1, S("a"));
+    test(S("abcdefghij"), 5, S("abcde"));
+    test(S("abcdefghij"), 9, S("abcdefghi"));
+    test(S("abcdefghij"), 10, S("abcdefghij"));
+    test(S("abcdefghij"), 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 10, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 20, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 21, S("can't happen"));
+
+    test(S(""), S(""));
+    test(S("abcde"), S(""));
+    test(S("abcdefghij"), S(""));
+    test(S("abcdefghijklmnopqrst"), S(""));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// iterator insert(const_iterator p, charT c);
+
+#if _LIBCPP_DEBUG >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
+{
+    bool sufficient_cap = s.size() < s.capacity();
+    typename S::difference_type pos = p - s.begin();
+    typename S::iterator i = s.insert(p, c);
+    assert(s.__invariants());
+    assert(s == expected);
+    assert(i - s.begin() == pos);
+    assert(*i == c);
+    if (sufficient_cap)
+        assert(i == p);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    S s;
+    test(s, s.begin(), '1', S("1"));
+    test(s, s.begin(), 'a', S("a1"));
+    test(s, s.end(), 'b', S("a1b"));
+    test(s, s.end()-1, 'c', S("a1cb"));
+    test(s, s.end()-2, 'd', S("a1dcb"));
+    test(s, s.end()-3, '2', S("a12dcb"));
+    test(s, s.end()-4, '3', S("a132dcb"));
+    test(s, s.end()-5, '4', S("a1432dcb"));
+    test(s, s.begin()+1, '5', S("a51432dcb"));
+    test(s, s.begin()+2, '6', S("a561432dcb"));
+    test(s, s.begin()+3, '7', S("a5671432dcb"));
+    test(s, s.begin()+4, 'A', S("a567A1432dcb"));
+    test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
+    test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    S s;
+    test(s, s.begin(), '1', S("1"));
+    test(s, s.begin(), 'a', S("a1"));
+    test(s, s.end(), 'b', S("a1b"));
+    test(s, s.end()-1, 'c', S("a1cb"));
+    test(s, s.end()-2, 'd', S("a1dcb"));
+    test(s, s.end()-3, '2', S("a12dcb"));
+    test(s, s.end()-4, '3', S("a132dcb"));
+    test(s, s.end()-5, '4', S("a1432dcb"));
+    test(s, s.begin()+1, '5', S("a51432dcb"));
+    test(s, s.begin()+2, '6', S("a561432dcb"));
+    test(s, s.begin()+3, '7', S("a5671432dcb"));
+    test(s, s.begin()+4, 'A', S("a567A1432dcb"));
+    test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
+    test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
+    }
+#endif
+#if _LIBCPP_DEBUG >= 1
+    {
+        typedef std::string S;
+        S s;
+        S s2;
+        s.insert(s2.begin(), '1');
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// iterator insert(const_iterator p, initializer_list<charT> il);
+
+#if _LIBCPP_DEBUG >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+    {
+        std::string s("123456");
+        std::string::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
+        assert(i - s.begin() == 3);
+        assert(s == "123abc456");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s("123456");
+        S::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
+        assert(i - s.begin() == 3);
+        assert(s == "123abc456");
+    }
+#endif
+#if _LIBCPP_DEBUG >= 1
+    {
+        std::string s;
+        std::string s2;
+        s.insert(s2.begin(), {'a', 'b', 'c'});
+        assert(false);
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_iter_iter.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+//   iterator insert(const_iterator p, InputIterator first, InputIterator last);
+
+#if _LIBCPP_DEBUG >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "../../input_iterator.h"
+#include "min_allocator.h"
+
+template <class S, class It>
+void
+test(S s, typename S::difference_type pos, It first, It last, S expected)
+{
+    typename S::const_iterator p = s.cbegin() + pos;
+    typename S::iterator i = s.insert(p, first, last);
+    assert(s.__invariants());
+    assert(i - s.begin() == pos);
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    test(S(), 0, s, s, S());
+    test(S(), 0, s, s+1, S("A"));
+    test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
+    test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), 0, s, s, S("12345"));
+    test(S("12345"), 1, s, s+1, S("1A2345"));
+    test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
+    test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), 0, s, s, S("1234567890"));
+    test(S("1234567890"), 1, s, s+1, S("1A234567890"));
+    test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+    test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
+    test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
+    test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
+    test(S("12345678901234567890"), 20, s, s+52,
+         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S());
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A"));
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S("12345"));
+    test(S("12345"), 1, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("1A2345"));
+    test(S("12345"), 4, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
+    test(S("12345"), 5, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S("1234567890"));
+    test(S("1234567890"), 1, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("1A234567890"));
+    test(S("1234567890"), 10, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), 8, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+    test(S("12345678901234567890"), 3, input_iterator<const char*>(s), input_iterator<const char*>(s), S("12345678901234567890"));
+    test(S("12345678901234567890"), 3, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("123A45678901234567890"));
+    test(S("12345678901234567890"), 15, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
+    test(S("12345678901234567890"), 20, input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    test(S(), 0, s, s, S());
+    test(S(), 0, s, s+1, S("A"));
+    test(S(), 0, s, s+10, S("ABCDEFGHIJ"));
+    test(S(), 0, s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), 0, s, s, S("12345"));
+    test(S("12345"), 1, s, s+1, S("1A2345"));
+    test(S("12345"), 4, s, s+10, S("1234ABCDEFGHIJ5"));
+    test(S("12345"), 5, s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), 0, s, s, S("1234567890"));
+    test(S("1234567890"), 1, s, s+1, S("1A234567890"));
+    test(S("1234567890"), 10, s, s+10, S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), 8, s, s+52, S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+    test(S("12345678901234567890"), 3, s, s, S("12345678901234567890"));
+    test(S("12345678901234567890"), 3, s, s+1, S("123A45678901234567890"));
+    test(S("12345678901234567890"), 15, s, s+10, S("123456789012345ABCDEFGHIJ67890"));
+    test(S("12345678901234567890"), 20, s, s+52,
+         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S());
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A"));
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("ABCDEFGHIJ"));
+    test(S(), 0, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S("12345"));
+    test(S("12345"), 1, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("1A2345"));
+    test(S("12345"), 4, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("1234ABCDEFGHIJ5"));
+    test(S("12345"), 5, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), 0, input_iterator<const char*>(s), input_iterator<const char*>(s), S("1234567890"));
+    test(S("1234567890"), 1, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("1A234567890"));
+    test(S("1234567890"), 10, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("1234567890ABCDEFGHIJ"));
+    test(S("1234567890"), 8, input_iterator<const char*>(s), input_iterator<const char*>(s+52), S("12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz90"));
+
+    test(S("12345678901234567890"), 3, input_iterator<const char*>(s), input_iterator<const char*>(s), S("12345678901234567890"));
+    test(S("12345678901234567890"), 3, input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("123A45678901234567890"));
+    test(S("12345678901234567890"), 15, input_iterator<const char*>(s), input_iterator<const char*>(s+10), S("123456789012345ABCDEFGHIJ67890"));
+    test(S("12345678901234567890"), 20, input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+    }
+#endif
+#if _LIBCPP_DEBUG >= 1
+    {
+        std::string v;
+        std::string v2;
+        char a[] = "123";
+        const int N = sizeof(a)/sizeof(a[0]);
+        std::string::iterator i = v.insert(v2.cbegin() + 10, a, a+N);
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/iter_size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,181 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>
+
+// iterator insert(const_iterator p, size_type n, charT c);
+
+#if _LIBCPP_DEBUG >= 1
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+#endif
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::difference_type pos, typename S::size_type n,
+     typename S::value_type c, S expected)
+{
+    typename S::const_iterator p = s.cbegin() + pos;
+    typename S::iterator i = s.insert(p, n, c);
+    assert(s.__invariants());
+    assert(i - s.begin() == pos);
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, 0, '1', S(""));
+    test(S(""), 0, 5, '1', S("11111"));
+    test(S(""), 0, 10, '1', S("1111111111"));
+    test(S(""), 0, 20, '1', S("11111111111111111111"));
+    test(S("abcde"), 0, 0, '1', S("abcde"));
+    test(S("abcde"), 0, 5, '1', S("11111abcde"));
+    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+    test(S("abcde"), 1, 0, '1', S("abcde"));
+    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+    test(S("abcde"), 2, 0, '1', S("abcde"));
+    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+    test(S("abcde"), 4, 0, '1', S("abcde"));
+    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+    test(S("abcde"), 5, 0, '1', S("abcde"));
+    test(S("abcde"), 5, 5, '1', S("abcde11111"));
+    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, 0, '1', S(""));
+    test(S(""), 0, 5, '1', S("11111"));
+    test(S(""), 0, 10, '1', S("1111111111"));
+    test(S(""), 0, 20, '1', S("11111111111111111111"));
+    test(S("abcde"), 0, 0, '1', S("abcde"));
+    test(S("abcde"), 0, 5, '1', S("11111abcde"));
+    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+    test(S("abcde"), 1, 0, '1', S("abcde"));
+    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+    test(S("abcde"), 2, 0, '1', S("abcde"));
+    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+    test(S("abcde"), 4, 0, '1', S("abcde"));
+    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+    test(S("abcde"), 5, 0, '1', S("abcde"));
+    test(S("abcde"), 5, 5, '1', S("abcde11111"));
+    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+    }
+#endif
+#if _LIBCPP_DEBUG >= 1
+    {
+        std::string s;
+        std::string s2;
+        s.insert(s2.begin(), 1, 'a');
+        assert(false);
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,211 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   insert(size_type pos, const charT* s);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, const typename S::value_type* str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos, str);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, "", S(""));
+    test(S(""), 0, "12345", S("12345"));
+    test(S(""), 0, "1234567890", S("1234567890"));
+    test(S(""), 0, "12345678901234567890", S("12345678901234567890"));
+    test(S(""), 1, "", S("can't happen"));
+    test(S(""), 1, "12345", S("can't happen"));
+    test(S(""), 1, "1234567890", S("can't happen"));
+    test(S(""), 1, "12345678901234567890", S("can't happen"));
+    test(S("abcde"), 0, "", S("abcde"));
+    test(S("abcde"), 0, "12345", S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", S("12345678901234567890abcde"));
+    test(S("abcde"), 1, "", S("abcde"));
+    test(S("abcde"), 1, "12345", S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, "", S("abcde"));
+    test(S("abcde"), 2, "12345", S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, "", S("abcde"));
+    test(S("abcde"), 4, "12345", S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, "", S("abcde"));
+    test(S("abcde"), 5, "12345", S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcde"), 6, "", S("can't happen"));
+    test(S("abcde"), 6, "12345", S("can't happen"));
+    test(S("abcde"), 6, "1234567890", S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", S("can't happen"));
+    test(S("abcdefghij"), 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, "", S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, "", S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, "", S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, "", S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, "", S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, "", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, "", S(""));
+    test(S(""), 0, "12345", S("12345"));
+    test(S(""), 0, "1234567890", S("1234567890"));
+    test(S(""), 0, "12345678901234567890", S("12345678901234567890"));
+    test(S(""), 1, "", S("can't happen"));
+    test(S(""), 1, "12345", S("can't happen"));
+    test(S(""), 1, "1234567890", S("can't happen"));
+    test(S(""), 1, "12345678901234567890", S("can't happen"));
+    test(S("abcde"), 0, "", S("abcde"));
+    test(S("abcde"), 0, "12345", S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", S("12345678901234567890abcde"));
+    test(S("abcde"), 1, "", S("abcde"));
+    test(S("abcde"), 1, "12345", S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, "", S("abcde"));
+    test(S("abcde"), 2, "12345", S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, "", S("abcde"));
+    test(S("abcde"), 4, "12345", S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, "", S("abcde"));
+    test(S("abcde"), 5, "12345", S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcde"), 6, "", S("can't happen"));
+    test(S("abcde"), 6, "12345", S("can't happen"));
+    test(S("abcde"), 6, "1234567890", S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", S("can't happen"));
+    test(S("abcdefghij"), 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, "", S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, "", S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, "", S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, "", S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, "", S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, "", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", S("can't happen"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_pointer_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,692 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   insert(size_type pos, const charT* s, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, const typename S::value_type* str,
+     typename S::size_type n, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos, str, n);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, "", 0, S(""));
+    test(S(""), 0, "12345", 0, S(""));
+    test(S(""), 0, "12345", 1, S("1"));
+    test(S(""), 0, "12345", 2, S("12"));
+    test(S(""), 0, "12345", 4, S("1234"));
+    test(S(""), 0, "12345", 5, S("12345"));
+    test(S(""), 0, "1234567890", 0, S(""));
+    test(S(""), 0, "1234567890", 1, S("1"));
+    test(S(""), 0, "1234567890", 5, S("12345"));
+    test(S(""), 0, "1234567890", 9, S("123456789"));
+    test(S(""), 0, "1234567890", 10, S("1234567890"));
+    test(S(""), 0, "12345678901234567890", 0, S(""));
+    test(S(""), 0, "12345678901234567890", 1, S("1"));
+    test(S(""), 0, "12345678901234567890", 10, S("1234567890"));
+    test(S(""), 0, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S(""), 0, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S(""), 1, "", 0, S("can't happen"));
+    test(S(""), 1, "12345", 0, S("can't happen"));
+    test(S(""), 1, "12345", 1, S("can't happen"));
+    test(S(""), 1, "12345", 2, S("can't happen"));
+    test(S(""), 1, "12345", 4, S("can't happen"));
+    test(S(""), 1, "12345", 5, S("can't happen"));
+    test(S(""), 1, "1234567890", 0, S("can't happen"));
+    test(S(""), 1, "1234567890", 1, S("can't happen"));
+    test(S(""), 1, "1234567890", 5, S("can't happen"));
+    test(S(""), 1, "1234567890", 9, S("can't happen"));
+    test(S(""), 1, "1234567890", 10, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 0, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 1, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 10, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 19, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcde"), 0, "", 0, S("abcde"));
+    test(S("abcde"), 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 0, "12345", 1, S("1abcde"));
+    test(S("abcde"), 0, "12345", 2, S("12abcde"));
+    test(S("abcde"), 0, "12345", 4, S("1234abcde"));
+    test(S("abcde"), 0, "12345", 5, S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 0, "1234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, "1234567890", 5, S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", 9, S("123456789abcde"));
+    test(S("abcde"), 0, "1234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 1, "", 0, S("abcde"));
+    test(S("abcde"), 1, "12345", 0, S("abcde"));
+    test(S("abcde"), 1, "12345", 1, S("a1bcde"));
+    test(S("abcde"), 1, "12345", 2, S("a12bcde"));
+    test(S("abcde"), 1, "12345", 4, S("a1234bcde"));
+    test(S("abcde"), 1, "12345", 5, S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 1, "1234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, "1234567890", 5, S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", 9, S("a123456789bcde"));
+    test(S("abcde"), 1, "1234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 1, "12345678901234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, "", 0, S("abcde"));
+    test(S("abcde"), 2, "12345", 0, S("abcde"));
+    test(S("abcde"), 2, "12345", 1, S("ab1cde"));
+    test(S("abcde"), 2, "12345", 2, S("ab12cde"));
+    test(S("abcde"), 2, "12345", 4, S("ab1234cde"));
+    test(S("abcde"), 2, "12345", 5, S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 2, "1234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, "1234567890", 5, S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", 9, S("ab123456789cde"));
+    test(S("abcde"), 2, "1234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 2, "12345678901234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, "12345678901234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", 19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, "12345678901234567890", 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, "", 0, S("abcde"));
+    test(S("abcde"), 4, "12345", 0, S("abcde"));
+    test(S("abcde"), 4, "12345", 1, S("abcd1e"));
+    test(S("abcde"), 4, "12345", 2, S("abcd12e"));
+    test(S("abcde"), 4, "12345", 4, S("abcd1234e"));
+    test(S("abcde"), 4, "12345", 5, S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 4, "1234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, "1234567890", 5, S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", 9, S("abcd123456789e"));
+    test(S("abcde"), 4, "1234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 4, "12345678901234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, "12345678901234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, "12345678901234567890", 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, "", 0, S("abcde"));
+    test(S("abcde"), 5, "12345", 0, S("abcde"));
+    test(S("abcde"), 5, "12345", 1, S("abcde1"));
+    test(S("abcde"), 5, "12345", 2, S("abcde12"));
+    test(S("abcde"), 5, "12345", 4, S("abcde1234"));
+    test(S("abcde"), 5, "12345", 5, S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 5, "1234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, "1234567890", 5, S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", 9, S("abcde123456789"));
+    test(S("abcde"), 5, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 5, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 6, "", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345", 1, S("can't happen"));
+    test(S("abcde"), 6, "12345", 2, S("can't happen"));
+    test(S("abcde"), 6, "12345", 4, S("can't happen"));
+    test(S("abcde"), 6, "12345", 5, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 5, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 9, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcdefghij"), 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "12345", 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, "12345", 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, "12345", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "1234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "12345", 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, "12345", 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, "12345", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "1234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "1234567890", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, "1234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, "", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 2, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 4, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, "", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, "", 0, S(""));
+    test(S(""), 0, "12345", 0, S(""));
+    test(S(""), 0, "12345", 1, S("1"));
+    test(S(""), 0, "12345", 2, S("12"));
+    test(S(""), 0, "12345", 4, S("1234"));
+    test(S(""), 0, "12345", 5, S("12345"));
+    test(S(""), 0, "1234567890", 0, S(""));
+    test(S(""), 0, "1234567890", 1, S("1"));
+    test(S(""), 0, "1234567890", 5, S("12345"));
+    test(S(""), 0, "1234567890", 9, S("123456789"));
+    test(S(""), 0, "1234567890", 10, S("1234567890"));
+    test(S(""), 0, "12345678901234567890", 0, S(""));
+    test(S(""), 0, "12345678901234567890", 1, S("1"));
+    test(S(""), 0, "12345678901234567890", 10, S("1234567890"));
+    test(S(""), 0, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S(""), 0, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S(""), 1, "", 0, S("can't happen"));
+    test(S(""), 1, "12345", 0, S("can't happen"));
+    test(S(""), 1, "12345", 1, S("can't happen"));
+    test(S(""), 1, "12345", 2, S("can't happen"));
+    test(S(""), 1, "12345", 4, S("can't happen"));
+    test(S(""), 1, "12345", 5, S("can't happen"));
+    test(S(""), 1, "1234567890", 0, S("can't happen"));
+    test(S(""), 1, "1234567890", 1, S("can't happen"));
+    test(S(""), 1, "1234567890", 5, S("can't happen"));
+    test(S(""), 1, "1234567890", 9, S("can't happen"));
+    test(S(""), 1, "1234567890", 10, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 0, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 1, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 10, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 19, S("can't happen"));
+    test(S(""), 1, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcde"), 0, "", 0, S("abcde"));
+    test(S("abcde"), 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 0, "12345", 1, S("1abcde"));
+    test(S("abcde"), 0, "12345", 2, S("12abcde"));
+    test(S("abcde"), 0, "12345", 4, S("1234abcde"));
+    test(S("abcde"), 0, "12345", 5, S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 0, "1234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, "1234567890", 5, S("12345abcde"));
+    test(S("abcde"), 0, "1234567890", 9, S("123456789abcde"));
+    test(S("abcde"), 0, "1234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, "12345678901234567890", 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 1, "", 0, S("abcde"));
+    test(S("abcde"), 1, "12345", 0, S("abcde"));
+    test(S("abcde"), 1, "12345", 1, S("a1bcde"));
+    test(S("abcde"), 1, "12345", 2, S("a12bcde"));
+    test(S("abcde"), 1, "12345", 4, S("a1234bcde"));
+    test(S("abcde"), 1, "12345", 5, S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 1, "1234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, "1234567890", 5, S("a12345bcde"));
+    test(S("abcde"), 1, "1234567890", 9, S("a123456789bcde"));
+    test(S("abcde"), 1, "1234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 1, "12345678901234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, "12345678901234567890", 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, "", 0, S("abcde"));
+    test(S("abcde"), 2, "12345", 0, S("abcde"));
+    test(S("abcde"), 2, "12345", 1, S("ab1cde"));
+    test(S("abcde"), 2, "12345", 2, S("ab12cde"));
+    test(S("abcde"), 2, "12345", 4, S("ab1234cde"));
+    test(S("abcde"), 2, "12345", 5, S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 2, "1234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, "1234567890", 5, S("ab12345cde"));
+    test(S("abcde"), 2, "1234567890", 9, S("ab123456789cde"));
+    test(S("abcde"), 2, "1234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 2, "12345678901234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, "12345678901234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, "12345678901234567890", 19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, "12345678901234567890", 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, "", 0, S("abcde"));
+    test(S("abcde"), 4, "12345", 0, S("abcde"));
+    test(S("abcde"), 4, "12345", 1, S("abcd1e"));
+    test(S("abcde"), 4, "12345", 2, S("abcd12e"));
+    test(S("abcde"), 4, "12345", 4, S("abcd1234e"));
+    test(S("abcde"), 4, "12345", 5, S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 4, "1234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, "1234567890", 5, S("abcd12345e"));
+    test(S("abcde"), 4, "1234567890", 9, S("abcd123456789e"));
+    test(S("abcde"), 4, "1234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 4, "12345678901234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, "12345678901234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, "12345678901234567890", 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, "12345678901234567890", 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, "", 0, S("abcde"));
+    test(S("abcde"), 5, "12345", 0, S("abcde"));
+    test(S("abcde"), 5, "12345", 1, S("abcde1"));
+    test(S("abcde"), 5, "12345", 2, S("abcde12"));
+    test(S("abcde"), 5, "12345", 4, S("abcde1234"));
+    test(S("abcde"), 5, "12345", 5, S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 5, "1234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, "1234567890", 5, S("abcde12345"));
+    test(S("abcde"), 5, "1234567890", 9, S("abcde123456789"));
+    test(S("abcde"), 5, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 5, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 6, "", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345", 1, S("can't happen"));
+    test(S("abcde"), 6, "12345", 2, S("can't happen"));
+    test(S("abcde"), 6, "12345", 4, S("can't happen"));
+    test(S("abcde"), 6, "12345", 5, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 5, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 9, S("can't happen"));
+    test(S("abcde"), 6, "1234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcde"), 6, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcdefghij"), 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, "12345", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, "1234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, "12345678901234567890", 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, "12345", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, "1234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, "12345678901234567890", 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "12345", 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, "12345", 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, "12345", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "1234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, "1234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, "12345678901234567890", 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "12345", 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, "12345", 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, "12345", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "1234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "1234567890", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, "1234567890", 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, "1234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, "12345678901234567890", 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, "", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 2, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 4, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghij"), 11, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghij"), 11, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "1234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, "12345678901234567890", 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "1234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, "12345678901234567890", 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "1234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, "", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, "12345678901234567890", 20, S("can't happen"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,212 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   insert(size_type pos, size_type n, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, typename S::size_type n,
+     typename S::value_type str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos, n, str);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, 0, '1', S(""));
+    test(S(""), 0, 5, '1', S("11111"));
+    test(S(""), 0, 10, '1', S("1111111111"));
+    test(S(""), 0, 20, '1', S("11111111111111111111"));
+    test(S(""), 1, 0, '1', S("can't happen"));
+    test(S(""), 1, 5, '1', S("can't happen"));
+    test(S(""), 1, 10, '1', S("can't happen"));
+    test(S(""), 1, 20, '1', S("can't happen"));
+    test(S("abcde"), 0, 0, '1', S("abcde"));
+    test(S("abcde"), 0, 5, '1', S("11111abcde"));
+    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+    test(S("abcde"), 1, 0, '1', S("abcde"));
+    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+    test(S("abcde"), 2, 0, '1', S("abcde"));
+    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+    test(S("abcde"), 4, 0, '1', S("abcde"));
+    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+    test(S("abcde"), 5, 0, '1', S("abcde"));
+    test(S("abcde"), 5, 5, '1', S("abcde11111"));
+    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+    test(S("abcde"), 6, 0, '1', S("can't happen"));
+    test(S("abcde"), 6, 5, '1', S("can't happen"));
+    test(S("abcde"), 6, 10, '1', S("can't happen"));
+    test(S("abcde"), 6, 20, '1', S("can't happen"));
+    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+    test(S("abcdefghij"), 11, 0, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 5, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 10, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 20, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, 0, '1', S(""));
+    test(S(""), 0, 5, '1', S("11111"));
+    test(S(""), 0, 10, '1', S("1111111111"));
+    test(S(""), 0, 20, '1', S("11111111111111111111"));
+    test(S(""), 1, 0, '1', S("can't happen"));
+    test(S(""), 1, 5, '1', S("can't happen"));
+    test(S(""), 1, 10, '1', S("can't happen"));
+    test(S(""), 1, 20, '1', S("can't happen"));
+    test(S("abcde"), 0, 0, '1', S("abcde"));
+    test(S("abcde"), 0, 5, '1', S("11111abcde"));
+    test(S("abcde"), 0, 10, '1', S("1111111111abcde"));
+    test(S("abcde"), 0, 20, '1', S("11111111111111111111abcde"));
+    test(S("abcde"), 1, 0, '1', S("abcde"));
+    test(S("abcde"), 1, 5, '1', S("a11111bcde"));
+    test(S("abcde"), 1, 10, '1', S("a1111111111bcde"));
+    test(S("abcde"), 1, 20, '1', S("a11111111111111111111bcde"));
+    test(S("abcde"), 2, 0, '1', S("abcde"));
+    test(S("abcde"), 2, 5, '1', S("ab11111cde"));
+    test(S("abcde"), 2, 10, '1', S("ab1111111111cde"));
+    test(S("abcde"), 2, 20, '1', S("ab11111111111111111111cde"));
+    test(S("abcde"), 4, 0, '1', S("abcde"));
+    test(S("abcde"), 4, 5, '1', S("abcd11111e"));
+    test(S("abcde"), 4, 10, '1', S("abcd1111111111e"));
+    test(S("abcde"), 4, 20, '1', S("abcd11111111111111111111e"));
+    test(S("abcde"), 5, 0, '1', S("abcde"));
+    test(S("abcde"), 5, 5, '1', S("abcde11111"));
+    test(S("abcde"), 5, 10, '1', S("abcde1111111111"));
+    test(S("abcde"), 5, 20, '1', S("abcde11111111111111111111"));
+    test(S("abcde"), 6, 0, '1', S("can't happen"));
+    test(S("abcde"), 6, 5, '1', S("can't happen"));
+    test(S("abcde"), 6, 10, '1', S("can't happen"));
+    test(S("abcde"), 6, 20, '1', S("can't happen"));
+    test(S("abcdefghij"), 0, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 5, '1', S("11111abcdefghij"));
+    test(S("abcdefghij"), 0, 10, '1', S("1111111111abcdefghij"));
+    test(S("abcdefghij"), 0, 20, '1', S("11111111111111111111abcdefghij"));
+    test(S("abcdefghij"), 1, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 5, '1', S("a11111bcdefghij"));
+    test(S("abcdefghij"), 1, 10, '1', S("a1111111111bcdefghij"));
+    test(S("abcdefghij"), 1, 20, '1', S("a11111111111111111111bcdefghij"));
+    test(S("abcdefghij"), 5, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 5, '1', S("abcde11111fghij"));
+    test(S("abcdefghij"), 5, 10, '1', S("abcde1111111111fghij"));
+    test(S("abcdefghij"), 5, 20, '1', S("abcde11111111111111111111fghij"));
+    test(S("abcdefghij"), 9, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 5, '1', S("abcdefghi11111j"));
+    test(S("abcdefghij"), 9, 10, '1', S("abcdefghi1111111111j"));
+    test(S("abcdefghij"), 9, 20, '1', S("abcdefghi11111111111111111111j"));
+    test(S("abcdefghij"), 10, 0, '1', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 5, '1', S("abcdefghij11111"));
+    test(S("abcdefghij"), 10, 10, '1', S("abcdefghij1111111111"));
+    test(S("abcdefghij"), 10, 20, '1', S("abcdefghij11111111111111111111"));
+    test(S("abcdefghij"), 11, 0, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 5, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 10, '1', S("can't happen"));
+    test(S("abcdefghij"), 11, 20, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 5, '1', S("11111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, '1', S("1111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, '1', S("11111111111111111111abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 5, '1', S("a11111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 10, '1', S("a1111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, '1', S("a11111111111111111111bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, '1', S("abcdefghij11111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, '1', S("abcdefghij1111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 20, '1', S("abcdefghij11111111111111111111klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 5, '1', S("abcdefghijklmnopqrs11111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 10, '1', S("abcdefghijklmnopqrs1111111111t"));
+    test(S("abcdefghijklmnopqrst"), 19, 20, '1', S("abcdefghijklmnopqrs11111111111111111111t"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, '1', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 5, '1', S("abcdefghijklmnopqrst11111"));
+    test(S("abcdefghijklmnopqrst"), 20, 10, '1', S("abcdefghijklmnopqrst1111111111"));
+    test(S("abcdefghijklmnopqrst"), 20, 20, '1', S("abcdefghijklmnopqrst11111111111111111111"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 5, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 10, '1', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 20, '1', S("can't happen"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,211 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   insert(size_type pos1, const basic_string& str);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, S str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos, str);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(""), 0, S(""), S(""));
+    test(S(""), 0, S("12345"), S("12345"));
+    test(S(""), 0, S("1234567890"), S("1234567890"));
+    test(S(""), 0, S("12345678901234567890"), S("12345678901234567890"));
+    test(S(""), 1, S(""), S("can't happen"));
+    test(S(""), 1, S("12345"), S("can't happen"));
+    test(S(""), 1, S("1234567890"), S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), S("can't happen"));
+    test(S("abcde"), 0, S(""), S("abcde"));
+    test(S("abcde"), 0, S("12345"), S("12345abcde"));
+    test(S("abcde"), 0, S("1234567890"), S("1234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), S("12345678901234567890abcde"));
+    test(S("abcde"), 1, S(""), S("abcde"));
+    test(S("abcde"), 1, S("12345"), S("a12345bcde"));
+    test(S("abcde"), 1, S("1234567890"), S("a1234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, S(""), S("abcde"));
+    test(S("abcde"), 2, S("12345"), S("ab12345cde"));
+    test(S("abcde"), 2, S("1234567890"), S("ab1234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, S(""), S("abcde"));
+    test(S("abcde"), 4, S("12345"), S("abcd12345e"));
+    test(S("abcde"), 4, S("1234567890"), S("abcd1234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, S(""), S("abcde"));
+    test(S("abcde"), 5, S("12345"), S("abcde12345"));
+    test(S("abcde"), 5, S("1234567890"), S("abcde1234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcde"), 6, S(""), S("can't happen"));
+    test(S("abcde"), 6, S("12345"), S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), S("can't happen"));
+    test(S("abcdefghij"), 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("1234567890"), S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, S(""), S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, S(""), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(""), 0, S(""), S(""));
+    test(S(""), 0, S("12345"), S("12345"));
+    test(S(""), 0, S("1234567890"), S("1234567890"));
+    test(S(""), 0, S("12345678901234567890"), S("12345678901234567890"));
+    test(S(""), 1, S(""), S("can't happen"));
+    test(S(""), 1, S("12345"), S("can't happen"));
+    test(S(""), 1, S("1234567890"), S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), S("can't happen"));
+    test(S("abcde"), 0, S(""), S("abcde"));
+    test(S("abcde"), 0, S("12345"), S("12345abcde"));
+    test(S("abcde"), 0, S("1234567890"), S("1234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), S("12345678901234567890abcde"));
+    test(S("abcde"), 1, S(""), S("abcde"));
+    test(S("abcde"), 1, S("12345"), S("a12345bcde"));
+    test(S("abcde"), 1, S("1234567890"), S("a1234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), S("a12345678901234567890bcde"));
+    test(S("abcde"), 2, S(""), S("abcde"));
+    test(S("abcde"), 2, S("12345"), S("ab12345cde"));
+    test(S("abcde"), 2, S("1234567890"), S("ab1234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), S("ab12345678901234567890cde"));
+    test(S("abcde"), 4, S(""), S("abcde"));
+    test(S("abcde"), 4, S("12345"), S("abcd12345e"));
+    test(S("abcde"), 4, S("1234567890"), S("abcd1234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), S("abcd12345678901234567890e"));
+    test(S("abcde"), 5, S(""), S("abcde"));
+    test(S("abcde"), 5, S("12345"), S("abcde12345"));
+    test(S("abcde"), 5, S("1234567890"), S("abcde1234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcde"), 6, S(""), S("can't happen"));
+    test(S("abcde"), 6, S("12345"), S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), S("can't happen"));
+    test(S("abcdefghij"), 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 1, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 5, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 9, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("1234567890"), S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 10, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, S(""), S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 20, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, S(""), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), S("can't happen"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_string_size_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,1784 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   insert(size_type pos1, const basic_string<charT,traits,Allocator>& str,
+//          size_type pos2, size_type n=npos);
+// the "=npos" was added in C++14
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, S str, typename S::size_type pos2,
+     typename S::size_type n, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos1, str, pos2, n);
+        assert(s.__invariants());
+        assert(pos1 <= old_size && pos2 <= str.size());
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > old_size || pos2 > str.size());
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void
+test_npos(S s, typename S::size_type pos1, S str, typename S::size_type pos2, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.insert(pos1, str, pos2);
+        assert(s.__invariants());
+        assert(pos1 <= old_size && pos2 <= str.size());
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > old_size || pos2 > str.size());
+        assert(s == s0);
+    }
+}
+
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, S(""), 0, 0, S(""));
+    test(S(""), 0, S(""), 0, 1, S(""));
+    test(S(""), 0, S(""), 1, 0, S("can't happen"));
+    test(S(""), 0, S("12345"), 0, 0, S(""));
+    test(S(""), 0, S("12345"), 0, 1, S("1"));
+    test(S(""), 0, S("12345"), 0, 2, S("12"));
+    test(S(""), 0, S("12345"), 0, 4, S("1234"));
+    test(S(""), 0, S("12345"), 0, 5, S("12345"));
+    test(S(""), 0, S("12345"), 0, 6, S("12345"));
+    test(S(""), 0, S("12345"), 1, 0, S(""));
+    test(S(""), 0, S("12345"), 1, 1, S("2"));
+    test(S(""), 0, S("12345"), 1, 2, S("23"));
+    test(S(""), 0, S("12345"), 1, 3, S("234"));
+    test(S(""), 0, S("12345"), 1, 4, S("2345"));
+    test(S(""), 0, S("12345"), 1, 5, S("2345"));
+    test(S(""), 0, S("12345"), 2, 0, S(""));
+    test(S(""), 0, S("12345"), 2, 1, S("3"));
+    test(S(""), 0, S("12345"), 2, 2, S("34"));
+    test(S(""), 0, S("12345"), 2, 3, S("345"));
+    test(S(""), 0, S("12345"), 2, 4, S("345"));
+    test(S(""), 0, S("12345"), 4, 0, S(""));
+    test(S(""), 0, S("12345"), 4, 1, S("5"));
+    test(S(""), 0, S("12345"), 4, 2, S("5"));
+    test(S(""), 0, S("12345"), 5, 0, S(""));
+    test(S(""), 0, S("12345"), 5, 1, S(""));
+    test(S(""), 0, S("12345"), 6, 0, S("can't happen"));
+    test(S(""), 0, S("1234567890"), 0, 0, S(""));
+    test(S(""), 0, S("1234567890"), 0, 1, S("1"));
+    test(S(""), 0, S("1234567890"), 0, 5, S("12345"));
+    test(S(""), 0, S("1234567890"), 0, 9, S("123456789"));
+    test(S(""), 0, S("1234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, S("1234567890"), 0, 11, S("1234567890"));
+    test(S(""), 0, S("1234567890"), 1, 0, S(""));
+    test(S(""), 0, S("1234567890"), 1, 1, S("2"));
+    test(S(""), 0, S("1234567890"), 1, 4, S("2345"));
+    test(S(""), 0, S("1234567890"), 1, 8, S("23456789"));
+    test(S(""), 0, S("1234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, S("1234567890"), 1, 10, S("234567890"));
+    test(S(""), 0, S("1234567890"), 5, 0, S(""));
+    test(S(""), 0, S("1234567890"), 5, 1, S("6"));
+    test(S(""), 0, S("1234567890"), 5, 2, S("67"));
+    test(S(""), 0, S("1234567890"), 5, 4, S("6789"));
+    test(S(""), 0, S("1234567890"), 5, 5, S("67890"));
+    test(S(""), 0, S("1234567890"), 5, 6, S("67890"));
+    test(S(""), 0, S("1234567890"), 9, 0, S(""));
+    test(S(""), 0, S("1234567890"), 9, 1, S("0"));
+    test(S(""), 0, S("1234567890"), 9, 2, S("0"));
+    test(S(""), 0, S("1234567890"), 10, 0, S(""));
+    test(S(""), 0, S("1234567890"), 10, 1, S(""));
+    test(S(""), 0, S("1234567890"), 11, 0, S("can't happen"));
+}
+
+template <class S>
+void test1()
+{
+    test(S(""), 0, S("12345678901234567890"), 0, 0, S(""));
+    test(S(""), 0, S("12345678901234567890"), 0, 1, S("1"));
+    test(S(""), 0, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S(""), 0, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S(""), 0, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S(""), 0, S("12345678901234567890"), 1, 0, S(""));
+    test(S(""), 0, S("12345678901234567890"), 1, 1, S("2"));
+    test(S(""), 0, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S(""), 0, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S(""), 0, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S(""), 0, S("12345678901234567890"), 10, 0, S(""));
+    test(S(""), 0, S("12345678901234567890"), 10, 1, S("1"));
+    test(S(""), 0, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S(""), 0, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S(""), 0, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S(""), 0, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S(""), 0, S("12345678901234567890"), 19, 0, S(""));
+    test(S(""), 0, S("12345678901234567890"), 19, 1, S("0"));
+    test(S(""), 0, S("12345678901234567890"), 19, 2, S("0"));
+    test(S(""), 0, S("12345678901234567890"), 20, 0, S(""));
+    test(S(""), 0, S("12345678901234567890"), 20, 1, S(""));
+    test(S(""), 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S(""), 1, S(""), 0, 0, S("can't happen"));
+    test(S(""), 1, S(""), 0, 1, S("can't happen"));
+    test(S(""), 1, S(""), 1, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 1, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 2, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 4, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 5, S("can't happen"));
+    test(S(""), 1, S("12345"), 0, 6, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 1, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 2, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 3, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 4, S("can't happen"));
+    test(S(""), 1, S("12345"), 1, 5, S("can't happen"));
+    test(S(""), 1, S("12345"), 2, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 2, 1, S("can't happen"));
+    test(S(""), 1, S("12345"), 2, 2, S("can't happen"));
+    test(S(""), 1, S("12345"), 2, 3, S("can't happen"));
+    test(S(""), 1, S("12345"), 2, 4, S("can't happen"));
+    test(S(""), 1, S("12345"), 4, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 4, 1, S("can't happen"));
+    test(S(""), 1, S("12345"), 4, 2, S("can't happen"));
+    test(S(""), 1, S("12345"), 5, 0, S("can't happen"));
+    test(S(""), 1, S("12345"), 5, 1, S("can't happen"));
+    test(S(""), 1, S("12345"), 6, 0, S("can't happen"));
+}
+
+template <class S>
+void test2()
+{
+    test(S(""), 1, S("1234567890"), 0, 0, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 0, 1, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 0, 5, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 0, 9, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 0, 10, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 0, 11, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 0, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 1, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 4, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 8, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 9, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 1, 10, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 0, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 1, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 2, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 4, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 5, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 5, 6, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 9, 0, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 9, 1, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 9, 2, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 10, 0, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 10, 1, S("can't happen"));
+    test(S(""), 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S(""), 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 0, S(""), 0, 1, S("abcde"));
+}
+
+template <class S>
+void test3()
+{
+    test(S("abcde"), 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 0, 1, S("1abcde"));
+    test(S("abcde"), 0, S("12345"), 0, 2, S("12abcde"));
+    test(S("abcde"), 0, S("12345"), 0, 4, S("1234abcde"));
+    test(S("abcde"), 0, S("12345"), 0, 5, S("12345abcde"));
+    test(S("abcde"), 0, S("12345"), 0, 6, S("12345abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 2, S("23abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 3, S("234abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 4, S("2345abcde"));
+    test(S("abcde"), 0, S("12345"), 1, 5, S("2345abcde"));
+    test(S("abcde"), 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 2, 1, S("3abcde"));
+    test(S("abcde"), 0, S("12345"), 2, 2, S("34abcde"));
+    test(S("abcde"), 0, S("12345"), 2, 3, S("345abcde"));
+    test(S("abcde"), 0, S("12345"), 2, 4, S("345abcde"));
+    test(S("abcde"), 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 4, 1, S("5abcde"));
+    test(S("abcde"), 0, S("12345"), 4, 2, S("5abcde"));
+    test(S("abcde"), 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 0, 1, S("1abcde"));
+    test(S("abcde"), 0, S("1234567890"), 0, 5, S("12345abcde"));
+    test(S("abcde"), 0, S("1234567890"), 0, 9, S("123456789abcde"));
+    test(S("abcde"), 0, S("1234567890"), 0, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 0, 11, S("1234567890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 4, S("2345abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 8, S("23456789abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 9, S("234567890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 1, 10, S("234567890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 1, S("6abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 2, S("67abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 4, S("6789abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 5, S("67890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 5, 6, S("67890abcde"));
+    test(S("abcde"), 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 9, 1, S("0abcde"));
+    test(S("abcde"), 0, S("1234567890"), 9, 2, S("0abcde"));
+    test(S("abcde"), 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 1, S("1abcde"));
+}
+
+template <class S>
+void test4()
+{
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 9, S("234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 1, S("1abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 5, S("12345abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 9, S("123456789abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 10, 11, S("1234567890abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 19, 1, S("0abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 19, 2, S("0abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 1, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 0, 1, S("a1bcde"));
+    test(S("abcde"), 1, S("12345"), 0, 2, S("a12bcde"));
+    test(S("abcde"), 1, S("12345"), 0, 4, S("a1234bcde"));
+    test(S("abcde"), 1, S("12345"), 0, 5, S("a12345bcde"));
+    test(S("abcde"), 1, S("12345"), 0, 6, S("a12345bcde"));
+    test(S("abcde"), 1, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 1, 1, S("a2bcde"));
+    test(S("abcde"), 1, S("12345"), 1, 2, S("a23bcde"));
+    test(S("abcde"), 1, S("12345"), 1, 3, S("a234bcde"));
+    test(S("abcde"), 1, S("12345"), 1, 4, S("a2345bcde"));
+    test(S("abcde"), 1, S("12345"), 1, 5, S("a2345bcde"));
+    test(S("abcde"), 1, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 2, 1, S("a3bcde"));
+    test(S("abcde"), 1, S("12345"), 2, 2, S("a34bcde"));
+    test(S("abcde"), 1, S("12345"), 2, 3, S("a345bcde"));
+    test(S("abcde"), 1, S("12345"), 2, 4, S("a345bcde"));
+    test(S("abcde"), 1, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 4, 1, S("a5bcde"));
+    test(S("abcde"), 1, S("12345"), 4, 2, S("a5bcde"));
+    test(S("abcde"), 1, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 0, 1, S("a1bcde"));
+}
+
+template <class S>
+void test5()
+{
+    test(S("abcde"), 1, S("1234567890"), 0, 5, S("a12345bcde"));
+    test(S("abcde"), 1, S("1234567890"), 0, 9, S("a123456789bcde"));
+    test(S("abcde"), 1, S("1234567890"), 0, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 0, 11, S("a1234567890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 1, S("a2bcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 4, S("a2345bcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 8, S("a23456789bcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 9, S("a234567890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 1, 10, S("a234567890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 1, S("a6bcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 2, S("a67bcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 4, S("a6789bcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 5, S("a67890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 5, 6, S("a67890bcde"));
+    test(S("abcde"), 1, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 9, 1, S("a0bcde"));
+    test(S("abcde"), 1, S("1234567890"), 9, 2, S("a0bcde"));
+    test(S("abcde"), 1, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 1, S("a1bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 1, S("a2bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 9, S("a234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 18, S("a234567890123456789bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 1, S("a1bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 5, S("a12345bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 9, S("a123456789bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 10, 11, S("a1234567890bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 19, 1, S("a0bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 19, 2, S("a0bcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 2, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, S("12345"), 0, 0, S("abcde"));
+}
+
+template <class S>
+void test6()
+{
+    test(S("abcde"), 2, S("12345"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, S("12345"), 0, 2, S("ab12cde"));
+    test(S("abcde"), 2, S("12345"), 0, 4, S("ab1234cde"));
+    test(S("abcde"), 2, S("12345"), 0, 5, S("ab12345cde"));
+    test(S("abcde"), 2, S("12345"), 0, 6, S("ab12345cde"));
+    test(S("abcde"), 2, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, S("12345"), 1, 2, S("ab23cde"));
+    test(S("abcde"), 2, S("12345"), 1, 3, S("ab234cde"));
+    test(S("abcde"), 2, S("12345"), 1, 4, S("ab2345cde"));
+    test(S("abcde"), 2, S("12345"), 1, 5, S("ab2345cde"));
+    test(S("abcde"), 2, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345"), 2, 1, S("ab3cde"));
+    test(S("abcde"), 2, S("12345"), 2, 2, S("ab34cde"));
+    test(S("abcde"), 2, S("12345"), 2, 3, S("ab345cde"));
+    test(S("abcde"), 2, S("12345"), 2, 4, S("ab345cde"));
+    test(S("abcde"), 2, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345"), 4, 1, S("ab5cde"));
+    test(S("abcde"), 2, S("12345"), 4, 2, S("ab5cde"));
+    test(S("abcde"), 2, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, S("1234567890"), 0, 5, S("ab12345cde"));
+    test(S("abcde"), 2, S("1234567890"), 0, 9, S("ab123456789cde"));
+    test(S("abcde"), 2, S("1234567890"), 0, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, S("1234567890"), 0, 11, S("ab1234567890cde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 4, S("ab2345cde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 8, S("ab23456789cde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 9, S("ab234567890cde"));
+    test(S("abcde"), 2, S("1234567890"), 1, 10, S("ab234567890cde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 1, S("ab6cde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 2, S("ab67cde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 4, S("ab6789cde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 5, S("ab67890cde"));
+    test(S("abcde"), 2, S("1234567890"), 5, 6, S("ab67890cde"));
+    test(S("abcde"), 2, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 9, 1, S("ab0cde"));
+    test(S("abcde"), 2, S("1234567890"), 9, 2, S("ab0cde"));
+    test(S("abcde"), 2, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
+}
+
+template <class S>
+void test7()
+{
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 9, S("ab234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 18, S("ab234567890123456789cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 19, S("ab2345678901234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 1, 20, S("ab2345678901234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 1, S("ab1cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 5, S("ab12345cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 9, S("ab123456789cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 10, 11, S("ab1234567890cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 19, 1, S("ab0cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 19, 2, S("ab0cde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 4, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 4, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 4, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, S("12345"), 0, 2, S("abcd12e"));
+    test(S("abcde"), 4, S("12345"), 0, 4, S("abcd1234e"));
+    test(S("abcde"), 4, S("12345"), 0, 5, S("abcd12345e"));
+    test(S("abcde"), 4, S("12345"), 0, 6, S("abcd12345e"));
+    test(S("abcde"), 4, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, S("12345"), 1, 2, S("abcd23e"));
+    test(S("abcde"), 4, S("12345"), 1, 3, S("abcd234e"));
+    test(S("abcde"), 4, S("12345"), 1, 4, S("abcd2345e"));
+    test(S("abcde"), 4, S("12345"), 1, 5, S("abcd2345e"));
+    test(S("abcde"), 4, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 2, 1, S("abcd3e"));
+    test(S("abcde"), 4, S("12345"), 2, 2, S("abcd34e"));
+    test(S("abcde"), 4, S("12345"), 2, 3, S("abcd345e"));
+    test(S("abcde"), 4, S("12345"), 2, 4, S("abcd345e"));
+    test(S("abcde"), 4, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 4, 1, S("abcd5e"));
+    test(S("abcde"), 4, S("12345"), 4, 2, S("abcd5e"));
+    test(S("abcde"), 4, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 4, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, S("1234567890"), 0, 5, S("abcd12345e"));
+    test(S("abcde"), 4, S("1234567890"), 0, 9, S("abcd123456789e"));
+}
+
+template <class S>
+void test8()
+{
+    test(S("abcde"), 4, S("1234567890"), 0, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, S("1234567890"), 0, 11, S("abcd1234567890e"));
+    test(S("abcde"), 4, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, S("1234567890"), 1, 4, S("abcd2345e"));
+    test(S("abcde"), 4, S("1234567890"), 1, 8, S("abcd23456789e"));
+    test(S("abcde"), 4, S("1234567890"), 1, 9, S("abcd234567890e"));
+    test(S("abcde"), 4, S("1234567890"), 1, 10, S("abcd234567890e"));
+    test(S("abcde"), 4, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 5, 1, S("abcd6e"));
+    test(S("abcde"), 4, S("1234567890"), 5, 2, S("abcd67e"));
+    test(S("abcde"), 4, S("1234567890"), 5, 4, S("abcd6789e"));
+    test(S("abcde"), 4, S("1234567890"), 5, 5, S("abcd67890e"));
+    test(S("abcde"), 4, S("1234567890"), 5, 6, S("abcd67890e"));
+    test(S("abcde"), 4, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 9, 1, S("abcd0e"));
+    test(S("abcde"), 4, S("1234567890"), 9, 2, S("abcd0e"));
+    test(S("abcde"), 4, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 9, S("abcd234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 18, S("abcd234567890123456789e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 1, S("abcd1e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 5, S("abcd12345e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 9, S("abcd123456789e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 10, 11, S("abcd1234567890e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 19, 1, S("abcd0e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 19, 2, S("abcd0e"));
+    test(S("abcde"), 4, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 5, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 5, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 5, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, S("12345"), 0, 2, S("abcde12"));
+}
+
+template <class S>
+void test9()
+{
+    test(S("abcde"), 5, S("12345"), 0, 4, S("abcde1234"));
+    test(S("abcde"), 5, S("12345"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, S("12345"), 0, 6, S("abcde12345"));
+    test(S("abcde"), 5, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, S("12345"), 1, 2, S("abcde23"));
+    test(S("abcde"), 5, S("12345"), 1, 3, S("abcde234"));
+    test(S("abcde"), 5, S("12345"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, S("12345"), 1, 5, S("abcde2345"));
+    test(S("abcde"), 5, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 2, 1, S("abcde3"));
+    test(S("abcde"), 5, S("12345"), 2, 2, S("abcde34"));
+    test(S("abcde"), 5, S("12345"), 2, 3, S("abcde345"));
+    test(S("abcde"), 5, S("12345"), 2, 4, S("abcde345"));
+    test(S("abcde"), 5, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 4, 1, S("abcde5"));
+    test(S("abcde"), 5, S("12345"), 4, 2, S("abcde5"));
+    test(S("abcde"), 5, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 5, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, S("1234567890"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, S("1234567890"), 0, 9, S("abcde123456789"));
+    test(S("abcde"), 5, S("1234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, S("1234567890"), 0, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, S("1234567890"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, S("1234567890"), 1, 8, S("abcde23456789"));
+    test(S("abcde"), 5, S("1234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, S("1234567890"), 1, 10, S("abcde234567890"));
+    test(S("abcde"), 5, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 5, 1, S("abcde6"));
+    test(S("abcde"), 5, S("1234567890"), 5, 2, S("abcde67"));
+    test(S("abcde"), 5, S("1234567890"), 5, 4, S("abcde6789"));
+    test(S("abcde"), 5, S("1234567890"), 5, 5, S("abcde67890"));
+    test(S("abcde"), 5, S("1234567890"), 5, 6, S("abcde67890"));
+    test(S("abcde"), 5, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 9, 1, S("abcde0"));
+    test(S("abcde"), 5, S("1234567890"), 9, 2, S("abcde0"));
+    test(S("abcde"), 5, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
+}
+
+template <class S>
+void test10()
+{
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 1, S("abcde1"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 5, S("abcde12345"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 9, S("abcde123456789"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 19, 1, S("abcde0"));
+    test(S("abcde"), 5, S("12345678901234567890"), 19, 2, S("abcde0"));
+    test(S("abcde"), 5, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 6, S(""), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, S(""), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 0, 11, S("can't happen"));
+}
+
+template <class S>
+void test11()
+{
+    test(S("abcde"), 6, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 1, 10, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 5, 6, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcde"), 6, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcde"), 6, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 0, 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 0, 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 0, 5, S("12345abcdefghij"));
+}
+
+template <class S>
+void test12()
+{
+    test(S("abcdefghij"), 0, S("12345"), 0, 6, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 1, S("2abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 2, S("23abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 3, S("234abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 4, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 1, 5, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 2, 1, S("3abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 2, 2, S("34abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 2, 3, S("345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 2, 4, S("345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 4, 1, S("5abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 4, 2, S("5abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 0, 11, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 1, S("2abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 4, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 8, S("23456789abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 9, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 1, 10, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 1, S("6abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 2, S("67abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 4, S("6789abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 5, S("67890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 5, 6, S("67890abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 9, 1, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 9, 2, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 1, S("2abcdefghij"));
+}
+
+template <class S>
+void test13()
+{
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 19, 1, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 19, 2, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 0, 6, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 1, S("a2bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 2, S("a23bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 3, S("a234bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 4, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 1, 5, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 2, 1, S("a3bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 2, 2, S("a34bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 2, 3, S("a345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 2, 4, S("a345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 4, 1, S("a5bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 4, 2, S("a5bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 0, 11, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 1, S("a2bcdefghij"));
+}
+
+template <class S>
+void test14()
+{
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 4, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 8, S("a23456789bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 9, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 1, 10, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 1, S("a6bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 2, S("a67bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 4, S("a6789bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 5, S("a67890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 5, 6, S("a67890bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 9, 1, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 9, 2, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 1, S("a2bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 9, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 19, 1, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 19, 2, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 0, 6, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 1, 0, S("abcdefghij"));
+}
+
+template <class S>
+void test15()
+{
+    test(S("abcdefghij"), 5, S("12345"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 1, 2, S("abcde23fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 1, 3, S("abcde234fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 1, 4, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 1, 5, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), 2, 1, S("abcde3fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 2, 2, S("abcde34fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 2, 3, S("abcde345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 2, 4, S("abcde345fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), 4, 1, S("abcde5fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 4, 2, S("abcde5fghij"));
+    test(S("abcdefghij"), 5, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 0, 11, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 4, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 8, S("abcde23456789fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 9, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 1, 10, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 1, S("abcde6fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 2, S("abcde67fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 4, S("abcde6789fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 5, S("abcde67890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 5, 6, S("abcde67890fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 9, 1, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 9, 2, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
+}
+
+template <class S>
+void test16()
+{
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 10, 11, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 19, 1, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 19, 2, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("12345"), 0, 6, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 2, S("abcdefghi23j"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 3, S("abcdefghi234j"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 4, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, S("12345"), 1, 5, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 2, 1, S("abcdefghi3j"));
+    test(S("abcdefghij"), 9, S("12345"), 2, 2, S("abcdefghi34j"));
+    test(S("abcdefghij"), 9, S("12345"), 2, 3, S("abcdefghi345j"));
+    test(S("abcdefghij"), 9, S("12345"), 2, 4, S("abcdefghi345j"));
+    test(S("abcdefghij"), 9, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 4, 1, S("abcdefghi5j"));
+    test(S("abcdefghij"), 9, S("12345"), 4, 2, S("abcdefghi5j"));
+    test(S("abcdefghij"), 9, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 0, 11, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 4, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 8, S("abcdefghi23456789j"));
+}
+
+template <class S>
+void test17()
+{
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 9, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 1, 10, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 1, S("abcdefghi6j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 2, S("abcdefghi67j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 4, S("abcdefghi6789j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 5, S("abcdefghi67890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 5, 6, S("abcdefghi67890j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 9, 1, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 9, 2, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 9, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 19, 1, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 19, 2, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("12345"), 0, 6, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, S("12345"), 1, 2, S("abcdefghij23"));
+}
+
+template <class S>
+void test18()
+{
+    test(S("abcdefghij"), 10, S("12345"), 1, 3, S("abcdefghij234"));
+    test(S("abcdefghij"), 10, S("12345"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, S("12345"), 1, 5, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 2, 1, S("abcdefghij3"));
+    test(S("abcdefghij"), 10, S("12345"), 2, 2, S("abcdefghij34"));
+    test(S("abcdefghij"), 10, S("12345"), 2, 3, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, S("12345"), 2, 4, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 4, 1, S("abcdefghij5"));
+    test(S("abcdefghij"), 10, S("12345"), 4, 2, S("abcdefghij5"));
+    test(S("abcdefghij"), 10, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 8, S("abcdefghij23456789"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 1, 10, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 1, S("abcdefghij6"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 2, S("abcdefghij67"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 4, S("abcdefghij6789"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 5, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 5, 6, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 9, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, S("1234567890"), 9, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
+}
+
+template <class S>
+void test19()
+{
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S(""), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S(""), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 0, 11, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 1, 10, S("can't happen"));
+}
+
+template <class S>
+void test20()
+{
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 5, 6, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 0, 6, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test21()
+{
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 1, S("3abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 2, S("34abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 3, S("345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 2, 4, S("345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 4, 1, S("5abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 4, 2, S("5abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 0, 11, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 4, S("2345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 8, S("23456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 1, 10, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 1, S("6abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 2, S("67abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 4, S("6789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 5, S("67890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 5, 6, S("67890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 9, 1, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 9, 2, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test22()
+{
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 19, 1, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 19, 2, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 0, 6, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 2, S("a23bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 3, S("a234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 4, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 1, 5, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 2, 1, S("a3bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 2, 2, S("a34bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 2, 3, S("a345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 2, 4, S("a345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 4, 1, S("a5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 4, 2, S("a5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 0, 11, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 4, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 8, S("a23456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test23()
+{
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 5, S("a67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 5, 6, S("a67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 9, 1, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 9, 2, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 19, 1, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 19, 2, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, 6, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 2, S("abcdefghij23klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 3, S("abcdefghij234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test24()
+{
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 3, S("abcdefghij345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 2, 4, S("abcdefghij345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 4, 1, S("abcdefghij5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 4, 2, S("abcdefghij5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 0, 11, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 4, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 8, S("abcdefghij23456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 1, 10, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 1, S("abcdefghij6klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 2, S("abcdefghij67klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 4, S("abcdefghij6789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 5, S("abcdefghij67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 5, 6, S("abcdefghij67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 9, 1, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 9, 2, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
+}
+
+template <class S>
+void test25()
+{
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 19, 1, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 19, 2, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 2, S("abcdefghijklmnopqrs23t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 3, S("abcdefghijklmnopqrs234t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 2, 1, S("abcdefghijklmnopqrs3t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 2, 2, S("abcdefghijklmnopqrs34t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 2, 3, S("abcdefghijklmnopqrs345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 2, 4, S("abcdefghijklmnopqrs345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 4, 1, S("abcdefghijklmnopqrs5t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 4, 2, S("abcdefghijklmnopqrs5t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
+}
+
+template <class S>
+void test26()
+{
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
+}
+
+template <class S>
+void test27()
+{
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
+}
+
+template <class S>
+void test28()
+{
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S(""), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S(""), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 0, 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 1, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 5, 6, S("can't happen"));
+}
+
+template <class S>
+void test29()
+{
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 21, 0, S("can't happen"));
+}
+
+template <class S>
+void test30()
+{
+    test_npos(S(""), 0, S("12345678901234567890"),  0, S("12345678901234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"),  1, S( "2345678901234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"),  2, S(  "345678901234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"),  3, S(   "45678901234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"),  5, S(     "678901234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"), 10, S(          "1234567890"));
+    test_npos(S(""), 0, S("12345678901234567890"), 21, S("can't happen"));
+    test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, S("abcdefghij12345klmnopqrst"));
+    test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, S("abcdefghij2345klmnopqrst"));
+    test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 3, S("abcdefghij45klmnopqrst"));
+    test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 5, S("abcdefghijklmnopqrst"));
+    test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 6, S("can't happen"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    test9<S>();
+    test10<S>();
+    test11<S>();
+    test12<S>();
+    test13<S>();
+    test14<S>();
+    test15<S>();
+    test16<S>();
+    test17<S>();
+    test18<S>();
+    test19<S>();
+    test20<S>();
+    test21<S>();
+    test22<S>();
+    test23<S>();
+    test24<S>();
+    test25<S>();
+    test26<S>();
+    test27<S>();
+    test28<S>();
+    test29<S>();
+    test30<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    test9<S>();
+    test10<S>();
+    test11<S>();
+    test12<S>();
+    test13<S>();
+    test14<S>();
+    test15<S>();
+    test16<S>();
+    test17<S>();
+    test18<S>();
+    test19<S>();
+    test20<S>();
+    test21<S>();
+    test22<S>();
+    test23<S>();
+    test24<S>();
+    test25<S>();
+    test26<S>();
+    test27<S>();
+    test28<S>();
+    test29<S>();
+    test30<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -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>
+
+// basic_string<charT,traits,Allocator>& operator+=(charT c);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::value_type str, S expected)
+{
+    s += str;
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(), 'a', S("a"));
+    test(S("12345"), 'a', S("12345a"));
+    test(S("1234567890"), 'a', S("1234567890a"));
+    test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test(S(), 'a', S("a"));
+    test(S("12345"), 'a', S("12345a"));
+    test(S("1234567890"), 'a', S("1234567890a"));
+    test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& operator+=(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 += {'a', 'b', 'c'};
+        assert(s == "123abc");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s("123");
+        s += {'a', 'b', 'c'};
+        assert(s == "123abc");
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>& operator+=(const charT* s);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, const typename S::value_type* str, S expected)
+{
+    s += str;
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test(S(), "", S());
+    test(S(), "12345", S("12345"));
+    test(S(), "1234567890", S("1234567890"));
+    test(S(), "12345678901234567890", S("12345678901234567890"));
+
+    test(S("12345"), "", S("12345"));
+    test(S("12345"), "12345", S("1234512345"));
+    test(S("12345"), "1234567890", S("123451234567890"));
+    test(S("12345"), "12345678901234567890", S("1234512345678901234567890"));
+
+    test(S("1234567890"), "", S("1234567890"));
+    test(S("1234567890"), "12345", S("123456789012345"));
+    test(S("1234567890"), "1234567890", S("12345678901234567890"));
+    test(S("1234567890"), "12345678901234567890", S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), "", S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), "12345678901234567890",
+         S("1234567890123456789012345678901234567890"));
+    }
+#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(), "1234567890", S("1234567890"));
+    test(S(), "12345678901234567890", S("12345678901234567890"));
+
+    test(S("12345"), "", S("12345"));
+    test(S("12345"), "12345", S("1234512345"));
+    test(S("12345"), "1234567890", S("123451234567890"));
+    test(S("12345"), "12345678901234567890", S("1234512345678901234567890"));
+
+    test(S("1234567890"), "", S("1234567890"));
+    test(S("1234567890"), "12345", S("123456789012345"));
+    test(S("1234567890"), "1234567890", S("12345678901234567890"));
+    test(S("1234567890"), "12345678901234567890", S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), "", S("12345678901234567890"));
+    test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
+    test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), "12345678901234567890",
+         S("1234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   operator+=(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, S str, S expected)
+{
+    s += 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("12345"));
+    test(S("12345"), S("12345"), S("1234512345"));
+    test(S("12345"), S("1234567890"), S("123451234567890"));
+    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+    test(S("1234567890"), S(), S("1234567890"));
+    test(S("1234567890"), S("12345"), S("123456789012345"));
+    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("1234567890123456789012345678901234567890"));
+    }
+#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("12345"));
+    test(S("12345"), S("12345"), S("1234512345"));
+    test(S("12345"), S("1234567890"), S("123451234567890"));
+    test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
+
+    test(S("1234567890"), S(), S("1234567890"));
+    test(S("1234567890"), S("12345"), S("123456789012345"));
+    test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S("12345678901234567890"));
+    test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
+    test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("1234567890123456789012345678901234567890"));
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_initializer_list.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_initializer_list.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_initializer_list.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+    {
+        std::string s("123def456");
+        s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
+        assert(s == "123abc456");
+    }
+#if __cplusplus >= 201103L
+    {
+        typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+        S s("123def456");
+        s.replace(s.cbegin() + 3, s.cbegin() + 6, {'a', 'b', 'c'});
+        assert(s == "123abc456");
+    }
+#endif
+#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_iter_iter.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,976 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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&
+//   replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
+
+#include <string>
+#include <iterator>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S, class It>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, It f, It l, S expected)
+{
+    typename S::size_type old_size = s.size();
+    typename S::const_iterator first = s.begin() + pos1;
+    typename S::const_iterator last = s.begin() + pos1 + n1;
+    typename S::size_type xlen = last - first;
+    s.replace(first, last, f, l);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type rlen = std::distance(f, l);
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+const char* str = "12345678901234567890";
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, str, str+0, S(""));
+    test(S(""), 0, 0, str, str+0, S(""));
+    test(S(""), 0, 0, str, str+1, S("1"));
+    test(S(""), 0, 0, str, str+2, S("12"));
+    test(S(""), 0, 0, str, str+4, S("1234"));
+    test(S(""), 0, 0, str, str+5, S("12345"));
+    test(S(""), 0, 0, str, str+0, S(""));
+    test(S(""), 0, 0, str, str+1, S("1"));
+    test(S(""), 0, 0, str, str+5, S("12345"));
+    test(S(""), 0, 0, str, str+9, S("123456789"));
+    test(S(""), 0, 0, str, str+10, S("1234567890"));
+    test(S(""), 0, 0, str, str+0, S(""));
+    test(S(""), 0, 0, str, str+1, S("1"));
+    test(S(""), 0, 0, str, str+10, S("1234567890"));
+    test(S(""), 0, 0, str, str+19, S("1234567890123456789"));
+    test(S(""), 0, 0, str, str+20, S("12345678901234567890"));
+    test(S("abcde"), 0, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 0, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 0, 0, str, str+1, S("1abcde"));
+    test(S("abcde"), 0, 0, str, str+2, S("12abcde"));
+    test(S("abcde"), 0, 0, str, str+4, S("1234abcde"));
+    test(S("abcde"), 0, 0, str, str+5, S("12345abcde"));
+    test(S("abcde"), 0, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 0, 0, str, str+1, S("1abcde"));
+    test(S("abcde"), 0, 0, str, str+5, S("12345abcde"));
+    test(S("abcde"), 0, 0, str, str+9, S("123456789abcde"));
+    test(S("abcde"), 0, 0, str, str+10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 0, 0, str, str+1, S("1abcde"));
+    test(S("abcde"), 0, 0, str, str+10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, str, str+19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, 0, str, str+20, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, str, str+0, S("bcde"));
+    test(S("abcde"), 0, 1, str, str+0, S("bcde"));
+    test(S("abcde"), 0, 1, str, str+1, S("1bcde"));
+    test(S("abcde"), 0, 1, str, str+2, S("12bcde"));
+    test(S("abcde"), 0, 1, str, str+4, S("1234bcde"));
+    test(S("abcde"), 0, 1, str, str+5, S("12345bcde"));
+    test(S("abcde"), 0, 1, str, str+0, S("bcde"));
+    test(S("abcde"), 0, 1, str, str+1, S("1bcde"));
+    test(S("abcde"), 0, 1, str, str+5, S("12345bcde"));
+    test(S("abcde"), 0, 1, str, str+9, S("123456789bcde"));
+    test(S("abcde"), 0, 1, str, str+10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, str, str+0, S("bcde"));
+    test(S("abcde"), 0, 1, str, str+1, S("1bcde"));
+    test(S("abcde"), 0, 1, str, str+10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, str, str+19, S("1234567890123456789bcde"));
+    test(S("abcde"), 0, 1, str, str+20, S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, str, str+0, S("cde"));
+    test(S("abcde"), 0, 2, str, str+0, S("cde"));
+    test(S("abcde"), 0, 2, str, str+1, S("1cde"));
+    test(S("abcde"), 0, 2, str, str+2, S("12cde"));
+    test(S("abcde"), 0, 2, str, str+4, S("1234cde"));
+    test(S("abcde"), 0, 2, str, str+5, S("12345cde"));
+    test(S("abcde"), 0, 2, str, str+0, S("cde"));
+    test(S("abcde"), 0, 2, str, str+1, S("1cde"));
+    test(S("abcde"), 0, 2, str, str+5, S("12345cde"));
+    test(S("abcde"), 0, 2, str, str+9, S("123456789cde"));
+    test(S("abcde"), 0, 2, str, str+10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, str, str+0, S("cde"));
+    test(S("abcde"), 0, 2, str, str+1, S("1cde"));
+    test(S("abcde"), 0, 2, str, str+10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, str, str+19, S("1234567890123456789cde"));
+    test(S("abcde"), 0, 2, str, str+20, S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, str, str+0, S("e"));
+    test(S("abcde"), 0, 4, str, str+0, S("e"));
+    test(S("abcde"), 0, 4, str, str+1, S("1e"));
+    test(S("abcde"), 0, 4, str, str+2, S("12e"));
+    test(S("abcde"), 0, 4, str, str+4, S("1234e"));
+    test(S("abcde"), 0, 4, str, str+5, S("12345e"));
+    test(S("abcde"), 0, 4, str, str+0, S("e"));
+    test(S("abcde"), 0, 4, str, str+1, S("1e"));
+    test(S("abcde"), 0, 4, str, str+5, S("12345e"));
+    test(S("abcde"), 0, 4, str, str+9, S("123456789e"));
+    test(S("abcde"), 0, 4, str, str+10, S("1234567890e"));
+    test(S("abcde"), 0, 4, str, str+0, S("e"));
+    test(S("abcde"), 0, 4, str, str+1, S("1e"));
+    test(S("abcde"), 0, 4, str, str+10, S("1234567890e"));
+    test(S("abcde"), 0, 4, str, str+19, S("1234567890123456789e"));
+    test(S("abcde"), 0, 4, str, str+20, S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, str, str+0, S(""));
+    test(S("abcde"), 0, 5, str, str+0, S(""));
+    test(S("abcde"), 0, 5, str, str+1, S("1"));
+    test(S("abcde"), 0, 5, str, str+2, S("12"));
+    test(S("abcde"), 0, 5, str, str+4, S("1234"));
+    test(S("abcde"), 0, 5, str, str+5, S("12345"));
+    test(S("abcde"), 0, 5, str, str+0, S(""));
+    test(S("abcde"), 0, 5, str, str+1, S("1"));
+    test(S("abcde"), 0, 5, str, str+5, S("12345"));
+    test(S("abcde"), 0, 5, str, str+9, S("123456789"));
+    test(S("abcde"), 0, 5, str, str+10, S("1234567890"));
+    test(S("abcde"), 0, 5, str, str+0, S(""));
+    test(S("abcde"), 0, 5, str, str+1, S("1"));
+    test(S("abcde"), 0, 5, str, str+10, S("1234567890"));
+    test(S("abcde"), 0, 5, str, str+19, S("1234567890123456789"));
+    test(S("abcde"), 0, 5, str, str+20, S("12345678901234567890"));
+    test(S("abcde"), 1, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 1, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 1, 0, str, str+1, S("a1bcde"));
+    test(S("abcde"), 1, 0, str, str+2, S("a12bcde"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 1, 0, str, str+4, S("a1234bcde"));
+    test(S("abcde"), 1, 0, str, str+5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 1, 0, str, str+1, S("a1bcde"));
+    test(S("abcde"), 1, 0, str, str+5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, str, str+9, S("a123456789bcde"));
+    test(S("abcde"), 1, 0, str, str+10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 1, 0, str, str+1, S("a1bcde"));
+    test(S("abcde"), 1, 0, str, str+10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, str, str+19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, 0, str, str+20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, str, str+0, S("acde"));
+    test(S("abcde"), 1, 1, str, str+0, S("acde"));
+    test(S("abcde"), 1, 1, str, str+1, S("a1cde"));
+    test(S("abcde"), 1, 1, str, str+2, S("a12cde"));
+    test(S("abcde"), 1, 1, str, str+4, S("a1234cde"));
+    test(S("abcde"), 1, 1, str, str+5, S("a12345cde"));
+    test(S("abcde"), 1, 1, str, str+0, S("acde"));
+    test(S("abcde"), 1, 1, str, str+1, S("a1cde"));
+    test(S("abcde"), 1, 1, str, str+5, S("a12345cde"));
+    test(S("abcde"), 1, 1, str, str+9, S("a123456789cde"));
+    test(S("abcde"), 1, 1, str, str+10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, str, str+0, S("acde"));
+    test(S("abcde"), 1, 1, str, str+1, S("a1cde"));
+    test(S("abcde"), 1, 1, str, str+10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, str, str+19, S("a1234567890123456789cde"));
+    test(S("abcde"), 1, 1, str, str+20, S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, str, str+0, S("ade"));
+    test(S("abcde"), 1, 2, str, str+0, S("ade"));
+    test(S("abcde"), 1, 2, str, str+1, S("a1de"));
+    test(S("abcde"), 1, 2, str, str+2, S("a12de"));
+    test(S("abcde"), 1, 2, str, str+4, S("a1234de"));
+    test(S("abcde"), 1, 2, str, str+5, S("a12345de"));
+    test(S("abcde"), 1, 2, str, str+0, S("ade"));
+    test(S("abcde"), 1, 2, str, str+1, S("a1de"));
+    test(S("abcde"), 1, 2, str, str+5, S("a12345de"));
+    test(S("abcde"), 1, 2, str, str+9, S("a123456789de"));
+    test(S("abcde"), 1, 2, str, str+10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, str, str+0, S("ade"));
+    test(S("abcde"), 1, 2, str, str+1, S("a1de"));
+    test(S("abcde"), 1, 2, str, str+10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, str, str+19, S("a1234567890123456789de"));
+    test(S("abcde"), 1, 2, str, str+20, S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, str, str+0, S("ae"));
+    test(S("abcde"), 1, 3, str, str+0, S("ae"));
+    test(S("abcde"), 1, 3, str, str+1, S("a1e"));
+    test(S("abcde"), 1, 3, str, str+2, S("a12e"));
+    test(S("abcde"), 1, 3, str, str+4, S("a1234e"));
+    test(S("abcde"), 1, 3, str, str+5, S("a12345e"));
+    test(S("abcde"), 1, 3, str, str+0, S("ae"));
+    test(S("abcde"), 1, 3, str, str+1, S("a1e"));
+    test(S("abcde"), 1, 3, str, str+5, S("a12345e"));
+    test(S("abcde"), 1, 3, str, str+9, S("a123456789e"));
+    test(S("abcde"), 1, 3, str, str+10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, str, str+0, S("ae"));
+    test(S("abcde"), 1, 3, str, str+1, S("a1e"));
+    test(S("abcde"), 1, 3, str, str+10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, str, str+19, S("a1234567890123456789e"));
+    test(S("abcde"), 1, 3, str, str+20, S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, str, str+0, S("a"));
+    test(S("abcde"), 1, 4, str, str+0, S("a"));
+    test(S("abcde"), 1, 4, str, str+1, S("a1"));
+    test(S("abcde"), 1, 4, str, str+2, S("a12"));
+    test(S("abcde"), 1, 4, str, str+4, S("a1234"));
+    test(S("abcde"), 1, 4, str, str+5, S("a12345"));
+    test(S("abcde"), 1, 4, str, str+0, S("a"));
+    test(S("abcde"), 1, 4, str, str+1, S("a1"));
+    test(S("abcde"), 1, 4, str, str+5, S("a12345"));
+    test(S("abcde"), 1, 4, str, str+9, S("a123456789"));
+    test(S("abcde"), 1, 4, str, str+10, S("a1234567890"));
+    test(S("abcde"), 1, 4, str, str+0, S("a"));
+    test(S("abcde"), 1, 4, str, str+1, S("a1"));
+    test(S("abcde"), 1, 4, str, str+10, S("a1234567890"));
+    test(S("abcde"), 1, 4, str, str+19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 4, str, str+20, S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 2, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 2, 0, str, str+1, S("ab1cde"));
+    test(S("abcde"), 2, 0, str, str+2, S("ab12cde"));
+    test(S("abcde"), 2, 0, str, str+4, S("ab1234cde"));
+    test(S("abcde"), 2, 0, str, str+5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 2, 0, str, str+1, S("ab1cde"));
+    test(S("abcde"), 2, 0, str, str+5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, str, str+9, S("ab123456789cde"));
+    test(S("abcde"), 2, 0, str, str+10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 2, 0, str, str+1, S("ab1cde"));
+    test(S("abcde"), 2, 0, str, str+10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, str, str+19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, 0, str, str+20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, str, str+0, S("abde"));
+    test(S("abcde"), 2, 1, str, str+0, S("abde"));
+    test(S("abcde"), 2, 1, str, str+1, S("ab1de"));
+    test(S("abcde"), 2, 1, str, str+2, S("ab12de"));
+    test(S("abcde"), 2, 1, str, str+4, S("ab1234de"));
+    test(S("abcde"), 2, 1, str, str+5, S("ab12345de"));
+    test(S("abcde"), 2, 1, str, str+0, S("abde"));
+    test(S("abcde"), 2, 1, str, str+1, S("ab1de"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcde"), 2, 1, str, str+5, S("ab12345de"));
+    test(S("abcde"), 2, 1, str, str+9, S("ab123456789de"));
+    test(S("abcde"), 2, 1, str, str+10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, str, str+0, S("abde"));
+    test(S("abcde"), 2, 1, str, str+1, S("ab1de"));
+    test(S("abcde"), 2, 1, str, str+10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, str, str+19, S("ab1234567890123456789de"));
+    test(S("abcde"), 2, 1, str, str+20, S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, str, str+0, S("abe"));
+    test(S("abcde"), 2, 2, str, str+0, S("abe"));
+    test(S("abcde"), 2, 2, str, str+1, S("ab1e"));
+    test(S("abcde"), 2, 2, str, str+2, S("ab12e"));
+    test(S("abcde"), 2, 2, str, str+4, S("ab1234e"));
+    test(S("abcde"), 2, 2, str, str+5, S("ab12345e"));
+    test(S("abcde"), 2, 2, str, str+0, S("abe"));
+    test(S("abcde"), 2, 2, str, str+1, S("ab1e"));
+    test(S("abcde"), 2, 2, str, str+5, S("ab12345e"));
+    test(S("abcde"), 2, 2, str, str+9, S("ab123456789e"));
+    test(S("abcde"), 2, 2, str, str+10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, str, str+0, S("abe"));
+    test(S("abcde"), 2, 2, str, str+1, S("ab1e"));
+    test(S("abcde"), 2, 2, str, str+10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, str, str+19, S("ab1234567890123456789e"));
+    test(S("abcde"), 2, 2, str, str+20, S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, str, str+0, S("ab"));
+    test(S("abcde"), 2, 3, str, str+0, S("ab"));
+    test(S("abcde"), 2, 3, str, str+1, S("ab1"));
+    test(S("abcde"), 2, 3, str, str+2, S("ab12"));
+    test(S("abcde"), 2, 3, str, str+4, S("ab1234"));
+    test(S("abcde"), 2, 3, str, str+5, S("ab12345"));
+    test(S("abcde"), 2, 3, str, str+0, S("ab"));
+    test(S("abcde"), 2, 3, str, str+1, S("ab1"));
+    test(S("abcde"), 2, 3, str, str+5, S("ab12345"));
+    test(S("abcde"), 2, 3, str, str+9, S("ab123456789"));
+    test(S("abcde"), 2, 3, str, str+10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, str, str+0, S("ab"));
+    test(S("abcde"), 2, 3, str, str+1, S("ab1"));
+    test(S("abcde"), 2, 3, str, str+10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, str, str+19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 3, str, str+20, S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 4, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 4, 0, str, str+1, S("abcd1e"));
+    test(S("abcde"), 4, 0, str, str+2, S("abcd12e"));
+    test(S("abcde"), 4, 0, str, str+4, S("abcd1234e"));
+    test(S("abcde"), 4, 0, str, str+5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 4, 0, str, str+1, S("abcd1e"));
+    test(S("abcde"), 4, 0, str, str+5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, str, str+9, S("abcd123456789e"));
+    test(S("abcde"), 4, 0, str, str+10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 4, 0, str, str+1, S("abcd1e"));
+    test(S("abcde"), 4, 0, str, str+10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, str, str+19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, 0, str, str+20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, str, str+0, S("abcd"));
+    test(S("abcde"), 4, 1, str, str+0, S("abcd"));
+    test(S("abcde"), 4, 1, str, str+1, S("abcd1"));
+    test(S("abcde"), 4, 1, str, str+2, S("abcd12"));
+    test(S("abcde"), 4, 1, str, str+4, S("abcd1234"));
+    test(S("abcde"), 4, 1, str, str+5, S("abcd12345"));
+    test(S("abcde"), 4, 1, str, str+0, S("abcd"));
+    test(S("abcde"), 4, 1, str, str+1, S("abcd1"));
+    test(S("abcde"), 4, 1, str, str+5, S("abcd12345"));
+    test(S("abcde"), 4, 1, str, str+9, S("abcd123456789"));
+    test(S("abcde"), 4, 1, str, str+10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, str, str+0, S("abcd"));
+    test(S("abcde"), 4, 1, str, str+1, S("abcd1"));
+    test(S("abcde"), 4, 1, str, str+10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, str, str+19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 1, str, str+20, S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 5, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 5, 0, str, str+1, S("abcde1"));
+    test(S("abcde"), 5, 0, str, str+2, S("abcde12"));
+    test(S("abcde"), 5, 0, str, str+4, S("abcde1234"));
+    test(S("abcde"), 5, 0, str, str+5, S("abcde12345"));
+    test(S("abcde"), 5, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 5, 0, str, str+1, S("abcde1"));
+    test(S("abcde"), 5, 0, str, str+5, S("abcde12345"));
+    test(S("abcde"), 5, 0, str, str+9, S("abcde123456789"));
+    test(S("abcde"), 5, 0, str, str+10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, str, str+0, S("abcde"));
+    test(S("abcde"), 5, 0, str, str+1, S("abcde1"));
+    test(S("abcde"), 5, 0, str, str+10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, str, str+19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 0, str, str+20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 0, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+0, S("abcdefghij"));
+}
+
+template <class S>
+void test3()
+{
+    test(S("abcdefghij"), 0, 0, str, str+1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, str, str+20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+2, S("12bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+4, S("1234bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+9, S("123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+19, S("1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, str, str+20, S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, str, str+0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+2, S("12fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+4, S("1234fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+9, S("123456789fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+19, S("1234567890123456789fghij"));
+    test(S("abcdefghij"), 0, 5, str, str+20, S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, str, str+0, S("j"));
+    test(S("abcdefghij"), 0, 9, str, str+0, S("j"));
+    test(S("abcdefghij"), 0, 9, str, str+1, S("1j"));
+    test(S("abcdefghij"), 0, 9, str, str+2, S("12j"));
+    test(S("abcdefghij"), 0, 9, str, str+4, S("1234j"));
+    test(S("abcdefghij"), 0, 9, str, str+5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, str, str+0, S("j"));
+    test(S("abcdefghij"), 0, 9, str, str+1, S("1j"));
+    test(S("abcdefghij"), 0, 9, str, str+5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, str, str+9, S("123456789j"));
+    test(S("abcdefghij"), 0, 9, str, str+10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, str, str+0, S("j"));
+    test(S("abcdefghij"), 0, 9, str, str+1, S("1j"));
+    test(S("abcdefghij"), 0, 9, str, str+10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, str, str+19, S("1234567890123456789j"));
+    test(S("abcdefghij"), 0, 9, str, str+20, S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, str, str+0, S(""));
+    test(S("abcdefghij"), 0, 10, str, str+0, S(""));
+    test(S("abcdefghij"), 0, 10, str, str+1, S("1"));
+    test(S("abcdefghij"), 0, 10, str, str+2, S("12"));
+    test(S("abcdefghij"), 0, 10, str, str+4, S("1234"));
+    test(S("abcdefghij"), 0, 10, str, str+5, S("12345"));
+    test(S("abcdefghij"), 0, 10, str, str+0, S(""));
+    test(S("abcdefghij"), 0, 10, str, str+1, S("1"));
+    test(S("abcdefghij"), 0, 10, str, str+5, S("12345"));
+    test(S("abcdefghij"), 0, 10, str, str+9, S("123456789"));
+    test(S("abcdefghij"), 0, 10, str, str+10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, str, str+0, S(""));
+    test(S("abcdefghij"), 0, 10, str, str+1, S("1"));
+    test(S("abcdefghij"), 0, 10, str, str+10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, str, str+19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 10, str, str+20, S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, str, str+20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+2, S("a12cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+4, S("a1234cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+9, S("a123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+19, S("a1234567890123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, str, str+20, S("a12345678901234567890cdefghij"));
+}
+
+template <class S>
+void test4()
+{
+    test(S("abcdefghij"), 1, 4, str, str+0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, str, str+0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, str, str+1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+2, S("a12fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+4, S("a1234fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, str, str+1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+9, S("a123456789fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, str, str+1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+19, S("a1234567890123456789fghij"));
+    test(S("abcdefghij"), 1, 4, str, str+20, S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, str, str+0, S("aj"));
+    test(S("abcdefghij"), 1, 8, str, str+0, S("aj"));
+    test(S("abcdefghij"), 1, 8, str, str+1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, str, str+2, S("a12j"));
+    test(S("abcdefghij"), 1, 8, str, str+4, S("a1234j"));
+    test(S("abcdefghij"), 1, 8, str, str+5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, str, str+0, S("aj"));
+    test(S("abcdefghij"), 1, 8, str, str+1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, str, str+5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, str, str+9, S("a123456789j"));
+    test(S("abcdefghij"), 1, 8, str, str+10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, str, str+0, S("aj"));
+    test(S("abcdefghij"), 1, 8, str, str+1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, str, str+10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, str, str+19, S("a1234567890123456789j"));
+    test(S("abcdefghij"), 1, 8, str, str+20, S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, str, str+0, S("a"));
+    test(S("abcdefghij"), 1, 9, str, str+0, S("a"));
+    test(S("abcdefghij"), 1, 9, str, str+1, S("a1"));
+    test(S("abcdefghij"), 1, 9, str, str+2, S("a12"));
+    test(S("abcdefghij"), 1, 9, str, str+4, S("a1234"));
+    test(S("abcdefghij"), 1, 9, str, str+5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, str, str+0, S("a"));
+    test(S("abcdefghij"), 1, 9, str, str+1, S("a1"));
+    test(S("abcdefghij"), 1, 9, str, str+5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, str, str+9, S("a123456789"));
+    test(S("abcdefghij"), 1, 9, str, str+10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, str, str+0, S("a"));
+    test(S("abcdefghij"), 1, 9, str, str+1, S("a1"));
+    test(S("abcdefghij"), 1, 9, str, str+10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, str, str+19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 9, str, str+20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, str, str+1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, str, str+1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, str, str+1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, 0, str, str+20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, str, str+0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, str, str+0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, str, str+1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+2, S("abcde12ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+4, S("abcde1234ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, str, str+1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+9, S("abcde123456789ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, str, str+1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+19, S("abcde1234567890123456789ghij"));
+    test(S("abcdefghij"), 5, 1, str, str+20, S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, str, str+0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, str, str+0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, str, str+1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, str, str+2, S("abcde12hij"));
+    test(S("abcdefghij"), 5, 2, str, str+4, S("abcde1234hij"));
+    test(S("abcdefghij"), 5, 2, str, str+5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, str, str+0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, str, str+1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, str, str+5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, str, str+9, S("abcde123456789hij"));
+    test(S("abcdefghij"), 5, 2, str, str+10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, str, str+0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, str, str+1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, str, str+10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, str, str+19, S("abcde1234567890123456789hij"));
+    test(S("abcdefghij"), 5, 2, str, str+20, S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, str, str+0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, str, str+0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, str, str+1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, str, str+2, S("abcde12j"));
+}
+
+template <class S>
+void test5()
+{
+    test(S("abcdefghij"), 5, 4, str, str+4, S("abcde1234j"));
+    test(S("abcdefghij"), 5, 4, str, str+5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, str, str+0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, str, str+1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, str, str+5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, str, str+9, S("abcde123456789j"));
+    test(S("abcdefghij"), 5, 4, str, str+10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, str, str+0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, str, str+1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, str, str+10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, str, str+19, S("abcde1234567890123456789j"));
+    test(S("abcdefghij"), 5, 4, str, str+20, S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, str, str+0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, str, str+0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, str, str+1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, str, str+2, S("abcde12"));
+    test(S("abcdefghij"), 5, 5, str, str+4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 5, str, str+5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, str, str+0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, str, str+1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, str, str+5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, str, str+9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 5, str, str+10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, str, str+0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, str, str+1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, str, str+10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, str, str+19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 5, str, str+20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, str, str+1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, str, str+2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, 0, str, str+4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, 0, str, str+5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, str, str+1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, str, str+5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, str, str+9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, 0, str, str+10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, str, str+1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, str, str+10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, str, str+19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, 0, str, str+20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, str, str+0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, str, str+0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, str, str+1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, str, str+2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 1, str, str+4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 1, str, str+5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, str, str+0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, str, str+1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, str, str+5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, str, str+9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 1, str, str+10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, str, str+0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, str, str+1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, str, str+10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, str, str+19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 1, str, str+20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, str, str+2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 0, str, str+4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 0, str, str+5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, str, str+5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, str, str+9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 0, str, str+10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, str, str+0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, str, str+10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, str, str+19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 0, str, str+20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, str, str+20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+2, S("12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+4, S("1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+1, S("1bcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test6()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+9, S("123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+19, S("1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, str, str+20, S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+2, S("12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+4, S("1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+9, S("123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+19, S("1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, str, str+20, S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+2, S("12t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+4, S("1234t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+9, S("123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+19, S("1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, str, str+20, S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, str, str+20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, str, str+20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+2, S("a12cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+4, S("a1234cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+9, S("a123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+19, S("a1234567890123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, str, str+20, S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+2, S("a12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+4, S("a1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+9, S("a123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+0, S("aklmnopqrst"));
+}
+
+template <class S>
+void test7()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+19, S("a1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, str, str+20, S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+2, S("a12t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+4, S("a1234t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+9, S("a123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+19, S("a1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, str, str+20, S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, str, str+20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, str, str+20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+2, S("abcdefghij12lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+4, S("abcdefghij1234lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+9, S("abcdefghij123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+19, S("abcdefghij1234567890123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, str, str+20, S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+2, S("abcdefghij12pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+4, S("abcdefghij1234pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+9, S("abcdefghij123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+19, S("abcdefghij1234567890123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, str, str+20, S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+2, S("abcdefghij12t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+4, S("abcdefghij1234t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+9, S("abcdefghij123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+19, S("abcdefghij1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, str, str+20, S("abcdefghij12345678901234567890t"));
+}
+
+template <class S>
+void test8()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, str, str+20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, str, str+20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, str, str+20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, str, str+20, S("abcdefghijklmnopqrst12345678901234567890"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,285 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(const_iterator i1, const_iterator i2, const charT* s);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, const typename S::value_type* str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    typename S::const_iterator first = s.begin() + pos1;
+    typename S::const_iterator last = s.begin() + pos1 + n1;
+    typename S::size_type xlen = last - first;
+    s.replace(first, last, str);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type rlen = S::traits_type::length(str);
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, "", S(""));
+    test(S(""), 0, 0, "12345", S("12345"));
+    test(S(""), 0, 0, "1234567890", S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcde"), 0, 0, "", S("abcde"));
+    test(S("abcde"), 0, 0, "12345", S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, "", S("bcde"));
+    test(S("abcde"), 0, 1, "12345", S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, "", S("cde"));
+    test(S("abcde"), 0, 2, "12345", S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, "", S("e"));
+    test(S("abcde"), 0, 4, "12345", S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, "", S(""));
+    test(S("abcde"), 0, 5, "12345", S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcde"), 1, 0, "", S("abcde"));
+    test(S("abcde"), 1, 0, "12345", S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, "", S("acde"));
+    test(S("abcde"), 1, 1, "12345", S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, "", S("ade"));
+    test(S("abcde"), 1, 2, "12345", S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, "", S("ae"));
+    test(S("abcde"), 1, 3, "12345", S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, "", S("a"));
+    test(S("abcde"), 1, 4, "12345", S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, "", S("abcde"));
+    test(S("abcde"), 2, 0, "12345", S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, "", S("abde"));
+    test(S("abcde"), 2, 1, "12345", S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, "", S("abe"));
+    test(S("abcde"), 2, 2, "12345", S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, "", S("ab"));
+    test(S("abcde"), 2, 3, "12345", S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, "", S("abcde"));
+    test(S("abcde"), 4, 0, "12345", S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, "", S("abcd"));
+    test(S("abcde"), 4, 1, "12345", S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, "", S("abcde"));
+    test(S("abcde"), 5, 0, "12345", S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 0, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, "", S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, "", S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, "", S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, "", S(""));
+    test(S("abcdefghij"), 0, 10, "12345", S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, "", S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcdefghij"), 1, 4, "", S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, "", S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, "", S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, "", S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, "", S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, "", S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, "", S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, "", S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", S("abcdefghij12345678901234567890t"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_pointer_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,976 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, const typename S::value_type* str,
+     typename S::size_type n2, S expected)
+{
+    typename S::size_type old_size = s.size();
+    typename S::const_iterator first = s.begin() + pos1;
+    typename S::const_iterator last = s.begin() + pos1 + n1;
+    typename S::size_type xlen = last - first;
+    s.replace(first, last, str, n2);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type rlen = n2;
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, "", 0, S(""));
+    test(S(""), 0, 0, "12345", 0, S(""));
+    test(S(""), 0, 0, "12345", 1, S("1"));
+    test(S(""), 0, 0, "12345", 2, S("12"));
+    test(S(""), 0, 0, "12345", 4, S("1234"));
+    test(S(""), 0, 0, "12345", 5, S("12345"));
+    test(S(""), 0, 0, "1234567890", 0, S(""));
+    test(S(""), 0, 0, "1234567890", 1, S("1"));
+    test(S(""), 0, 0, "1234567890", 5, S("12345"));
+    test(S(""), 0, 0, "1234567890", 9, S("123456789"));
+    test(S(""), 0, 0, "1234567890", 10, S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", 0, S(""));
+    test(S(""), 0, 0, "12345678901234567890", 1, S("1"));
+    test(S(""), 0, 0, "12345678901234567890", 10, S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S(""), 0, 0, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcde"), 0, 0, "", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "12345", 2, S("12abcde"));
+    test(S("abcde"), 0, 0, "12345", 4, S("1234abcde"));
+    test(S("abcde"), 0, 0, "12345", 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 9, S("123456789abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, "", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "12345", 2, S("12bcde"));
+    test(S("abcde"), 0, 1, "12345", 4, S("1234bcde"));
+    test(S("abcde"), 0, 1, "12345", 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 9, S("123456789bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, "", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "12345", 2, S("12cde"));
+    test(S("abcde"), 0, 2, "12345", 4, S("1234cde"));
+    test(S("abcde"), 0, 2, "12345", 5, S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", 0, S("cde"));
+    test(S("abcde"), 0, 2, "1234567890", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "1234567890", 5, S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", 9, S("123456789cde"));
+    test(S("abcde"), 0, 2, "1234567890", 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 19, S("1234567890123456789cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 20, S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, "", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345", 1, S("1e"));
+    test(S("abcde"), 0, 4, "12345", 2, S("12e"));
+    test(S("abcde"), 0, 4, "12345", 4, S("1234e"));
+    test(S("abcde"), 0, 4, "12345", 5, S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", 0, S("e"));
+    test(S("abcde"), 0, 4, "1234567890", 1, S("1e"));
+    test(S("abcde"), 0, 4, "1234567890", 5, S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", 9, S("123456789e"));
+    test(S("abcde"), 0, 4, "1234567890", 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 1, S("1e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 19, S("1234567890123456789e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 20, S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, "", 0, S(""));
+    test(S("abcde"), 0, 5, "12345", 0, S(""));
+    test(S("abcde"), 0, 5, "12345", 1, S("1"));
+    test(S("abcde"), 0, 5, "12345", 2, S("12"));
+    test(S("abcde"), 0, 5, "12345", 4, S("1234"));
+    test(S("abcde"), 0, 5, "12345", 5, S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", 0, S(""));
+    test(S("abcde"), 0, 5, "1234567890", 1, S("1"));
+    test(S("abcde"), 0, 5, "1234567890", 5, S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", 9, S("123456789"));
+    test(S("abcde"), 0, 5, "1234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 0, S(""));
+    test(S("abcde"), 0, 5, "12345678901234567890", 1, S("1"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcde"), 1, 0, "", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "12345", 2, S("a12bcde"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 1, 0, "12345", 4, S("a1234bcde"));
+    test(S("abcde"), 1, 0, "12345", 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "1234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 9, S("a123456789bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, "", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "12345", 2, S("a12cde"));
+    test(S("abcde"), 1, 1, "12345", 4, S("a1234cde"));
+    test(S("abcde"), 1, 1, "12345", 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", 0, S("acde"));
+    test(S("abcde"), 1, 1, "1234567890", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "1234567890", 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", 9, S("a123456789cde"));
+    test(S("abcde"), 1, 1, "1234567890", 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, "", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "12345", 2, S("a12de"));
+    test(S("abcde"), 1, 2, "12345", 4, S("a1234de"));
+    test(S("abcde"), 1, 2, "12345", 5, S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", 0, S("ade"));
+    test(S("abcde"), 1, 2, "1234567890", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "1234567890", 5, S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", 9, S("a123456789de"));
+    test(S("abcde"), 1, 2, "1234567890", 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 19, S("a1234567890123456789de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 20, S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, "", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345", 1, S("a1e"));
+    test(S("abcde"), 1, 3, "12345", 2, S("a12e"));
+    test(S("abcde"), 1, 3, "12345", 4, S("a1234e"));
+    test(S("abcde"), 1, 3, "12345", 5, S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", 0, S("ae"));
+    test(S("abcde"), 1, 3, "1234567890", 1, S("a1e"));
+    test(S("abcde"), 1, 3, "1234567890", 5, S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", 9, S("a123456789e"));
+    test(S("abcde"), 1, 3, "1234567890", 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 1, S("a1e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 19, S("a1234567890123456789e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 20, S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, "", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345", 1, S("a1"));
+    test(S("abcde"), 1, 4, "12345", 2, S("a12"));
+    test(S("abcde"), 1, 4, "12345", 4, S("a1234"));
+    test(S("abcde"), 1, 4, "12345", 5, S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", 0, S("a"));
+    test(S("abcde"), 1, 4, "1234567890", 1, S("a1"));
+    test(S("abcde"), 1, 4, "1234567890", 5, S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", 9, S("a123456789"));
+    test(S("abcde"), 1, 4, "1234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 1, S("a1"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, "", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "12345", 2, S("ab12cde"));
+    test(S("abcde"), 2, 0, "12345", 4, S("ab1234cde"));
+    test(S("abcde"), 2, 0, "12345", 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "1234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "1234567890", 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", 9, S("ab123456789cde"));
+    test(S("abcde"), 2, 0, "1234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, "", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345", 1, S("ab1de"));
+    test(S("abcde"), 2, 1, "12345", 2, S("ab12de"));
+    test(S("abcde"), 2, 1, "12345", 4, S("ab1234de"));
+    test(S("abcde"), 2, 1, "12345", 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", 0, S("abde"));
+    test(S("abcde"), 2, 1, "1234567890", 1, S("ab1de"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcde"), 2, 1, "1234567890", 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", 9, S("ab123456789de"));
+    test(S("abcde"), 2, 1, "1234567890", 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 1, S("ab1de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 19, S("ab1234567890123456789de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 20, S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, "", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "12345", 2, S("ab12e"));
+    test(S("abcde"), 2, 2, "12345", 4, S("ab1234e"));
+    test(S("abcde"), 2, 2, "12345", 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", 0, S("abe"));
+    test(S("abcde"), 2, 2, "1234567890", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "1234567890", 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", 9, S("ab123456789e"));
+    test(S("abcde"), 2, 2, "1234567890", 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 19, S("ab1234567890123456789e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 20, S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, "", 0, S("ab"));
+    test(S("abcde"), 2, 3, "12345", 0, S("ab"));
+    test(S("abcde"), 2, 3, "12345", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "12345", 2, S("ab12"));
+    test(S("abcde"), 2, 3, "12345", 4, S("ab1234"));
+    test(S("abcde"), 2, 3, "12345", 5, S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", 0, S("ab"));
+    test(S("abcde"), 2, 3, "1234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "1234567890", 5, S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", 9, S("ab123456789"));
+    test(S("abcde"), 2, 3, "1234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 0, S("ab"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 20, S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, "", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "12345", 2, S("abcd12e"));
+    test(S("abcde"), 4, 0, "12345", 4, S("abcd1234e"));
+    test(S("abcde"), 4, 0, "12345", 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "1234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "1234567890", 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", 9, S("abcd123456789e"));
+    test(S("abcde"), 4, 0, "1234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, "", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "12345", 2, S("abcd12"));
+    test(S("abcde"), 4, 1, "12345", 4, S("abcd1234"));
+    test(S("abcde"), 4, 1, "12345", 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "1234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "1234567890", 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", 9, S("abcd123456789"));
+    test(S("abcde"), 4, 1, "1234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 20, S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, "", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "12345", 2, S("abcde12"));
+    test(S("abcde"), 5, 0, "12345", 4, S("abcde1234"));
+    test(S("abcde"), 5, 0, "12345", 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "1234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "1234567890", 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", 9, S("abcde123456789"));
+    test(S("abcde"), 5, 0, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 0, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 0, S("abcdefghij"));
+}
+
+template <class S>
+void test3()
+{
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, "", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 2, S("12bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 4, S("1234bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 9, S("123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, "", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 2, S("12fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 4, S("1234fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 9, S("123456789fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 19, S("1234567890123456789fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 20, S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, "", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "12345", 2, S("12j"));
+    test(S("abcdefghij"), 0, 9, "12345", 4, S("1234j"));
+    test(S("abcdefghij"), 0, 9, "12345", 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 9, S("123456789j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 19, S("1234567890123456789j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 20, S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, "", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "12345", 2, S("12"));
+    test(S("abcdefghij"), 0, 10, "12345", 4, S("1234"));
+    test(S("abcdefghij"), 0, 10, "12345", 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "1234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 9, S("123456789"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, "", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 2, S("a12cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 4, S("a1234cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 9, S("a123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghij"));
+}
+
+template <class S>
+void test4()
+{
+    test(S("abcdefghij"), 1, 4, "", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 2, S("a12fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 4, S("a1234fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 9, S("a123456789fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, "", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "12345", 2, S("a12j"));
+    test(S("abcdefghij"), 1, 8, "12345", 4, S("a1234j"));
+    test(S("abcdefghij"), 1, 8, "12345", 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 9, S("a123456789j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 19, S("a1234567890123456789j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 20, S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, "", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "12345", 2, S("a12"));
+    test(S("abcdefghij"), 1, 9, "12345", 4, S("a1234"));
+    test(S("abcdefghij"), 1, 9, "12345", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, "", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 2, S("abcde12ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 4, S("abcde1234ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 9, S("abcde123456789ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 19, S("abcde1234567890123456789ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 20, S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, "", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 2, S("abcde12hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 4, S("abcde1234hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 9, S("abcde123456789hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 19, S("abcde1234567890123456789hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 20, S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, "", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "12345", 2, S("abcde12j"));
+}
+
+template <class S>
+void test5()
+{
+    test(S("abcdefghij"), 5, 4, "12345", 4, S("abcde1234j"));
+    test(S("abcdefghij"), 5, 4, "12345", 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 9, S("abcde123456789j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 19, S("abcde1234567890123456789j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 20, S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, "", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "12345", 2, S("abcde12"));
+    test(S("abcdefghij"), 5, 5, "12345", 4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 5, "12345", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "12345", 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, 0, "12345", 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, 0, "12345", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, "", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "12345", 2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 1, "12345", 4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 1, "12345", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 0, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 0, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 2, S("12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 4, S("1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 1, S("1bcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test6()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 9, S("123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 2, S("12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 4, S("1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 9, S("123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 19, S("1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 20, S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 2, S("12t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 4, S("1234t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 9, S("123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 19, S("1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 20, S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 2, S("a12cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 4, S("a1234cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 9, S("a123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 2, S("a12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 4, S("a1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 9, S("a123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 0, S("aklmnopqrst"));
+}
+
+template <class S>
+void test7()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 2, S("a12t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 4, S("a1234t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 9, S("a123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 19, S("a1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 20, S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 2, S("abcdefghij12lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 4, S("abcdefghij1234lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 9, S("abcdefghij123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 19, S("abcdefghij1234567890123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 20, S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 2, S("abcdefghij12pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 4, S("abcdefghij1234pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 9, S("abcdefghij123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 19, S("abcdefghij1234567890123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 20, S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 2, S("abcdefghij12t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 4, S("abcdefghij1234t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 9, S("abcdefghij123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 19, S("abcdefghij1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 20, S("abcdefghij12345678901234567890t"));
+}
+
+template <class S>
+void test8()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,286 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(const_iterator i1, const_iterator i2, size_type n, charT c);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, typename S::size_type n2,
+     typename S::value_type c, S expected)
+{
+    typename S::size_type old_size = s.size();
+    typename S::const_iterator first = s.begin() + pos1;
+    typename S::const_iterator last = s.begin() + pos1 + n1;
+    typename S::size_type xlen = last - first;
+    s.replace(first, last, n2, c);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type rlen = n2;
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, 0, '3', S(""));
+    test(S(""), 0, 0, 5, '3', S("33333"));
+    test(S(""), 0, 0, 10, '3', S("3333333333"));
+    test(S(""), 0, 0, 20, '3', S("33333333333333333333"));
+    test(S("abcde"), 0, 0, 0, '3', S("abcde"));
+    test(S("abcde"), 0, 0, 5, '3', S("33333abcde"));
+    test(S("abcde"), 0, 0, 10, '3', S("3333333333abcde"));
+    test(S("abcde"), 0, 0, 20, '3', S("33333333333333333333abcde"));
+    test(S("abcde"), 0, 1, 0, '3', S("bcde"));
+    test(S("abcde"), 0, 1, 5, '3', S("33333bcde"));
+    test(S("abcde"), 0, 1, 10, '3', S("3333333333bcde"));
+    test(S("abcde"), 0, 1, 20, '3', S("33333333333333333333bcde"));
+    test(S("abcde"), 0, 2, 0, '3', S("cde"));
+    test(S("abcde"), 0, 2, 5, '3', S("33333cde"));
+    test(S("abcde"), 0, 2, 10, '3', S("3333333333cde"));
+    test(S("abcde"), 0, 2, 20, '3', S("33333333333333333333cde"));
+    test(S("abcde"), 0, 4, 0, '3', S("e"));
+    test(S("abcde"), 0, 4, 5, '3', S("33333e"));
+    test(S("abcde"), 0, 4, 10, '3', S("3333333333e"));
+    test(S("abcde"), 0, 4, 20, '3', S("33333333333333333333e"));
+    test(S("abcde"), 0, 5, 0, '3', S(""));
+    test(S("abcde"), 0, 5, 5, '3', S("33333"));
+    test(S("abcde"), 0, 5, 10, '3', S("3333333333"));
+    test(S("abcde"), 0, 5, 20, '3', S("33333333333333333333"));
+    test(S("abcde"), 1, 0, 0, '3', S("abcde"));
+    test(S("abcde"), 1, 0, 5, '3', S("a33333bcde"));
+    test(S("abcde"), 1, 0, 10, '3', S("a3333333333bcde"));
+    test(S("abcde"), 1, 0, 20, '3', S("a33333333333333333333bcde"));
+    test(S("abcde"), 1, 1, 0, '3', S("acde"));
+    test(S("abcde"), 1, 1, 5, '3', S("a33333cde"));
+    test(S("abcde"), 1, 1, 10, '3', S("a3333333333cde"));
+    test(S("abcde"), 1, 1, 20, '3', S("a33333333333333333333cde"));
+    test(S("abcde"), 1, 2, 0, '3', S("ade"));
+    test(S("abcde"), 1, 2, 5, '3', S("a33333de"));
+    test(S("abcde"), 1, 2, 10, '3', S("a3333333333de"));
+    test(S("abcde"), 1, 2, 20, '3', S("a33333333333333333333de"));
+    test(S("abcde"), 1, 3, 0, '3', S("ae"));
+    test(S("abcde"), 1, 3, 5, '3', S("a33333e"));
+    test(S("abcde"), 1, 3, 10, '3', S("a3333333333e"));
+    test(S("abcde"), 1, 3, 20, '3', S("a33333333333333333333e"));
+    test(S("abcde"), 1, 4, 0, '3', S("a"));
+    test(S("abcde"), 1, 4, 5, '3', S("a33333"));
+    test(S("abcde"), 1, 4, 10, '3', S("a3333333333"));
+    test(S("abcde"), 1, 4, 20, '3', S("a33333333333333333333"));
+    test(S("abcde"), 2, 0, 0, '3', S("abcde"));
+    test(S("abcde"), 2, 0, 5, '3', S("ab33333cde"));
+    test(S("abcde"), 2, 0, 10, '3', S("ab3333333333cde"));
+    test(S("abcde"), 2, 0, 20, '3', S("ab33333333333333333333cde"));
+    test(S("abcde"), 2, 1, 0, '3', S("abde"));
+    test(S("abcde"), 2, 1, 5, '3', S("ab33333de"));
+    test(S("abcde"), 2, 1, 10, '3', S("ab3333333333de"));
+    test(S("abcde"), 2, 1, 20, '3', S("ab33333333333333333333de"));
+    test(S("abcde"), 2, 2, 0, '3', S("abe"));
+    test(S("abcde"), 2, 2, 5, '3', S("ab33333e"));
+    test(S("abcde"), 2, 2, 10, '3', S("ab3333333333e"));
+    test(S("abcde"), 2, 2, 20, '3', S("ab33333333333333333333e"));
+    test(S("abcde"), 2, 3, 0, '3', S("ab"));
+    test(S("abcde"), 2, 3, 5, '3', S("ab33333"));
+    test(S("abcde"), 2, 3, 10, '3', S("ab3333333333"));
+    test(S("abcde"), 2, 3, 20, '3', S("ab33333333333333333333"));
+    test(S("abcde"), 4, 0, 0, '3', S("abcde"));
+    test(S("abcde"), 4, 0, 5, '3', S("abcd33333e"));
+    test(S("abcde"), 4, 0, 10, '3', S("abcd3333333333e"));
+    test(S("abcde"), 4, 0, 20, '3', S("abcd33333333333333333333e"));
+    test(S("abcde"), 4, 1, 0, '3', S("abcd"));
+    test(S("abcde"), 4, 1, 5, '3', S("abcd33333"));
+    test(S("abcde"), 4, 1, 10, '3', S("abcd3333333333"));
+    test(S("abcde"), 4, 1, 20, '3', S("abcd33333333333333333333"));
+    test(S("abcde"), 5, 0, 0, '3', S("abcde"));
+    test(S("abcde"), 5, 0, 5, '3', S("abcde33333"));
+    test(S("abcde"), 5, 0, 10, '3', S("abcde3333333333"));
+    test(S("abcde"), 5, 0, 20, '3', S("abcde33333333333333333333"));
+    test(S("abcdefghij"), 0, 0, 0, '3', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 5, '3', S("33333abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 10, '3', S("3333333333abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 20, '3', S("33333333333333333333abcdefghij"));
+    test(S("abcdefghij"), 0, 1, 0, '3', S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 5, '3', S("33333bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 10, '3', S("3333333333bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 20, '3', S("33333333333333333333bcdefghij"));
+    test(S("abcdefghij"), 0, 5, 0, '3', S("fghij"));
+    test(S("abcdefghij"), 0, 5, 5, '3', S("33333fghij"));
+    test(S("abcdefghij"), 0, 5, 10, '3', S("3333333333fghij"));
+    test(S("abcdefghij"), 0, 5, 20, '3', S("33333333333333333333fghij"));
+    test(S("abcdefghij"), 0, 9, 0, '3', S("j"));
+    test(S("abcdefghij"), 0, 9, 5, '3', S("33333j"));
+    test(S("abcdefghij"), 0, 9, 10, '3', S("3333333333j"));
+    test(S("abcdefghij"), 0, 9, 20, '3', S("33333333333333333333j"));
+    test(S("abcdefghij"), 0, 10, 0, '3', S(""));
+    test(S("abcdefghij"), 0, 10, 5, '3', S("33333"));
+    test(S("abcdefghij"), 0, 10, 10, '3', S("3333333333"));
+    test(S("abcdefghij"), 0, 10, 20, '3', S("33333333333333333333"));
+    test(S("abcdefghij"), 1, 0, 0, '3', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, 5, '3', S("a33333bcdefghij"));
+    test(S("abcdefghij"), 1, 0, 10, '3', S("a3333333333bcdefghij"));
+    test(S("abcdefghij"), 1, 0, 20, '3', S("a33333333333333333333bcdefghij"));
+    test(S("abcdefghij"), 1, 1, 0, '3', S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, 5, '3', S("a33333cdefghij"));
+    test(S("abcdefghij"), 1, 1, 10, '3', S("a3333333333cdefghij"));
+    test(S("abcdefghij"), 1, 1, 20, '3', S("a33333333333333333333cdefghij"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcdefghij"), 1, 4, 0, '3', S("afghij"));
+    test(S("abcdefghij"), 1, 4, 5, '3', S("a33333fghij"));
+    test(S("abcdefghij"), 1, 4, 10, '3', S("a3333333333fghij"));
+    test(S("abcdefghij"), 1, 4, 20, '3', S("a33333333333333333333fghij"));
+    test(S("abcdefghij"), 1, 8, 0, '3', S("aj"));
+    test(S("abcdefghij"), 1, 8, 5, '3', S("a33333j"));
+    test(S("abcdefghij"), 1, 8, 10, '3', S("a3333333333j"));
+    test(S("abcdefghij"), 1, 8, 20, '3', S("a33333333333333333333j"));
+    test(S("abcdefghij"), 1, 9, 0, '3', S("a"));
+    test(S("abcdefghij"), 1, 9, 5, '3', S("a33333"));
+    test(S("abcdefghij"), 1, 9, 10, '3', S("a3333333333"));
+    test(S("abcdefghij"), 1, 9, 20, '3', S("a33333333333333333333"));
+    test(S("abcdefghij"), 5, 0, 0, '3', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, 5, '3', S("abcde33333fghij"));
+    test(S("abcdefghij"), 5, 0, 10, '3', S("abcde3333333333fghij"));
+    test(S("abcdefghij"), 5, 0, 20, '3', S("abcde33333333333333333333fghij"));
+    test(S("abcdefghij"), 5, 1, 0, '3', S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, 5, '3', S("abcde33333ghij"));
+    test(S("abcdefghij"), 5, 1, 10, '3', S("abcde3333333333ghij"));
+    test(S("abcdefghij"), 5, 1, 20, '3', S("abcde33333333333333333333ghij"));
+    test(S("abcdefghij"), 5, 2, 0, '3', S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, 5, '3', S("abcde33333hij"));
+    test(S("abcdefghij"), 5, 2, 10, '3', S("abcde3333333333hij"));
+    test(S("abcdefghij"), 5, 2, 20, '3', S("abcde33333333333333333333hij"));
+    test(S("abcdefghij"), 5, 4, 0, '3', S("abcdej"));
+    test(S("abcdefghij"), 5, 4, 5, '3', S("abcde33333j"));
+    test(S("abcdefghij"), 5, 4, 10, '3', S("abcde3333333333j"));
+    test(S("abcdefghij"), 5, 4, 20, '3', S("abcde33333333333333333333j"));
+    test(S("abcdefghij"), 5, 5, 0, '3', S("abcde"));
+    test(S("abcdefghij"), 5, 5, 5, '3', S("abcde33333"));
+    test(S("abcdefghij"), 5, 5, 10, '3', S("abcde3333333333"));
+    test(S("abcdefghij"), 5, 5, 20, '3', S("abcde33333333333333333333"));
+    test(S("abcdefghij"), 9, 0, 0, '3', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, 5, '3', S("abcdefghi33333j"));
+    test(S("abcdefghij"), 9, 0, 10, '3', S("abcdefghi3333333333j"));
+    test(S("abcdefghij"), 9, 0, 20, '3', S("abcdefghi33333333333333333333j"));
+    test(S("abcdefghij"), 9, 1, 0, '3', S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, 5, '3', S("abcdefghi33333"));
+    test(S("abcdefghij"), 9, 1, 10, '3', S("abcdefghi3333333333"));
+    test(S("abcdefghij"), 9, 1, 20, '3', S("abcdefghi33333333333333333333"));
+    test(S("abcdefghij"), 10, 0, 0, '3', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, 5, '3', S("abcdefghij33333"));
+    test(S("abcdefghij"), 10, 0, 10, '3', S("abcdefghij3333333333"));
+    test(S("abcdefghij"), 10, 0, 20, '3', S("abcdefghij33333333333333333333"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 0, '3', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 5, '3', S("33333abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 10, '3', S("3333333333abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 20, '3', S("33333333333333333333abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 0, '3', S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 5, '3', S("33333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 10, '3', S("3333333333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 20, '3', S("33333333333333333333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 0, '3', S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 5, '3', S("33333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 10, '3', S("3333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 20, '3', S("33333333333333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 0, '3', S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 5, '3', S("33333t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 10, '3', S("3333333333t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 20, '3', S("33333333333333333333t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 0, '3', S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 5, '3', S("33333"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 10, '3', S("3333333333"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 20, '3', S("33333333333333333333"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 0, '3', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 5, '3', S("a33333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 10, '3', S("a3333333333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 20, '3', S("a33333333333333333333bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 0, '3', S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 5, '3', S("a33333cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 10, '3', S("a3333333333cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 20, '3', S("a33333333333333333333cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 0, '3', S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 5, '3', S("a33333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 10, '3', S("a3333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 20, '3', S("a33333333333333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 0, '3', S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 5, '3', S("a33333t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 10, '3', S("a3333333333t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 20, '3', S("a33333333333333333333t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 0, '3', S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 5, '3', S("a33333"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 10, '3', S("a3333333333"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 20, '3', S("a33333333333333333333"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 0, '3', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 5, '3', S("abcdefghij33333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 10, '3', S("abcdefghij3333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 20, '3', S("abcdefghij33333333333333333333klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 0, '3', S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 5, '3', S("abcdefghij33333lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 10, '3', S("abcdefghij3333333333lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 20, '3', S("abcdefghij33333333333333333333lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 0, '3', S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 5, '3', S("abcdefghij33333pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 10, '3', S("abcdefghij3333333333pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 20, '3', S("abcdefghij33333333333333333333pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 0, '3', S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 5, '3', S("abcdefghij33333t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 10, '3', S("abcdefghij3333333333t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 20, '3', S("abcdefghij33333333333333333333t"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, 0, '3', S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 5, '3', S("abcdefghij33333"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 10, '3', S("abcdefghij3333333333"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 20, '3', S("abcdefghij33333333333333333333"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 0, '3', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 5, '3', S("abcdefghijklmnopqrs33333t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 10, '3', S("abcdefghijklmnopqrs3333333333t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 20, '3', S("abcdefghijklmnopqrs33333333333333333333t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 0, '3', S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 5, '3', S("abcdefghijklmnopqrs33333"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 10, '3', S("abcdefghijklmnopqrs3333333333"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 20, '3', S("abcdefghijklmnopqrs33333333333333333333"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 0, '3', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 5, '3', S("abcdefghijklmnopqrst33333"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 10, '3', S("abcdefghijklmnopqrst3333333333"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 20, '3', S("abcdefghijklmnopqrst33333333333333333333"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/iter_iter_string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,285 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(const_iterator i1, const_iterator i2, const basic_string& str);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    typename S::const_iterator first = s.begin() + pos1;
+    typename S::const_iterator last = s.begin() + pos1 + n1;
+    typename S::size_type xlen = last - first;
+    s.replace(first, last, str);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type rlen = str.size();
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, S(""), S(""));
+    test(S(""), 0, 0, S("12345"), S("12345"));
+    test(S(""), 0, 0, S("1234567890"), S("1234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcde"), 0, 0, S(""), S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), S("12345abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, S(""), S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), S("12345bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, S(""), S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), S("12345cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, S(""), S("e"));
+    test(S("abcde"), 0, 4, S("12345"), S("12345e"));
+    test(S("abcde"), 0, 4, S("1234567890"), S("1234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, S(""), S(""));
+    test(S("abcde"), 0, 5, S("12345"), S("12345"));
+    test(S("abcde"), 0, 5, S("1234567890"), S("1234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcde"), 1, 0, S(""), S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, S(""), S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), S("a12345cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, S(""), S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), S("a12345de"));
+    test(S("abcde"), 1, 2, S("1234567890"), S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, S(""), S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), S("a12345e"));
+    test(S("abcde"), 1, 3, S("1234567890"), S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, S(""), S("a"));
+    test(S("abcde"), 1, 4, S("12345"), S("a12345"));
+    test(S("abcde"), 1, 4, S("1234567890"), S("a1234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, S(""), S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, S(""), S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), S("ab12345de"));
+    test(S("abcde"), 2, 1, S("1234567890"), S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, S(""), S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), S("ab12345e"));
+    test(S("abcde"), 2, 2, S("1234567890"), S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, S(""), S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), S("ab12345"));
+    test(S("abcde"), 2, 3, S("1234567890"), S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, S(""), S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("1234567890"), S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, S(""), S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), S("abcd12345"));
+    test(S("abcde"), 4, 1, S("1234567890"), S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, S(""), S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), S("abcde12345"));
+    test(S("abcde"), 5, 0, S("1234567890"), S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 0, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S(""), S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S(""), S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, S(""), S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, S(""), S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), S("12345"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, S(""), S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghij"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcdefghij"), 1, 4, S(""), S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, S(""), S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, S(""), S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, S(""), S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, S(""), S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, S(""), S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, S(""), S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, S(""), S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), S("abcdefghij12345678901234567890t"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,375 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(size_type pos, size_type n1, const charT* s);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, typename S::size_type n1,
+     const typename S::value_type* str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.replace(pos, n1, str);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+        typename S::size_type xlen = std::min(n1, old_size - pos);
+        typename S::size_type rlen = S::traits_type::length(str);
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, "", S(""));
+    test(S(""), 0, 0, "12345", S("12345"));
+    test(S(""), 0, 0, "1234567890", S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", S("12345678901234567890"));
+    test(S(""), 0, 1, "", S(""));
+    test(S(""), 0, 1, "12345", S("12345"));
+    test(S(""), 0, 1, "1234567890", S("1234567890"));
+    test(S(""), 0, 1, "12345678901234567890", S("12345678901234567890"));
+    test(S(""), 1, 0, "", S("can't happen"));
+    test(S(""), 1, 0, "12345", S("can't happen"));
+    test(S(""), 1, 0, "1234567890", S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", S("can't happen"));
+    test(S("abcde"), 0, 0, "", S("abcde"));
+    test(S("abcde"), 0, 0, "12345", S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, "", S("bcde"));
+    test(S("abcde"), 0, 1, "12345", S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, "", S("cde"));
+    test(S("abcde"), 0, 2, "12345", S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, "", S("e"));
+    test(S("abcde"), 0, 4, "12345", S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, "", S(""));
+    test(S("abcde"), 0, 5, "12345", S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcde"), 0, 6, "", S(""));
+    test(S("abcde"), 0, 6, "12345", S("12345"));
+    test(S("abcde"), 0, 6, "1234567890", S("1234567890"));
+    test(S("abcde"), 0, 6, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcde"), 1, 0, "", S("abcde"));
+    test(S("abcde"), 1, 0, "12345", S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, "", S("acde"));
+    test(S("abcde"), 1, 1, "12345", S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, "", S("ade"));
+    test(S("abcde"), 1, 2, "12345", S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, "", S("ae"));
+    test(S("abcde"), 1, 3, "12345", S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, "", S("a"));
+    test(S("abcde"), 1, 4, "12345", S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcde"), 1, 5, "", S("a"));
+    test(S("abcde"), 1, 5, "12345", S("a12345"));
+    test(S("abcde"), 1, 5, "1234567890", S("a1234567890"));
+    test(S("abcde"), 1, 5, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, "", S("abcde"));
+    test(S("abcde"), 2, 0, "12345", S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, "", S("abde"));
+    test(S("abcde"), 2, 1, "12345", S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, "", S("abe"));
+    test(S("abcde"), 2, 2, "12345", S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, "", S("ab"));
+    test(S("abcde"), 2, 3, "12345", S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", S("ab12345678901234567890"));
+    test(S("abcde"), 2, 4, "", S("ab"));
+    test(S("abcde"), 2, 4, "12345", S("ab12345"));
+    test(S("abcde"), 2, 4, "1234567890", S("ab1234567890"));
+    test(S("abcde"), 2, 4, "12345678901234567890", S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, "", S("abcde"));
+    test(S("abcde"), 4, 0, "12345", S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, "", S("abcd"));
+    test(S("abcde"), 4, 1, "12345", S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 2, "", S("abcd"));
+    test(S("abcde"), 4, 2, "12345", S("abcd12345"));
+    test(S("abcde"), 4, 2, "1234567890", S("abcd1234567890"));
+    test(S("abcde"), 4, 2, "12345678901234567890", S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, "", S("abcde"));
+    test(S("abcde"), 5, 0, "12345", S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 1, "", S("abcde"));
+    test(S("abcde"), 5, 1, "12345", S("abcde12345"));
+    test(S("abcde"), 5, 1, "1234567890", S("abcde1234567890"));
+    test(S("abcde"), 5, 1, "12345678901234567890", S("abcde12345678901234567890"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 6, 0, "", S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", S("can't happen"));
+    test(S("abcdefghij"), 0, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, "", S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, "", S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, "", S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, "", S(""));
+    test(S("abcdefghij"), 0, 10, "12345", S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 11, "", S(""));
+    test(S("abcdefghij"), 0, 11, "12345", S("12345"));
+    test(S("abcdefghij"), 0, 11, "1234567890", S("1234567890"));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, "", S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 4, "", S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, "", S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, "", S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 10, "", S("a"));
+    test(S("abcdefghij"), 1, 10, "12345", S("a12345"));
+    test(S("abcdefghij"), 1, 10, "1234567890", S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, "", S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, "", S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, "", S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, "", S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 6, "", S("abcde"));
+    test(S("abcdefghij"), 5, 6, "12345", S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, "1234567890", S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, "", S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 2, "", S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, "12345", S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, "1234567890", S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, "", S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 1, "", S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, "12345", S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, 0, "", S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", S("can't happen"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "", S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "", S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", S("abcdefghij12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "", S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "", S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "", S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", S("can't happen"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_pointer_size.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,1327 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(size_type pos, size_type n1, const charT* s, size_type n2);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, typename S::size_type n1,
+     const typename S::value_type* str, typename S::size_type n2,
+     S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.replace(pos, n1, str, n2);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+        typename S::size_type xlen = std::min(n1, old_size - pos);
+        typename S::size_type rlen = n2;
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, "", 0, S(""));
+    test(S(""), 0, 0, "12345", 0, S(""));
+    test(S(""), 0, 0, "12345", 1, S("1"));
+    test(S(""), 0, 0, "12345", 2, S("12"));
+    test(S(""), 0, 0, "12345", 4, S("1234"));
+    test(S(""), 0, 0, "12345", 5, S("12345"));
+    test(S(""), 0, 0, "1234567890", 0, S(""));
+    test(S(""), 0, 0, "1234567890", 1, S("1"));
+    test(S(""), 0, 0, "1234567890", 5, S("12345"));
+    test(S(""), 0, 0, "1234567890", 9, S("123456789"));
+    test(S(""), 0, 0, "1234567890", 10, S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", 0, S(""));
+    test(S(""), 0, 0, "12345678901234567890", 1, S("1"));
+    test(S(""), 0, 0, "12345678901234567890", 10, S("1234567890"));
+    test(S(""), 0, 0, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S(""), 0, 0, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S(""), 0, 1, "", 0, S(""));
+    test(S(""), 0, 1, "12345", 0, S(""));
+    test(S(""), 0, 1, "12345", 1, S("1"));
+    test(S(""), 0, 1, "12345", 2, S("12"));
+    test(S(""), 0, 1, "12345", 4, S("1234"));
+    test(S(""), 0, 1, "12345", 5, S("12345"));
+    test(S(""), 0, 1, "1234567890", 0, S(""));
+    test(S(""), 0, 1, "1234567890", 1, S("1"));
+    test(S(""), 0, 1, "1234567890", 5, S("12345"));
+    test(S(""), 0, 1, "1234567890", 9, S("123456789"));
+    test(S(""), 0, 1, "1234567890", 10, S("1234567890"));
+    test(S(""), 0, 1, "12345678901234567890", 0, S(""));
+    test(S(""), 0, 1, "12345678901234567890", 1, S("1"));
+    test(S(""), 0, 1, "12345678901234567890", 10, S("1234567890"));
+    test(S(""), 0, 1, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S(""), 0, 1, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S(""), 1, 0, "", 0, S("can't happen"));
+    test(S(""), 1, 0, "12345", 0, S("can't happen"));
+    test(S(""), 1, 0, "12345", 1, S("can't happen"));
+    test(S(""), 1, 0, "12345", 2, S("can't happen"));
+    test(S(""), 1, 0, "12345", 4, S("can't happen"));
+    test(S(""), 1, 0, "12345", 5, S("can't happen"));
+    test(S(""), 1, 0, "1234567890", 0, S("can't happen"));
+    test(S(""), 1, 0, "1234567890", 1, S("can't happen"));
+    test(S(""), 1, 0, "1234567890", 5, S("can't happen"));
+    test(S(""), 1, 0, "1234567890", 9, S("can't happen"));
+    test(S(""), 1, 0, "1234567890", 10, S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", 0, S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", 1, S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", 10, S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", 19, S("can't happen"));
+    test(S(""), 1, 0, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcde"), 0, 0, "", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "12345", 2, S("12abcde"));
+    test(S("abcde"), 0, 0, "12345", 4, S("1234abcde"));
+    test(S("abcde"), 0, 0, "12345", 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 9, S("123456789abcde"));
+    test(S("abcde"), 0, 0, "1234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 1, S("1abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, "", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "12345", 2, S("12bcde"));
+    test(S("abcde"), 0, 1, "12345", 4, S("1234bcde"));
+    test(S("abcde"), 0, 1, "12345", 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 9, S("123456789bcde"));
+    test(S("abcde"), 0, 1, "1234567890", 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 0, S("bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 1, S("1bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcde"));
+    test(S("abcde"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, "", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "12345", 2, S("12cde"));
+    test(S("abcde"), 0, 2, "12345", 4, S("1234cde"));
+    test(S("abcde"), 0, 2, "12345", 5, S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", 0, S("cde"));
+    test(S("abcde"), 0, 2, "1234567890", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "1234567890", 5, S("12345cde"));
+    test(S("abcde"), 0, 2, "1234567890", 9, S("123456789cde"));
+    test(S("abcde"), 0, 2, "1234567890", 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 0, S("cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 1, S("1cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 19, S("1234567890123456789cde"));
+    test(S("abcde"), 0, 2, "12345678901234567890", 20, S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, "", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345", 1, S("1e"));
+    test(S("abcde"), 0, 4, "12345", 2, S("12e"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 0, 4, "12345", 4, S("1234e"));
+    test(S("abcde"), 0, 4, "12345", 5, S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", 0, S("e"));
+    test(S("abcde"), 0, 4, "1234567890", 1, S("1e"));
+    test(S("abcde"), 0, 4, "1234567890", 5, S("12345e"));
+    test(S("abcde"), 0, 4, "1234567890", 9, S("123456789e"));
+    test(S("abcde"), 0, 4, "1234567890", 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 0, S("e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 1, S("1e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 19, S("1234567890123456789e"));
+    test(S("abcde"), 0, 4, "12345678901234567890", 20, S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, "", 0, S(""));
+    test(S("abcde"), 0, 5, "12345", 0, S(""));
+    test(S("abcde"), 0, 5, "12345", 1, S("1"));
+    test(S("abcde"), 0, 5, "12345", 2, S("12"));
+    test(S("abcde"), 0, 5, "12345", 4, S("1234"));
+    test(S("abcde"), 0, 5, "12345", 5, S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", 0, S(""));
+    test(S("abcde"), 0, 5, "1234567890", 1, S("1"));
+    test(S("abcde"), 0, 5, "1234567890", 5, S("12345"));
+    test(S("abcde"), 0, 5, "1234567890", 9, S("123456789"));
+    test(S("abcde"), 0, 5, "1234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 0, S(""));
+    test(S("abcde"), 0, 5, "12345678901234567890", 1, S("1"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcde"), 0, 5, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcde"), 0, 6, "", 0, S(""));
+    test(S("abcde"), 0, 6, "12345", 0, S(""));
+    test(S("abcde"), 0, 6, "12345", 1, S("1"));
+    test(S("abcde"), 0, 6, "12345", 2, S("12"));
+    test(S("abcde"), 0, 6, "12345", 4, S("1234"));
+    test(S("abcde"), 0, 6, "12345", 5, S("12345"));
+    test(S("abcde"), 0, 6, "1234567890", 0, S(""));
+    test(S("abcde"), 0, 6, "1234567890", 1, S("1"));
+    test(S("abcde"), 0, 6, "1234567890", 5, S("12345"));
+    test(S("abcde"), 0, 6, "1234567890", 9, S("123456789"));
+    test(S("abcde"), 0, 6, "1234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 6, "12345678901234567890", 0, S(""));
+    test(S("abcde"), 0, 6, "12345678901234567890", 1, S("1"));
+    test(S("abcde"), 0, 6, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcde"), 0, 6, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcde"), 0, 6, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcde"), 1, 0, "", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "12345", 2, S("a12bcde"));
+    test(S("abcde"), 1, 0, "12345", 4, S("a1234bcde"));
+    test(S("abcde"), 1, 0, "12345", 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "1234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 9, S("a123456789bcde"));
+    test(S("abcde"), 1, 0, "1234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, "", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "12345", 2, S("a12cde"));
+    test(S("abcde"), 1, 1, "12345", 4, S("a1234cde"));
+    test(S("abcde"), 1, 1, "12345", 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", 0, S("acde"));
+    test(S("abcde"), 1, 1, "1234567890", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "1234567890", 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, "1234567890", 9, S("a123456789cde"));
+    test(S("abcde"), 1, 1, "1234567890", 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 0, S("acde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 1, S("a1cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cde"));
+    test(S("abcde"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, "", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "12345", 2, S("a12de"));
+    test(S("abcde"), 1, 2, "12345", 4, S("a1234de"));
+    test(S("abcde"), 1, 2, "12345", 5, S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", 0, S("ade"));
+    test(S("abcde"), 1, 2, "1234567890", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "1234567890", 5, S("a12345de"));
+    test(S("abcde"), 1, 2, "1234567890", 9, S("a123456789de"));
+    test(S("abcde"), 1, 2, "1234567890", 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 0, S("ade"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 1, S("a1de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 19, S("a1234567890123456789de"));
+    test(S("abcde"), 1, 2, "12345678901234567890", 20, S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, "", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345", 1, S("a1e"));
+    test(S("abcde"), 1, 3, "12345", 2, S("a12e"));
+    test(S("abcde"), 1, 3, "12345", 4, S("a1234e"));
+    test(S("abcde"), 1, 3, "12345", 5, S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", 0, S("ae"));
+    test(S("abcde"), 1, 3, "1234567890", 1, S("a1e"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcde"), 1, 3, "1234567890", 5, S("a12345e"));
+    test(S("abcde"), 1, 3, "1234567890", 9, S("a123456789e"));
+    test(S("abcde"), 1, 3, "1234567890", 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 0, S("ae"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 1, S("a1e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 19, S("a1234567890123456789e"));
+    test(S("abcde"), 1, 3, "12345678901234567890", 20, S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, "", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345", 1, S("a1"));
+    test(S("abcde"), 1, 4, "12345", 2, S("a12"));
+    test(S("abcde"), 1, 4, "12345", 4, S("a1234"));
+    test(S("abcde"), 1, 4, "12345", 5, S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", 0, S("a"));
+    test(S("abcde"), 1, 4, "1234567890", 1, S("a1"));
+    test(S("abcde"), 1, 4, "1234567890", 5, S("a12345"));
+    test(S("abcde"), 1, 4, "1234567890", 9, S("a123456789"));
+    test(S("abcde"), 1, 4, "1234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 0, S("a"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 1, S("a1"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcde"), 1, 5, "", 0, S("a"));
+    test(S("abcde"), 1, 5, "12345", 0, S("a"));
+    test(S("abcde"), 1, 5, "12345", 1, S("a1"));
+    test(S("abcde"), 1, 5, "12345", 2, S("a12"));
+    test(S("abcde"), 1, 5, "12345", 4, S("a1234"));
+    test(S("abcde"), 1, 5, "12345", 5, S("a12345"));
+    test(S("abcde"), 1, 5, "1234567890", 0, S("a"));
+    test(S("abcde"), 1, 5, "1234567890", 1, S("a1"));
+    test(S("abcde"), 1, 5, "1234567890", 5, S("a12345"));
+    test(S("abcde"), 1, 5, "1234567890", 9, S("a123456789"));
+    test(S("abcde"), 1, 5, "1234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 5, "12345678901234567890", 0, S("a"));
+    test(S("abcde"), 1, 5, "12345678901234567890", 1, S("a1"));
+    test(S("abcde"), 1, 5, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcde"), 1, 5, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 5, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, "", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "12345", 2, S("ab12cde"));
+    test(S("abcde"), 2, 0, "12345", 4, S("ab1234cde"));
+    test(S("abcde"), 2, 0, "12345", 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "1234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "1234567890", 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, "1234567890", 9, S("ab123456789cde"));
+    test(S("abcde"), 2, 0, "1234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, 0, "12345678901234567890", 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, "", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345", 1, S("ab1de"));
+    test(S("abcde"), 2, 1, "12345", 2, S("ab12de"));
+    test(S("abcde"), 2, 1, "12345", 4, S("ab1234de"));
+    test(S("abcde"), 2, 1, "12345", 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", 0, S("abde"));
+    test(S("abcde"), 2, 1, "1234567890", 1, S("ab1de"));
+    test(S("abcde"), 2, 1, "1234567890", 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, "1234567890", 9, S("ab123456789de"));
+    test(S("abcde"), 2, 1, "1234567890", 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 0, S("abde"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 1, S("ab1de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 19, S("ab1234567890123456789de"));
+    test(S("abcde"), 2, 1, "12345678901234567890", 20, S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, "", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "12345", 2, S("ab12e"));
+    test(S("abcde"), 2, 2, "12345", 4, S("ab1234e"));
+    test(S("abcde"), 2, 2, "12345", 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", 0, S("abe"));
+    test(S("abcde"), 2, 2, "1234567890", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "1234567890", 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, "1234567890", 9, S("ab123456789e"));
+    test(S("abcde"), 2, 2, "1234567890", 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 0, S("abe"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 1, S("ab1e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 19, S("ab1234567890123456789e"));
+    test(S("abcde"), 2, 2, "12345678901234567890", 20, S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, "", 0, S("ab"));
+    test(S("abcde"), 2, 3, "12345", 0, S("ab"));
+    test(S("abcde"), 2, 3, "12345", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "12345", 2, S("ab12"));
+    test(S("abcde"), 2, 3, "12345", 4, S("ab1234"));
+    test(S("abcde"), 2, 3, "12345", 5, S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", 0, S("ab"));
+    test(S("abcde"), 2, 3, "1234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "1234567890", 5, S("ab12345"));
+    test(S("abcde"), 2, 3, "1234567890", 9, S("ab123456789"));
+    test(S("abcde"), 2, 3, "1234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 0, S("ab"));
+}
+
+template <class S>
+void test3()
+{
+    test(S("abcde"), 2, 3, "12345678901234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 3, "12345678901234567890", 20, S("ab12345678901234567890"));
+    test(S("abcde"), 2, 4, "", 0, S("ab"));
+    test(S("abcde"), 2, 4, "12345", 0, S("ab"));
+    test(S("abcde"), 2, 4, "12345", 1, S("ab1"));
+    test(S("abcde"), 2, 4, "12345", 2, S("ab12"));
+    test(S("abcde"), 2, 4, "12345", 4, S("ab1234"));
+    test(S("abcde"), 2, 4, "12345", 5, S("ab12345"));
+    test(S("abcde"), 2, 4, "1234567890", 0, S("ab"));
+    test(S("abcde"), 2, 4, "1234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 4, "1234567890", 5, S("ab12345"));
+    test(S("abcde"), 2, 4, "1234567890", 9, S("ab123456789"));
+    test(S("abcde"), 2, 4, "1234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 4, "12345678901234567890", 0, S("ab"));
+    test(S("abcde"), 2, 4, "12345678901234567890", 1, S("ab1"));
+    test(S("abcde"), 2, 4, "12345678901234567890", 10, S("ab1234567890"));
+    test(S("abcde"), 2, 4, "12345678901234567890", 19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 4, "12345678901234567890", 20, S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, "", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "12345", 2, S("abcd12e"));
+    test(S("abcde"), 4, 0, "12345", 4, S("abcd1234e"));
+    test(S("abcde"), 4, 0, "12345", 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "1234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "1234567890", 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, "1234567890", 9, S("abcd123456789e"));
+    test(S("abcde"), 4, 0, "1234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, 0, "12345678901234567890", 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, "", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "12345", 2, S("abcd12"));
+    test(S("abcde"), 4, 1, "12345", 4, S("abcd1234"));
+    test(S("abcde"), 4, 1, "12345", 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "1234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "1234567890", 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, "1234567890", 9, S("abcd123456789"));
+    test(S("abcde"), 4, 1, "1234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 1, "12345678901234567890", 20, S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 2, "", 0, S("abcd"));
+    test(S("abcde"), 4, 2, "12345", 0, S("abcd"));
+    test(S("abcde"), 4, 2, "12345", 1, S("abcd1"));
+    test(S("abcde"), 4, 2, "12345", 2, S("abcd12"));
+    test(S("abcde"), 4, 2, "12345", 4, S("abcd1234"));
+    test(S("abcde"), 4, 2, "12345", 5, S("abcd12345"));
+    test(S("abcde"), 4, 2, "1234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 2, "1234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 2, "1234567890", 5, S("abcd12345"));
+    test(S("abcde"), 4, 2, "1234567890", 9, S("abcd123456789"));
+    test(S("abcde"), 4, 2, "1234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, "12345678901234567890", 0, S("abcd"));
+    test(S("abcde"), 4, 2, "12345678901234567890", 1, S("abcd1"));
+    test(S("abcde"), 4, 2, "12345678901234567890", 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, "12345678901234567890", 19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 2, "12345678901234567890", 20, S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, "", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "12345", 2, S("abcde12"));
+    test(S("abcde"), 5, 0, "12345", 4, S("abcde1234"));
+    test(S("abcde"), 5, 0, "12345", 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "1234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "1234567890", 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, "1234567890", 9, S("abcde123456789"));
+    test(S("abcde"), 5, 0, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 1, "", 0, S("abcde"));
+    test(S("abcde"), 5, 1, "12345", 0, S("abcde"));
+    test(S("abcde"), 5, 1, "12345", 1, S("abcde1"));
+    test(S("abcde"), 5, 1, "12345", 2, S("abcde12"));
+    test(S("abcde"), 5, 1, "12345", 4, S("abcde1234"));
+    test(S("abcde"), 5, 1, "12345", 5, S("abcde12345"));
+    test(S("abcde"), 5, 1, "1234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 1, "1234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 1, "1234567890", 5, S("abcde12345"));
+    test(S("abcde"), 5, 1, "1234567890", 9, S("abcde123456789"));
+    test(S("abcde"), 5, 1, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, "12345678901234567890", 0, S("abcde"));
+    test(S("abcde"), 5, 1, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcde"), 5, 1, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 1, "12345678901234567890", 20, S("abcde12345678901234567890"));
+}
+
+template <class S>
+void test4()
+{
+    test(S("abcde"), 6, 0, "", 0, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", 0, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", 1, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", 2, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", 4, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345", 5, S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", 5, S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", 9, S("can't happen"));
+    test(S("abcde"), 6, 0, "1234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcde"), 6, 0, "12345678901234567890", 20, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "1234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, "", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 2, S("12bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 4, S("1234bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345", 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 9, S("123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "1234567890", 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, "", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 2, S("12fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 4, S("1234fghij"));
+    test(S("abcdefghij"), 0, 5, "12345", 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 9, S("123456789fghij"));
+    test(S("abcdefghij"), 0, 5, "1234567890", 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 19, S("1234567890123456789fghij"));
+    test(S("abcdefghij"), 0, 5, "12345678901234567890", 20, S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, "", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "12345", 2, S("12j"));
+    test(S("abcdefghij"), 0, 9, "12345", 4, S("1234j"));
+    test(S("abcdefghij"), 0, 9, "12345", 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 9, S("123456789j"));
+    test(S("abcdefghij"), 0, 9, "1234567890", 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 0, S("j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 19, S("1234567890123456789j"));
+    test(S("abcdefghij"), 0, 9, "12345678901234567890", 20, S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, "", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "12345", 2, S("12"));
+    test(S("abcdefghij"), 0, 10, "12345", 4, S("1234"));
+    test(S("abcdefghij"), 0, 10, "12345", 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "1234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 9, S("123456789"));
+    test(S("abcdefghij"), 0, 10, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 10, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 11, "", 0, S(""));
+    test(S("abcdefghij"), 0, 11, "12345", 0, S(""));
+    test(S("abcdefghij"), 0, 11, "12345", 1, S("1"));
+    test(S("abcdefghij"), 0, 11, "12345", 2, S("12"));
+}
+
+template <class S>
+void test5()
+{
+    test(S("abcdefghij"), 0, 11, "12345", 4, S("1234"));
+    test(S("abcdefghij"), 0, 11, "12345", 5, S("12345"));
+    test(S("abcdefghij"), 0, 11, "1234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 11, "1234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 11, "1234567890", 5, S("12345"));
+    test(S("abcdefghij"), 0, 11, "1234567890", 9, S("123456789"));
+    test(S("abcdefghij"), 0, 11, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", 0, S(""));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 11, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "1234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, "", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 2, S("a12cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 4, S("a1234cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345", 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 9, S("a123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, "1234567890", 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 4, "", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 2, S("a12fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 4, S("a1234fghij"));
+    test(S("abcdefghij"), 1, 4, "12345", 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 9, S("a123456789fghij"));
+    test(S("abcdefghij"), 1, 4, "1234567890", 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 19, S("a1234567890123456789fghij"));
+    test(S("abcdefghij"), 1, 4, "12345678901234567890", 20, S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, "", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "12345", 2, S("a12j"));
+    test(S("abcdefghij"), 1, 8, "12345", 4, S("a1234j"));
+    test(S("abcdefghij"), 1, 8, "12345", 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 9, S("a123456789j"));
+    test(S("abcdefghij"), 1, 8, "1234567890", 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 19, S("a1234567890123456789j"));
+    test(S("abcdefghij"), 1, 8, "12345678901234567890", 20, S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, "", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "12345", 2, S("a12"));
+    test(S("abcdefghij"), 1, 9, "12345", 4, S("a1234"));
+    test(S("abcdefghij"), 1, 9, "12345", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 9, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 10, "", 0, S("a"));
+    test(S("abcdefghij"), 1, 10, "12345", 0, S("a"));
+    test(S("abcdefghij"), 1, 10, "12345", 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, "12345", 2, S("a12"));
+    test(S("abcdefghij"), 1, 10, "12345", 4, S("a1234"));
+    test(S("abcdefghij"), 1, 10, "12345", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 10, "1234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 10, "1234567890", 1, S("a1"));
+}
+
+template <class S>
+void test6()
+{
+    test(S("abcdefghij"), 1, 10, "1234567890", 5, S("a12345"));
+    test(S("abcdefghij"), 1, 10, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 10, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 10, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, 0, "12345", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, 0, "1234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, 0, "12345678901234567890", 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, "", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 2, S("abcde12ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 4, S("abcde1234ghij"));
+    test(S("abcdefghij"), 5, 1, "12345", 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 9, S("abcde123456789ghij"));
+    test(S("abcdefghij"), 5, 1, "1234567890", 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 19, S("abcde1234567890123456789ghij"));
+    test(S("abcdefghij"), 5, 1, "12345678901234567890", 20, S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, "", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 2, S("abcde12hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 4, S("abcde1234hij"));
+    test(S("abcdefghij"), 5, 2, "12345", 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 9, S("abcde123456789hij"));
+    test(S("abcdefghij"), 5, 2, "1234567890", 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 19, S("abcde1234567890123456789hij"));
+    test(S("abcdefghij"), 5, 2, "12345678901234567890", 20, S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, "", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "12345", 2, S("abcde12j"));
+    test(S("abcdefghij"), 5, 4, "12345", 4, S("abcde1234j"));
+    test(S("abcdefghij"), 5, 4, "12345", 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 9, S("abcde123456789j"));
+    test(S("abcdefghij"), 5, 4, "1234567890", 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 19, S("abcde1234567890123456789j"));
+    test(S("abcdefghij"), 5, 4, "12345678901234567890", 20, S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, "", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "12345", 2, S("abcde12"));
+    test(S("abcdefghij"), 5, 5, "12345", 4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 5, "12345", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 5, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 5, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 6, "", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, "12345", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, "12345", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, "12345", 2, S("abcde12"));
+    test(S("abcdefghij"), 5, 6, "12345", 4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 6, "12345", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, "1234567890", 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, "1234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, "1234567890", 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, "1234567890", 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 6, "1234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", 0, S("abcde"));
+}
+
+template <class S>
+void test7()
+{
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", 19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 6, "12345678901234567890", 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "12345", 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, 0, "12345", 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, 0, "12345", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, 0, "1234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, 0, "12345678901234567890", 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, "", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "12345", 2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 1, "12345", 4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 1, "12345", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 1, "1234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 1, "12345678901234567890", 20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 2, "", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, "12345", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, "12345", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, "12345", 2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 2, "12345", 4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 2, "12345", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, "1234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, "1234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, "1234567890", 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, "1234567890", 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 2, "1234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", 19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 2, "12345678901234567890", 20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 0, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 0, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 0, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 1, "", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 1, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 1, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 1, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 1, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, 0, "", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, "12345678901234567890", 20, S("can't happen"));
+}
+
+template <class S>
+void test8()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "1234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, "12345678901234567890", 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 2, S("12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 4, S("1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345", 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 9, S("123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "1234567890", 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 19, S("1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, "12345678901234567890", 20, S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 2, S("12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 4, S("1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345", 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 9, S("123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "1234567890", 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 19, S("1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, "12345678901234567890", 20, S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 2, S("12t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 4, S("1234t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345", 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 9, S("123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "1234567890", 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 19, S("1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, "12345678901234567890", 20, S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", 2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", 4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "1234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", 19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, "12345678901234567890", 20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 2, S("a12bcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test9()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "1234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, "12345678901234567890", 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 2, S("a12cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 4, S("a1234cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345", 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 9, S("a123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "1234567890", 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 19, S("a1234567890123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, "12345678901234567890", 20, S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 2, S("a12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 4, S("a1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345", 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 9, S("a123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "1234567890", 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 19, S("a1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, "12345678901234567890", 20, S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 2, S("a12t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 4, S("a1234t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345", 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 9, S("a123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "1234567890", 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 19, S("a1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, "12345678901234567890", 20, S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", 2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", 4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "1234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", 19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, "12345678901234567890", 20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 1, S("abcdefghij1klmnopqrst"));
+}
+
+template <class S>
+void test10()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "1234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, "12345678901234567890", 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 2, S("abcdefghij12lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 4, S("abcdefghij1234lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345", 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 9, S("abcdefghij123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "1234567890", 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 19, S("abcdefghij1234567890123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, "12345678901234567890", 20, S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 2, S("abcdefghij12pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 4, S("abcdefghij1234pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345", 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 9, S("abcdefghij123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "1234567890", 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 19, S("abcdefghij1234567890123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, "12345678901234567890", 20, S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 2, S("abcdefghij12t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 4, S("abcdefghij1234t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345", 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 9, S("abcdefghij123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "1234567890", 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 19, S("abcdefghij1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, "12345678901234567890", 20, S("abcdefghij12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", 2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", 4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "1234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, "12345678901234567890", 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "1234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+}
+
+template <class S>
+void test11()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "1234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", 2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", 4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "1234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", 19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, "12345678901234567890", 20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "1234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, "12345678901234567890", 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "1234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, "12345678901234567890", 20, S("can't happen"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    test9<S>();
+    test10<S>();
+    test11<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    test3<S>();
+    test4<S>();
+    test5<S>();
+    test6<S>();
+    test7<S>();
+    test8<S>();
+    test9<S>();
+    test10<S>();
+    test11<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_size_char.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,374 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(size_type pos, size_type n1, size_type n2, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos, typename S::size_type n1,
+     typename S::size_type n2, typename S::value_type c,
+     S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.replace(pos, n1, n2, c);
+        assert(s.__invariants());
+        assert(pos <= old_size);
+        assert(s == expected);
+        typename S::size_type xlen = std::min(n1, old_size - pos);
+        typename S::size_type rlen = n2;
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, 0, '2', S(""));
+    test(S(""), 0, 0, 5, '2', S("22222"));
+    test(S(""), 0, 0, 10, '2', S("2222222222"));
+    test(S(""), 0, 0, 20, '2', S("22222222222222222222"));
+    test(S(""), 0, 1, 0, '2', S(""));
+    test(S(""), 0, 1, 5, '2', S("22222"));
+    test(S(""), 0, 1, 10, '2', S("2222222222"));
+    test(S(""), 0, 1, 20, '2', S("22222222222222222222"));
+    test(S(""), 1, 0, 0, '2', S("can't happen"));
+    test(S(""), 1, 0, 5, '2', S("can't happen"));
+    test(S(""), 1, 0, 10, '2', S("can't happen"));
+    test(S(""), 1, 0, 20, '2', S("can't happen"));
+    test(S("abcde"), 0, 0, 0, '2', S("abcde"));
+    test(S("abcde"), 0, 0, 5, '2', S("22222abcde"));
+    test(S("abcde"), 0, 0, 10, '2', S("2222222222abcde"));
+    test(S("abcde"), 0, 0, 20, '2', S("22222222222222222222abcde"));
+    test(S("abcde"), 0, 1, 0, '2', S("bcde"));
+    test(S("abcde"), 0, 1, 5, '2', S("22222bcde"));
+    test(S("abcde"), 0, 1, 10, '2', S("2222222222bcde"));
+    test(S("abcde"), 0, 1, 20, '2', S("22222222222222222222bcde"));
+    test(S("abcde"), 0, 2, 0, '2', S("cde"));
+    test(S("abcde"), 0, 2, 5, '2', S("22222cde"));
+    test(S("abcde"), 0, 2, 10, '2', S("2222222222cde"));
+    test(S("abcde"), 0, 2, 20, '2', S("22222222222222222222cde"));
+    test(S("abcde"), 0, 4, 0, '2', S("e"));
+    test(S("abcde"), 0, 4, 5, '2', S("22222e"));
+    test(S("abcde"), 0, 4, 10, '2', S("2222222222e"));
+    test(S("abcde"), 0, 4, 20, '2', S("22222222222222222222e"));
+    test(S("abcde"), 0, 5, 0, '2', S(""));
+    test(S("abcde"), 0, 5, 5, '2', S("22222"));
+    test(S("abcde"), 0, 5, 10, '2', S("2222222222"));
+    test(S("abcde"), 0, 5, 20, '2', S("22222222222222222222"));
+    test(S("abcde"), 0, 6, 0, '2', S(""));
+    test(S("abcde"), 0, 6, 5, '2', S("22222"));
+    test(S("abcde"), 0, 6, 10, '2', S("2222222222"));
+    test(S("abcde"), 0, 6, 20, '2', S("22222222222222222222"));
+    test(S("abcde"), 1, 0, 0, '2', S("abcde"));
+    test(S("abcde"), 1, 0, 5, '2', S("a22222bcde"));
+    test(S("abcde"), 1, 0, 10, '2', S("a2222222222bcde"));
+    test(S("abcde"), 1, 0, 20, '2', S("a22222222222222222222bcde"));
+    test(S("abcde"), 1, 1, 0, '2', S("acde"));
+    test(S("abcde"), 1, 1, 5, '2', S("a22222cde"));
+    test(S("abcde"), 1, 1, 10, '2', S("a2222222222cde"));
+    test(S("abcde"), 1, 1, 20, '2', S("a22222222222222222222cde"));
+    test(S("abcde"), 1, 2, 0, '2', S("ade"));
+    test(S("abcde"), 1, 2, 5, '2', S("a22222de"));
+    test(S("abcde"), 1, 2, 10, '2', S("a2222222222de"));
+    test(S("abcde"), 1, 2, 20, '2', S("a22222222222222222222de"));
+    test(S("abcde"), 1, 3, 0, '2', S("ae"));
+    test(S("abcde"), 1, 3, 5, '2', S("a22222e"));
+    test(S("abcde"), 1, 3, 10, '2', S("a2222222222e"));
+    test(S("abcde"), 1, 3, 20, '2', S("a22222222222222222222e"));
+    test(S("abcde"), 1, 4, 0, '2', S("a"));
+    test(S("abcde"), 1, 4, 5, '2', S("a22222"));
+    test(S("abcde"), 1, 4, 10, '2', S("a2222222222"));
+    test(S("abcde"), 1, 4, 20, '2', S("a22222222222222222222"));
+    test(S("abcde"), 1, 5, 0, '2', S("a"));
+    test(S("abcde"), 1, 5, 5, '2', S("a22222"));
+    test(S("abcde"), 1, 5, 10, '2', S("a2222222222"));
+    test(S("abcde"), 1, 5, 20, '2', S("a22222222222222222222"));
+    test(S("abcde"), 2, 0, 0, '2', S("abcde"));
+    test(S("abcde"), 2, 0, 5, '2', S("ab22222cde"));
+    test(S("abcde"), 2, 0, 10, '2', S("ab2222222222cde"));
+    test(S("abcde"), 2, 0, 20, '2', S("ab22222222222222222222cde"));
+    test(S("abcde"), 2, 1, 0, '2', S("abde"));
+    test(S("abcde"), 2, 1, 5, '2', S("ab22222de"));
+    test(S("abcde"), 2, 1, 10, '2', S("ab2222222222de"));
+    test(S("abcde"), 2, 1, 20, '2', S("ab22222222222222222222de"));
+    test(S("abcde"), 2, 2, 0, '2', S("abe"));
+    test(S("abcde"), 2, 2, 5, '2', S("ab22222e"));
+    test(S("abcde"), 2, 2, 10, '2', S("ab2222222222e"));
+    test(S("abcde"), 2, 2, 20, '2', S("ab22222222222222222222e"));
+    test(S("abcde"), 2, 3, 0, '2', S("ab"));
+    test(S("abcde"), 2, 3, 5, '2', S("ab22222"));
+    test(S("abcde"), 2, 3, 10, '2', S("ab2222222222"));
+    test(S("abcde"), 2, 3, 20, '2', S("ab22222222222222222222"));
+    test(S("abcde"), 2, 4, 0, '2', S("ab"));
+    test(S("abcde"), 2, 4, 5, '2', S("ab22222"));
+    test(S("abcde"), 2, 4, 10, '2', S("ab2222222222"));
+    test(S("abcde"), 2, 4, 20, '2', S("ab22222222222222222222"));
+    test(S("abcde"), 4, 0, 0, '2', S("abcde"));
+    test(S("abcde"), 4, 0, 5, '2', S("abcd22222e"));
+    test(S("abcde"), 4, 0, 10, '2', S("abcd2222222222e"));
+    test(S("abcde"), 4, 0, 20, '2', S("abcd22222222222222222222e"));
+    test(S("abcde"), 4, 1, 0, '2', S("abcd"));
+    test(S("abcde"), 4, 1, 5, '2', S("abcd22222"));
+    test(S("abcde"), 4, 1, 10, '2', S("abcd2222222222"));
+    test(S("abcde"), 4, 1, 20, '2', S("abcd22222222222222222222"));
+    test(S("abcde"), 4, 2, 0, '2', S("abcd"));
+    test(S("abcde"), 4, 2, 5, '2', S("abcd22222"));
+    test(S("abcde"), 4, 2, 10, '2', S("abcd2222222222"));
+    test(S("abcde"), 4, 2, 20, '2', S("abcd22222222222222222222"));
+    test(S("abcde"), 5, 0, 0, '2', S("abcde"));
+    test(S("abcde"), 5, 0, 5, '2', S("abcde22222"));
+    test(S("abcde"), 5, 0, 10, '2', S("abcde2222222222"));
+    test(S("abcde"), 5, 0, 20, '2', S("abcde22222222222222222222"));
+    test(S("abcde"), 5, 1, 0, '2', S("abcde"));
+    test(S("abcde"), 5, 1, 5, '2', S("abcde22222"));
+    test(S("abcde"), 5, 1, 10, '2', S("abcde2222222222"));
+    test(S("abcde"), 5, 1, 20, '2', S("abcde22222222222222222222"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 6, 0, 0, '2', S("can't happen"));
+    test(S("abcde"), 6, 0, 5, '2', S("can't happen"));
+    test(S("abcde"), 6, 0, 10, '2', S("can't happen"));
+    test(S("abcde"), 6, 0, 20, '2', S("can't happen"));
+    test(S("abcdefghij"), 0, 0, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 5, '2', S("22222abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 10, '2', S("2222222222abcdefghij"));
+    test(S("abcdefghij"), 0, 0, 20, '2', S("22222222222222222222abcdefghij"));
+    test(S("abcdefghij"), 0, 1, 0, '2', S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 5, '2', S("22222bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 10, '2', S("2222222222bcdefghij"));
+    test(S("abcdefghij"), 0, 1, 20, '2', S("22222222222222222222bcdefghij"));
+    test(S("abcdefghij"), 0, 5, 0, '2', S("fghij"));
+    test(S("abcdefghij"), 0, 5, 5, '2', S("22222fghij"));
+    test(S("abcdefghij"), 0, 5, 10, '2', S("2222222222fghij"));
+    test(S("abcdefghij"), 0, 5, 20, '2', S("22222222222222222222fghij"));
+    test(S("abcdefghij"), 0, 9, 0, '2', S("j"));
+    test(S("abcdefghij"), 0, 9, 5, '2', S("22222j"));
+    test(S("abcdefghij"), 0, 9, 10, '2', S("2222222222j"));
+    test(S("abcdefghij"), 0, 9, 20, '2', S("22222222222222222222j"));
+    test(S("abcdefghij"), 0, 10, 0, '2', S(""));
+    test(S("abcdefghij"), 0, 10, 5, '2', S("22222"));
+    test(S("abcdefghij"), 0, 10, 10, '2', S("2222222222"));
+    test(S("abcdefghij"), 0, 10, 20, '2', S("22222222222222222222"));
+    test(S("abcdefghij"), 0, 11, 0, '2', S(""));
+    test(S("abcdefghij"), 0, 11, 5, '2', S("22222"));
+    test(S("abcdefghij"), 0, 11, 10, '2', S("2222222222"));
+    test(S("abcdefghij"), 0, 11, 20, '2', S("22222222222222222222"));
+    test(S("abcdefghij"), 1, 0, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, 5, '2', S("a22222bcdefghij"));
+    test(S("abcdefghij"), 1, 0, 10, '2', S("a2222222222bcdefghij"));
+    test(S("abcdefghij"), 1, 0, 20, '2', S("a22222222222222222222bcdefghij"));
+    test(S("abcdefghij"), 1, 1, 0, '2', S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, 5, '2', S("a22222cdefghij"));
+    test(S("abcdefghij"), 1, 1, 10, '2', S("a2222222222cdefghij"));
+    test(S("abcdefghij"), 1, 1, 20, '2', S("a22222222222222222222cdefghij"));
+    test(S("abcdefghij"), 1, 4, 0, '2', S("afghij"));
+    test(S("abcdefghij"), 1, 4, 5, '2', S("a22222fghij"));
+    test(S("abcdefghij"), 1, 4, 10, '2', S("a2222222222fghij"));
+    test(S("abcdefghij"), 1, 4, 20, '2', S("a22222222222222222222fghij"));
+    test(S("abcdefghij"), 1, 8, 0, '2', S("aj"));
+    test(S("abcdefghij"), 1, 8, 5, '2', S("a22222j"));
+    test(S("abcdefghij"), 1, 8, 10, '2', S("a2222222222j"));
+    test(S("abcdefghij"), 1, 8, 20, '2', S("a22222222222222222222j"));
+    test(S("abcdefghij"), 1, 9, 0, '2', S("a"));
+    test(S("abcdefghij"), 1, 9, 5, '2', S("a22222"));
+    test(S("abcdefghij"), 1, 9, 10, '2', S("a2222222222"));
+    test(S("abcdefghij"), 1, 9, 20, '2', S("a22222222222222222222"));
+    test(S("abcdefghij"), 1, 10, 0, '2', S("a"));
+    test(S("abcdefghij"), 1, 10, 5, '2', S("a22222"));
+    test(S("abcdefghij"), 1, 10, 10, '2', S("a2222222222"));
+    test(S("abcdefghij"), 1, 10, 20, '2', S("a22222222222222222222"));
+    test(S("abcdefghij"), 5, 0, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, 5, '2', S("abcde22222fghij"));
+    test(S("abcdefghij"), 5, 0, 10, '2', S("abcde2222222222fghij"));
+    test(S("abcdefghij"), 5, 0, 20, '2', S("abcde22222222222222222222fghij"));
+    test(S("abcdefghij"), 5, 1, 0, '2', S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, 5, '2', S("abcde22222ghij"));
+    test(S("abcdefghij"), 5, 1, 10, '2', S("abcde2222222222ghij"));
+    test(S("abcdefghij"), 5, 1, 20, '2', S("abcde22222222222222222222ghij"));
+    test(S("abcdefghij"), 5, 2, 0, '2', S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, 5, '2', S("abcde22222hij"));
+    test(S("abcdefghij"), 5, 2, 10, '2', S("abcde2222222222hij"));
+    test(S("abcdefghij"), 5, 2, 20, '2', S("abcde22222222222222222222hij"));
+    test(S("abcdefghij"), 5, 4, 0, '2', S("abcdej"));
+    test(S("abcdefghij"), 5, 4, 5, '2', S("abcde22222j"));
+    test(S("abcdefghij"), 5, 4, 10, '2', S("abcde2222222222j"));
+    test(S("abcdefghij"), 5, 4, 20, '2', S("abcde22222222222222222222j"));
+    test(S("abcdefghij"), 5, 5, 0, '2', S("abcde"));
+    test(S("abcdefghij"), 5, 5, 5, '2', S("abcde22222"));
+    test(S("abcdefghij"), 5, 5, 10, '2', S("abcde2222222222"));
+    test(S("abcdefghij"), 5, 5, 20, '2', S("abcde22222222222222222222"));
+    test(S("abcdefghij"), 5, 6, 0, '2', S("abcde"));
+    test(S("abcdefghij"), 5, 6, 5, '2', S("abcde22222"));
+    test(S("abcdefghij"), 5, 6, 10, '2', S("abcde2222222222"));
+    test(S("abcdefghij"), 5, 6, 20, '2', S("abcde22222222222222222222"));
+    test(S("abcdefghij"), 9, 0, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, 5, '2', S("abcdefghi22222j"));
+    test(S("abcdefghij"), 9, 0, 10, '2', S("abcdefghi2222222222j"));
+    test(S("abcdefghij"), 9, 0, 20, '2', S("abcdefghi22222222222222222222j"));
+    test(S("abcdefghij"), 9, 1, 0, '2', S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, 5, '2', S("abcdefghi22222"));
+    test(S("abcdefghij"), 9, 1, 10, '2', S("abcdefghi2222222222"));
+    test(S("abcdefghij"), 9, 1, 20, '2', S("abcdefghi22222222222222222222"));
+    test(S("abcdefghij"), 9, 2, 0, '2', S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, 5, '2', S("abcdefghi22222"));
+    test(S("abcdefghij"), 9, 2, 10, '2', S("abcdefghi2222222222"));
+    test(S("abcdefghij"), 9, 2, 20, '2', S("abcdefghi22222222222222222222"));
+    test(S("abcdefghij"), 10, 0, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, 5, '2', S("abcdefghij22222"));
+    test(S("abcdefghij"), 10, 0, 10, '2', S("abcdefghij2222222222"));
+    test(S("abcdefghij"), 10, 0, 20, '2', S("abcdefghij22222222222222222222"));
+    test(S("abcdefghij"), 10, 1, 0, '2', S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, 5, '2', S("abcdefghij22222"));
+    test(S("abcdefghij"), 10, 1, 10, '2', S("abcdefghij2222222222"));
+    test(S("abcdefghij"), 10, 1, 20, '2', S("abcdefghij22222222222222222222"));
+    test(S("abcdefghij"), 11, 0, 0, '2', S("can't happen"));
+    test(S("abcdefghij"), 11, 0, 5, '2', S("can't happen"));
+    test(S("abcdefghij"), 11, 0, 10, '2', S("can't happen"));
+    test(S("abcdefghij"), 11, 0, 20, '2', S("can't happen"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 5, '2', S("22222abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 10, '2', S("2222222222abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, 20, '2', S("22222222222222222222abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 0, '2', S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 5, '2', S("22222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 10, '2', S("2222222222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, 20, '2', S("22222222222222222222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 0, '2', S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 5, '2', S("22222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 10, '2', S("2222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, 20, '2', S("22222222222222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 0, '2', S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 5, '2', S("22222t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 10, '2', S("2222222222t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, 20, '2', S("22222222222222222222t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 0, '2', S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 5, '2', S("22222"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 10, '2', S("2222222222"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, 20, '2', S("22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, 0, '2', S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, 5, '2', S("22222"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, 10, '2', S("2222222222"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, 20, '2', S("22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 5, '2', S("a22222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 10, '2', S("a2222222222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, 20, '2', S("a22222222222222222222bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 0, '2', S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 5, '2', S("a22222cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 10, '2', S("a2222222222cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, 20, '2', S("a22222222222222222222cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 0, '2', S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 5, '2', S("a22222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 10, '2', S("a2222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, 20, '2', S("a22222222222222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 0, '2', S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 5, '2', S("a22222t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 10, '2', S("a2222222222t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, 20, '2', S("a22222222222222222222t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 0, '2', S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 5, '2', S("a22222"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 10, '2', S("a2222222222"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, 20, '2', S("a22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, 0, '2', S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, 5, '2', S("a22222"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, 10, '2', S("a2222222222"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, 20, '2', S("a22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 5, '2', S("abcdefghij22222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 10, '2', S("abcdefghij2222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, 20, '2', S("abcdefghij22222222222222222222klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 0, '2', S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 5, '2', S("abcdefghij22222lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 10, '2', S("abcdefghij2222222222lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, 20, '2', S("abcdefghij22222222222222222222lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 0, '2', S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 5, '2', S("abcdefghij22222pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 10, '2', S("abcdefghij2222222222pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, 20, '2', S("abcdefghij22222222222222222222pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 0, '2', S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 5, '2', S("abcdefghij22222t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 10, '2', S("abcdefghij2222222222t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, 20, '2', S("abcdefghij22222222222222222222t"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 0, '2', S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 5, '2', S("abcdefghij22222"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 10, '2', S("abcdefghij2222222222"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, 20, '2', S("abcdefghij22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, 0, '2', S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, 5, '2', S("abcdefghij22222"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, 10, '2', S("abcdefghij2222222222"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, 20, '2', S("abcdefghij22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 5, '2', S("abcdefghijklmnopqrs22222t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 10, '2', S("abcdefghijklmnopqrs2222222222t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, 20, '2', S("abcdefghijklmnopqrs22222222222222222222t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 0, '2', S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 5, '2', S("abcdefghijklmnopqrs22222"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 10, '2', S("abcdefghijklmnopqrs2222222222"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, 20, '2', S("abcdefghijklmnopqrs22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, 0, '2', S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, 5, '2', S("abcdefghijklmnopqrs22222"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, 10, '2', S("abcdefghijklmnopqrs2222222222"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, 20, '2', S("abcdefghijklmnopqrs22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 5, '2', S("abcdefghijklmnopqrst22222"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 10, '2', S("abcdefghijklmnopqrst2222222222"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, 20, '2', S("abcdefghijklmnopqrst22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, 0, '2', S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, 5, '2', S("abcdefghijklmnopqrst22222"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, 10, '2', S("abcdefghijklmnopqrst2222222222"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, 20, '2', S("abcdefghijklmnopqrst22222222222222222222"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, 0, '2', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, 5, '2', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, 10, '2', S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, 20, '2', S("can't happen"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}

Added: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp?rev=224658&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_string.pass.cpp Fri Dec 19 19:40:03 2014
@@ -0,0 +1,372 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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>&
+//   replace(size_type pos1, size_type n1, const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "min_allocator.h"
+
+template <class S>
+void
+test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected)
+{
+    typename S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.replace(pos1, n1, str);
+        assert(s.__invariants());
+        assert(pos1 <= old_size);
+        assert(s == expected);
+        typename S::size_type xlen = std::min(n1, old_size - pos1);
+        typename S::size_type rlen = str.size();
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > old_size);
+        assert(s == s0);
+    }
+}
+
+template <class S>
+void test0()
+{
+    test(S(""), 0, 0, S(""), S(""));
+    test(S(""), 0, 0, S("12345"), S("12345"));
+    test(S(""), 0, 0, S("1234567890"), S("1234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), S("12345678901234567890"));
+    test(S(""), 0, 1, S(""), S(""));
+    test(S(""), 0, 1, S("12345"), S("12345"));
+    test(S(""), 0, 1, S("1234567890"), S("1234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), S("12345678901234567890"));
+    test(S(""), 1, 0, S(""), S("can't happen"));
+    test(S(""), 1, 0, S("12345"), S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), S("can't happen"));
+    test(S("abcde"), 0, 0, S(""), S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), S("12345abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 1, S(""), S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), S("12345bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 2, S(""), S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), S("12345cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), S("12345678901234567890cde"));
+    test(S("abcde"), 0, 4, S(""), S("e"));
+    test(S("abcde"), 0, 4, S("12345"), S("12345e"));
+    test(S("abcde"), 0, 4, S("1234567890"), S("1234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), S("12345678901234567890e"));
+    test(S("abcde"), 0, 5, S(""), S(""));
+    test(S("abcde"), 0, 5, S("12345"), S("12345"));
+    test(S("abcde"), 0, 5, S("1234567890"), S("1234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcde"), 0, 6, S(""), S(""));
+    test(S("abcde"), 0, 6, S("12345"), S("12345"));
+    test(S("abcde"), 0, 6, S("1234567890"), S("1234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcde"), 1, 0, S(""), S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 1, S(""), S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), S("a12345cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 2, S(""), S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), S("a12345de"));
+    test(S("abcde"), 1, 2, S("1234567890"), S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), S("a12345678901234567890de"));
+    test(S("abcde"), 1, 3, S(""), S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), S("a12345e"));
+    test(S("abcde"), 1, 3, S("1234567890"), S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), S("a12345678901234567890e"));
+    test(S("abcde"), 1, 4, S(""), S("a"));
+    test(S("abcde"), 1, 4, S("12345"), S("a12345"));
+    test(S("abcde"), 1, 4, S("1234567890"), S("a1234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcde"), 1, 5, S(""), S("a"));
+    test(S("abcde"), 1, 5, S("12345"), S("a12345"));
+    test(S("abcde"), 1, 5, S("1234567890"), S("a1234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcde"), 2, 0, S(""), S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 1, S(""), S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), S("ab12345de"));
+    test(S("abcde"), 2, 1, S("1234567890"), S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 2, S(""), S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), S("ab12345e"));
+    test(S("abcde"), 2, 2, S("1234567890"), S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 3, S(""), S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), S("ab12345"));
+    test(S("abcde"), 2, 3, S("1234567890"), S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), S("ab12345678901234567890"));
+    test(S("abcde"), 2, 4, S(""), S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), S("ab12345"));
+    test(S("abcde"), 2, 4, S("1234567890"), S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), S("ab12345678901234567890"));
+    test(S("abcde"), 4, 0, S(""), S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("1234567890"), S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 1, S(""), S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), S("abcd12345"));
+    test(S("abcde"), 4, 1, S("1234567890"), S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 2, S(""), S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), S("abcd12345"));
+    test(S("abcde"), 4, 2, S("1234567890"), S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), S("abcd12345678901234567890"));
+    test(S("abcde"), 5, 0, S(""), S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), S("abcde12345"));
+    test(S("abcde"), 5, 0, S("1234567890"), S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 1, S(""), S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), S("abcde12345"));
+    test(S("abcde"), 5, 1, S("1234567890"), S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), S("abcde12345678901234567890"));
+}
+
+template <class S>
+void test1()
+{
+    test(S("abcde"), 6, 0, S(""), S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 1, S(""), S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 5, S(""), S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 9, S(""), S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 10, S(""), S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), S("12345"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 11, S(""), S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), S("12345"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghij"), 1, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 1, S(""), S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 4, S(""), S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 8, S(""), S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 9, S(""), S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 10, S(""), S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), S("a12345"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghij"), 5, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 1, S(""), S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 2, S(""), S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 4, S(""), S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 5, S(""), S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 6, S(""), S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 9, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 1, S(""), S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 2, S(""), S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 1, S(""), S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 11, 0, S(""), S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), S("can't happen"));
+}
+
+template <class S>
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), S("abcdefghij12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), S("can't happen"));
+}
+
+int main()
+{
+    {
+    typedef std::string S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#if __cplusplus >= 201103L
+    {
+    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
+    test0<S>();
+    test1<S>();
+    test2<S>();
+    }
+#endif
+}





More information about the cfe-commits mailing list