libcxx initial import

llvm-svn: 103490
diff --git a/libcxx/test/strings/basic.string.hash/strings.pass.cpp b/libcxx/test/strings/basic.string.hash/strings.pass.cpp
new file mode 100644
index 0000000..9697c34
--- /dev/null
+++ b/libcxx/test/strings/basic.string.hash/strings.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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
+    test<std::wstring>();
+}
diff --git a/libcxx/test/strings/basic.string/input_iterator.h b/libcxx/test/strings/basic.string/input_iterator.h
new file mode 100644
index 0000000..5d1a1b0
--- /dev/null
+++ b/libcxx/test/strings/basic.string/input_iterator.h
@@ -0,0 +1,32 @@
+#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
diff --git a/libcxx/test/strings/basic.string/string.access/at.pass.cpp b/libcxx/test/strings/basic.string/string.access/at.pass.cpp
new file mode 100644
index 0000000..1e05a46
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.access/at.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_reference at(size_type pos) const;
+//       reference at(size_type pos);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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);
+}
diff --git a/libcxx/test/strings/basic.string/string.access/back.pass.cpp b/libcxx/test/strings/basic.string/string.access/back.pass.cpp
new file mode 100644
index 0000000..a4ce3ac
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.access/back.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const charT& back() const;
+//       charT& back();
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.access/front.pass.cpp b/libcxx/test/strings/basic.string/string.access/front.pass.cpp
new file mode 100644
index 0000000..42593bb
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.access/front.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const charT& front() const;
+//       charT& front();
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.access/index.pass.cpp b/libcxx/test/strings/basic.string/string.access/index.pass.cpp
new file mode 100644
index 0000000..0018cc5
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.access/index.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_reference operator[](size_type pos) const;
+//       reference operator[](size_type pos);
+
+#include <string>
+#include <cassert>
+
+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');
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/capacity.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/capacity.pass.cpp
new file mode 100644
index 0000000..f5fe109
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type capacity() const;
+
+#include <string>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s)
+{
+    S::allocator_type::throw_after = 0;
+    try
+    {
+        while (s.size() < s.capacity())
+            s.push_back(typename S::value_type());
+        assert(s.size() == s.capacity());
+    }
+    catch (...)
+    {
+        assert(false);
+    }
+    S::allocator_type::throw_after = INT_MAX;
+}
+
+int main()
+{
+    typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
+    S s;
+    test(s);
+    s.assign(10, 'a');
+    s.erase(5);
+    test(s);
+    s.assign(100, 'a');
+    s.erase(50);
+    test(s);
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/clear.pass.cpp
new file mode 100644
index 0000000..f1d1cfe
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/clear.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void clear();
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s)
+{
+    s.clear();
+    assert(s.size() == 0);
+}
+
+int main()
+{
+    typedef std::string S;
+    S s;
+    test(s);
+
+    s.assign(10, 'a');
+    s.erase(5);
+    test(s);
+
+    s.assign(100, 'a');
+    s.erase(50);
+    test(s);
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/empty.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/empty.pass.cpp
new file mode 100644
index 0000000..0581217
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/empty.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// bool empty() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s)
+{
+    assert(s.empty() == (s.size() == 0));
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/length.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/length.pass.cpp
new file mode 100644
index 0000000..ee9fb52
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/length.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type length() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s)
+{
+    assert(s.length() == s.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp
new file mode 100644
index 0000000..f0fc3bc
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/max_size.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type max_size() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s)
+{
+    assert(s.max_size() >= s.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S());
+    test(S("123"));
+    test(S("12345678901234567890123456789012345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/reserve.pass.cpp
new file mode 100644
index 0000000..92d9123
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void reserve(size_type res_arg=0);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s)
+{
+    typename S::size_type old_cap = s.capacity();
+    S s0 = s;
+    s.reserve();
+    assert(s.__invariants());
+    assert(s == s0);
+    assert(s.capacity() <= old_cap);
+    assert(s.capacity() >= s.size());
+}
+
+template <class S>
+void
+test(S s, typename S::size_type res_arg)
+{
+    typename S::size_type old_cap = s.capacity();
+    S s0 = s;
+    try
+    {
+        s.reserve(res_arg);
+        assert(res_arg <= s.max_size());
+        assert(s == s0);
+        assert(s.capacity() >= res_arg);
+        assert(s.capacity() >= s.size());
+    }
+    catch (std::length_error&)
+    {
+        assert(res_arg > s.max_size());
+    }
+}
+
+int main()
+{
+    typedef std::string S;
+    {
+    S s;
+    test(s);
+
+    s.assign(10, 'a');
+    s.erase(5);
+    test(s);
+
+    s.assign(100, 'a');
+    s.erase(50);
+    test(s);
+    }
+    {
+    S s;
+    test(s, 5);
+    test(s, 10);
+    test(s, 50);
+    }
+    {
+    S s(100, 'a');
+    s.erase(50);
+    test(s, 5);
+    test(s, 10);
+    test(s, 50);
+    test(s, 100);
+    test(s, S::npos);
+    }
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/resize_size.pass.cpp
new file mode 100644
index 0000000..fc68dde
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/resize_size.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void resize(size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, typename S::size_type n, S expected)
+{
+    try
+    {
+        s.resize(n);
+        assert(s.__invariants());
+        assert(n <= s.max_size());
+        assert(s == expected);
+    }
+    catch (std::length_error&)
+    {
+        assert(n > s.max_size());
+    }
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), 0, S());
+    test(S(), 1, S(1, '\0'));
+    test(S(), 10, S(10, '\0'));
+    test(S(), 100, S(100, '\0'));
+    test(S("12345"), 0, S());
+    test(S("12345"), 2, S("12"));
+    test(S("12345"), 5, S("12345"));
+    test(S("12345"), 15, S("12345\0\0\0\0\0\0\0\0\0\0", 15));
+    test(S("12345678901234567890123456789012345678901234567890"), 0, S());
+    test(S("12345678901234567890123456789012345678901234567890"), 10,
+         S("1234567890"));
+    test(S("12345678901234567890123456789012345678901234567890"), 50,
+         S("12345678901234567890123456789012345678901234567890"));
+    test(S("12345678901234567890123456789012345678901234567890"), 60,
+         S("12345678901234567890123456789012345678901234567890\0\0\0\0\0\0\0\0\0\0", 60));
+    test(S(), S::npos, S("not going to happen"));
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/resize_size_char.pass.cpp
new file mode 100644
index 0000000..678252d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/resize_size_char.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void resize(size_type n, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, typename S::size_type n, typename S::value_type c, S expected)
+{
+    try
+    {
+        s.resize(n, c);
+        assert(s.__invariants());
+        assert(n <= s.max_size());
+        assert(s == expected);
+    }
+    catch (std::length_error&)
+    {
+        assert(n > s.max_size());
+    }
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), 0, 'a', S());
+    test(S(), 1, 'a', S("a"));
+    test(S(), 10, 'a', S(10, 'a'));
+    test(S(), 100, 'a', S(100, 'a'));
+    test(S("12345"), 0, 'a', S());
+    test(S("12345"), 2, 'a', S("12"));
+    test(S("12345"), 5, 'a', S("12345"));
+    test(S("12345"), 15, 'a', S("12345aaaaaaaaaa"));
+    test(S("12345678901234567890123456789012345678901234567890"), 0, 'a', S());
+    test(S("12345678901234567890123456789012345678901234567890"), 10, 'a',
+         S("1234567890"));
+    test(S("12345678901234567890123456789012345678901234567890"), 50, 'a',
+         S("12345678901234567890123456789012345678901234567890"));
+    test(S("12345678901234567890123456789012345678901234567890"), 60, 'a',
+         S("12345678901234567890123456789012345678901234567890aaaaaaaaaa"));
+    test(S(), S::npos, 'a', S("not going to happen"));
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
new file mode 100644
index 0000000..ea257b2
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void shrink_to_fit();
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s)
+{
+    typename S::size_type old_cap = s.capacity();
+    S s0 = s;
+    s.shrink_to_fit();
+    assert(s.__invariants());
+    assert(s == s0);
+    assert(s.capacity() <= old_cap);
+    assert(s.capacity() >= s.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    S s;
+    test(s);
+
+    s.assign(10, 'a');
+    s.erase(5);
+    test(s);
+
+    s.assign(100, 'a');
+    s.erase(50);
+    test(s);
+}
diff --git a/libcxx/test/strings/basic.string/string.capacity/size.pass.cpp b/libcxx/test/strings/basic.string/string.capacity/size.pass.cpp
new file mode 100644
index 0000000..90dd295
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.capacity/size.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type size() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::size_type c)
+{
+    assert(s.size() == c);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), 0);
+    test(S("123"), 3);
+    test(S("12345678901234567890123456789012345678901234567890"), 50);
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/alloc.pass.cpp
new file mode 100644
index 0000000..f015f6a
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/alloc.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// explicit basic_string(const Allocator& a = Allocator());
+
+#include <string>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test()
+{
+    {
+    S s;
+    assert(s.__invariants());
+    assert(s.data());
+    assert(s.size() == 0);
+    assert(s.capacity() >= s.size());
+    assert(s.get_allocator() == typename S::allocator_type());
+    }
+    {
+    S s(typename S::allocator_type(5));
+    assert(s.__invariants());
+    assert(s.data());
+    assert(s.size() == 0);
+    assert(s.capacity() >= s.size());
+    assert(s.get_allocator() == typename S::allocator_type(5));
+    }
+}
+
+int main()
+{
+    test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/char_assignment.pass.cpp b/libcxx/test/strings/basic.string/string.cons/char_assignment.pass.cpp
new file mode 100644
index 0000000..b945b1b
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/char_assignment.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& operator=(charT c);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s1, typename S::value_type s2)
+{
+    typedef typename S::traits_type T;
+    s1 = s2;
+    assert(s1.__invariants());
+    assert(s1.size() == 1);
+    assert(T::eq(s1[0], s2));
+    assert(s1.capacity() >= s1.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), 'a');
+    test(S("1"), 'a');
+    test(S("123456789"), 'a');
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/copy.pass.cpp b/libcxx/test/strings/basic.string/string.cons/copy.pass.cpp
new file mode 100644
index 0000000..2c68fbd
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/copy.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s1)
+{
+    S s2 = s1;
+    assert(s2.__invariants());
+    assert(s2 == s1);
+    assert(s2.capacity() >= s2.size());
+    assert(s2.get_allocator() == s1.get_allocator());
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(A(3)));
+    test(S("1", A(5)));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/copy_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/copy_alloc.pass.cpp
new file mode 100644
index 0000000..00763cd
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(const basic_string& str, const Allocator& alloc);
+
+#include <string>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s1, const typename S::allocator_type& a)
+{
+    S s2(s1, a);
+    assert(s2.__invariants());
+    assert(s2 == s1);
+    assert(s2.capacity() >= s2.size());
+    assert(s2.get_allocator() == a);
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(), A(3));
+    test(S("1"), A(5));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/copy_assignment.pass.cpp b/libcxx/test/strings/basic.string/string.cons/copy_assignment.pass.cpp
new file mode 100644
index 0000000..9756607
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/copy_assignment.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   operator=(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s1, const S& s2)
+{
+    s1 = s2;
+    assert(s1.__invariants());
+    assert(s1 == s2);
+    assert(s1.capacity() >= s1.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), S());
+    test(S("1"), S());
+    test(S(), S("1"));
+    test(S("1"), S("2"));
+    test(S("1"), S("2"));
+
+    test(S(),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("123456789"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+           "1234567890123456789012345678901234567890123456789012345678901234567890"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.cons/initializer_list.pass.cpp
new file mode 100644
index 0000000..1e4e8a4
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/initializer_list.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
+
+#include <string>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+    {
+        std::wstring s;
+        s = {L'a', L'b', L'c'};
+        assert(s == L"abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp b/libcxx/test/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
new file mode 100644
index 0000000..d7686a3
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/initializer_list_assignment.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& operator=(initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s;
+        s = {'a', 'b', 'c'};
+        assert(s == "abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/iter_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/iter_alloc.pass.cpp
new file mode 100644
index 0000000..752fb33
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/iter_alloc.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class InputIterator> 
+//   basic_string(InputIterator begin, InputIterator end, 
+//   const Allocator& a = Allocator());
+
+#include <string>
+#include <iterator>
+#include <cassert>
+
+#include "../test_allocator.h"
+#include "../input_iterator.h"
+
+template <class It>
+void
+test(It first, It last)
+{
+    typedef typename std::iterator_traits<It>::value_type charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(first, last);
+    assert(s2.__invariants());
+    assert(s2.size() == std::distance(first, last));
+    unsigned i = 0;
+    for (It it = first; it != last; ++it, ++i)
+        assert(s2[i] == *it);
+    assert(s2.get_allocator() == A());
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class It>
+void
+test(It first, It last, const test_allocator<typename std::iterator_traits<It>::value_type>& a)
+{
+    typedef typename std::iterator_traits<It>::value_type charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(first, last, a);
+    assert(s2.__invariants());
+    assert(s2.size() == std::distance(first, last));
+    unsigned i = 0;
+    for (It it = first; it != last; ++it, ++i)
+        assert(s2[i] == *it);
+    assert(s2.get_allocator() == a);
+    assert(s2.capacity() >= s2.size());
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    const char* s = "12345678901234567890123456789012345678901234567890";
+
+    test(s, s);
+    test(s, s, A(2));
+
+    test(s, s+1);
+    test(s, s+1, A(2));
+
+    test(s, s+10);
+    test(s, s+10, A(2));
+
+    test(s, s+50);
+    test(s, s+50, A(2));
+
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s));
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s), A(2));
+
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+1));
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A(2));
+
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+10));
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A(2));
+
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+50));
+    test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A(2));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/move.pass.cpp b/libcxx/test/strings/basic.string/string.cons/move.pass.cpp
new file mode 100644
index 0000000..80887dc
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/move.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(basic_string<charT,traits,Allocator>&& str);
+
+#include <string>
+#include <cassert>
+
+#ifdef _LIBCPP_MOVE
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s0)
+{
+    S s1 = s0;
+    S s2 = std::move(s0);
+    assert(s2.__invariants());
+    assert(s0.__invariants());
+    assert(s2 == s1);
+    assert(s2.capacity() >= s2.size());
+    assert(s2.get_allocator() == s1.get_allocator());
+}
+
+#endif
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(A(3)));
+    test(S("1", A(5)));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/move_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/move_alloc.pass.cpp
new file mode 100644
index 0000000..7b45647
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/move_alloc.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(basic_string&& str, const Allocator& alloc);
+
+#include <string>
+#include <cassert>
+
+#ifdef _LIBCPP_MOVE
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s0, const typename S::allocator_type& a)
+{
+    S s1 = s0;
+    S s2(std::move(s0), a);
+    assert(s2.__invariants());
+    assert(s0.__invariants());
+    assert(s2 == s1);
+    assert(s2.capacity() >= s2.size());
+    assert(s2.get_allocator() == a);
+}
+
+#endif
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(), A(3));
+    test(S("1"), A(5));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/move_assignment.pass.cpp b/libcxx/test/strings/basic.string/string.cons/move_assignment.pass.cpp
new file mode 100644
index 0000000..12c02ca
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/move_assignment.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   operator=(basic_string<charT,traits,Allocator>&& str);
+
+#include <string>
+#include <cassert>
+
+#ifdef _LIBCPP_MOVE
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S s1, S s2)
+{
+    S s0 = s2;
+    s1 = std::move(s2);
+    assert(s1.__invariants());
+    assert(s2.__invariants());
+    assert(s1 == s0);
+    assert(s1.capacity() >= s1.size());
+}
+
+#endif
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    typedef std::string S;
+    test(S(), S());
+    test(S("1"), S());
+    test(S(), S("1"));
+    test(S("1"), S("2"));
+    test(S("1"), S("2"));
+
+    test(S(),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("123456789"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+           "1234567890123456789012345678901234567890123456789012345678901234567890"),
+         S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/pointer_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/pointer_alloc.pass.cpp
new file mode 100644
index 0000000..517e5f6
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/pointer_alloc.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(const charT* s, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class charT>
+void
+test(const charT* s)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    unsigned n = T::length(s);
+    S s2(s);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    assert(T::compare(s2.data(), s, n) == 0);
+    assert(s2.get_allocator() == A());
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class charT>
+void
+test(const charT* s, const test_allocator<charT>& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    unsigned n = T::length(s);
+    S s2(s, a);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    assert(T::compare(s2.data(), s, n) == 0);
+    assert(s2.get_allocator() == a);
+    assert(s2.capacity() >= s2.size());
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test("");
+    test("", A(2));
+
+    test("1");
+    test("1", A(2));
+
+    test("1234567980");
+    test("1234567980", A(2));
+
+    test("123456798012345679801234567980123456798012345679801234567980");
+    test("123456798012345679801234567980123456798012345679801234567980", A(2));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/pointer_assignment.pass.cpp b/libcxx/test/strings/basic.string/string.cons/pointer_assignment.pass.cpp
new file mode 100644
index 0000000..f0f38bc
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/pointer_assignment.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   operator=(const charT* s);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s1, const typename S::value_type* s2)
+{
+    typedef typename S::traits_type T;
+    s1 = s2;
+    assert(s1.__invariants());
+    assert(s1.size() == T::length(s2));
+    assert(T::compare(s1.data(), s2, s1.size()) == 0);
+    assert(s1.capacity() >= s1.size());
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), "");
+    test(S("1"), "");
+    test(S(), "1");
+    test(S("1"), "2");
+    test(S("1"), "2");
+
+    test(S(),
+         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+    test(S("123456789"),
+         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
+         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
+           "1234567890123456789012345678901234567890123456789012345678901234567890"),
+         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
new file mode 100644
index 0000000..83104a1
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/pointer_size_alloc.pass.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class charT>
+void
+test(const charT* s, unsigned n)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(s, n);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    assert(T::compare(s2.data(), s, n) == 0);
+    assert(s2.get_allocator() == A());
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class charT>
+void
+test(const charT* s, unsigned n, const test_allocator<charT>& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(s, n, a);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    assert(T::compare(s2.data(), s, n) == 0);
+    assert(s2.get_allocator() == a);
+    assert(s2.capacity() >= s2.size());
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test("", 0);
+    test("", 0, A(2));
+
+    test("1", 1);
+    test("1", 1, A(2));
+
+    test("1234567980", 10);
+    test("1234567980", 10, A(2));
+
+    test("123456798012345679801234567980123456798012345679801234567980", 60);
+    test("123456798012345679801234567980123456798012345679801234567980", 60, A(2));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/size_char_alloc.pass.cpp b/libcxx/test/strings/basic.string/string.cons/size_char_alloc.pass.cpp
new file mode 100644
index 0000000..a2e7a53
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/size_char_alloc.pass.cpp
@@ -0,0 +1,106 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(size_type n, charT c, const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class charT>
+void
+test(unsigned n, charT c)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(n, c);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    for (unsigned i = 0; i < n; ++i)
+        assert(s2[i] == c);
+    assert(s2.get_allocator() == A());
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class charT>
+void
+test(unsigned n, charT c, const test_allocator<charT>& a)
+{
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(n, c, a);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    for (unsigned i = 0; i < n; ++i)
+        assert(s2[i] == c);
+    assert(s2.get_allocator() == a);
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class Tp>
+void
+test(Tp n, Tp c)
+{
+    typedef char charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(n, c);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    for (unsigned i = 0; i < n; ++i)
+        assert(s2[i] == c);
+    assert(s2.get_allocator() == A());
+    assert(s2.capacity() >= s2.size());
+}
+
+template <class Tp>
+void
+test(Tp n, Tp c, const test_allocator<char>& a)
+{
+    typedef char charT;
+    typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    S s2(n, c, a);
+    assert(s2.__invariants());
+    assert(s2.size() == n);
+    for (unsigned i = 0; i < n; ++i)
+        assert(s2[i] == c);
+    assert(s2.get_allocator() == a);
+    assert(s2.capacity() >= s2.size());
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test(0, 'a');
+    test(0, 'a', A(2));
+
+    test(1, 'a');
+    test(1, 'a', A(2));
+
+    test(10, 'a');
+    test(10, 'a', A(2));
+
+    test(100, 'a');
+    test(100, 'a', A(2));
+
+    test(100, 65);
+    test(100, 65, A(3));
+}
diff --git a/libcxx/test/strings/basic.string/string.cons/substr.pass.cpp b/libcxx/test/strings/basic.string/string.cons/substr.pass.cpp
new file mode 100644
index 0000000..8687fa8
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.cons/substr.pass.cpp
@@ -0,0 +1,130 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string(const basic_string<charT,traits,Allocator>& str, 
+//              size_type pos, size_type n = npos, 
+//              const Allocator& a = Allocator());
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+#include "../test_allocator.h"
+
+template <class S>
+void
+test(S str, unsigned pos)
+{
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    try
+    {
+        S s2(str, pos);
+        assert(s2.__invariants());
+        assert(pos <= str.size());
+        unsigned rlen = str.size() - pos;
+        assert(s2.size() == rlen);
+        assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+        assert(s2.get_allocator() == A());
+        assert(s2.capacity() >= s2.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+template <class S>
+void
+test(S str, unsigned pos, unsigned n)
+{
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    try
+    {
+        S s2(str, pos, n);
+        assert(s2.__invariants());
+        assert(pos <= str.size());
+        unsigned rlen = std::min(str.size() - pos, n);
+        assert(s2.size() == rlen);
+        assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+        assert(s2.get_allocator() == A());
+        assert(s2.capacity() >= s2.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+template <class S>
+void
+test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
+{
+    typedef typename S::traits_type T;
+    typedef typename S::allocator_type A;
+    try
+    {
+        S s2(str, pos, n, a);
+        assert(s2.__invariants());
+        assert(pos <= str.size());
+        unsigned rlen = std::min(str.size() - pos, n);
+        assert(s2.size() == rlen);
+        assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
+        assert(s2.get_allocator() == a);
+        assert(s2.capacity() >= s2.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+
+    test(S(A(3)), 0);
+    test(S(A(3)), 1);
+    test(S("1", A(5)), 0);
+    test(S("1", A(5)), 1);
+    test(S("1", A(5)), 2);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 0);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 5);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 500);
+
+    test(S(A(3)), 0, 0);
+    test(S(A(3)), 0, 1);
+    test(S(A(3)), 1, 0);
+    test(S(A(3)), 1, 1);
+    test(S(A(3)), 1, 2);
+    test(S("1", A(5)), 0, 0);
+    test(S("1", A(5)), 0, 1);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10);
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100);
+
+    test(S(A(3)), 0, 0, A(4));
+    test(S(A(3)), 0, 1, A(4));
+    test(S(A(3)), 1, 0, A(4));
+    test(S(A(3)), 1, 1, A(4));
+    test(S(A(3)), 1, 2, A(4));
+    test(S("1", A(5)), 0, 0, A(6));
+    test(S("1", A(5)), 0, 1, A(6));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0, A(8));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1, A(8));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8));
+    test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/begin.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/begin.pass.cpp
new file mode 100644
index 0000000..2d54de4
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/begin.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+//       iterator begin();
+// const_iterator begin() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/cbegin.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/cbegin.pass.cpp
new file mode 100644
index 0000000..f794a46
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/cbegin.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_iterator cbegin() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/cend.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/cend.pass.cpp
new file mode 100644
index 0000000..5d5801fa
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/cend.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_iterator cend() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/crbegin.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/crbegin.pass.cpp
new file mode 100644
index 0000000..707272f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/crbegin.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_reverse_iterator crbegin() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/crend.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/crend.pass.cpp
new file mode 100644
index 0000000..290854d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/crend.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const_reverse_iterator crend() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/end.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/end.pass.cpp
new file mode 100644
index 0000000..cf43bdd
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/end.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+//       iterator end();
+// const_iterator end() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/rbegin.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/rbegin.pass.cpp
new file mode 100644
index 0000000..1653136
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/rbegin.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+//       reverse_iterator rbegin();
+// const_reverse_iterator rbegin() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.iterators/rend.pass.cpp b/libcxx/test/strings/basic.string/string.iterators/rend.pass.cpp
new file mode 100644
index 0000000..5daed01
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.iterators/rend.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+//       reverse_iterator rend();
+// const_reverse_iterator rend() const;
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/initializer_list.pass.cpp
new file mode 100644
index 0000000..134f4ff
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/initializer_list.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& append(initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("123");
+        s.append({'a', 'b', 'c'});
+        assert(s == "123abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/iterator.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/iterator.pass.cpp
new file mode 100644
index 0000000..e9126a1
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/iterator.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class InputIterator> 
+//   basic_string& append(InputIterator first, InputIterator last);
+
+#include <string>
+#include <cassert>
+
+#include "../../input_iterator.h"
+
+template <class S, class It>
+void
+test(S s, It first, It last, S expected)
+{
+    s.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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer.pass.cpp
new file mode 100644
index 0000000..4d98a1f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& append(const charT* s);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, const typename S::value_type* str, S expected)
+{
+    s.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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer_size.pass.cpp
new file mode 100644
index 0000000..4daffe8
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/pointer_size.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   append(const charT* s, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, const typename S::value_type* str, typename S::size_type n, S expected)
+{
+    s.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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/push_back.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/push_back.pass.cpp
new file mode 100644
index 0000000..da5604e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/push_back.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void push_back(charT c)
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/size_char.pass.cpp
new file mode 100644
index 0000000..c567460
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/size_char.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   append(size_type n, charT c);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s, typename S::size_type n, typename S::value_type c, S expected)
+{
+    s.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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/string.pass.cpp
new file mode 100644
index 0000000..1e56234
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/string.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   append(const basic_string<charT,traits>& str);
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::append/string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::append/string_size_size.pass.cpp
new file mode 100644
index 0000000..c043fb7
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::append/string_size_size.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   append(const basic_string<charT,traits>& str, size_type pos, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
+{
+    try
+    {
+        s.append(str, pos, n);
+        assert(s.__invariants());
+        assert(pos <= str.size());
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), S(), 0, 0, S());
+    test(S(), S(), 1, 0, S());
+    test(S(), S("12345"), 0, 3, S("123"));
+    test(S(), S("12345"), 1, 4, S("2345"));
+    test(S(), S("12345"), 3, 15, S("45"));
+    test(S(), S("12345"), 5, 15, S(""));
+    test(S(), S("12345"), 6, 15, S("not happening"));
+    test(S(), S("12345678901234567890"), 0, 0, S());
+    test(S(), S("12345678901234567890"), 1, 1, S("2"));
+    test(S(), S("12345678901234567890"), 2, 3, S("345"));
+    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
+    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
+
+    test(S("12345"), S(), 0, 0, S("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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/initializer_list.pass.cpp
new file mode 100644
index 0000000..61bab9c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/initializer_list.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& assign(initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("123");
+        s.assign({'a', 'b', 'c'});
+        assert(s == "abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/iterator.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/iterator.pass.cpp
new file mode 100644
index 0000000..b305674
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/iterator.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class InputIterator> 
+//   basic_string& assign(InputIterator first, InputIterator last);
+
+#include <string>
+#include <cassert>
+
+#include "../../input_iterator.h"
+
+template <class S, class It>
+void
+test(S s, It first, It last, S expected)
+{
+    s.assign(first, last);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    test(S(), s, s, S());
+    test(S(), s, s+1, S("A"));
+    test(S(), s, s+10, S("ABCDEFGHIJ"));
+    test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), s, s, S());
+    test(S("12345"), s, s+1, S("A"));
+    test(S("12345"), s, s+10, S("ABCDEFGHIJ"));
+    test(S("12345"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), s, s, S());
+    test(S("1234567890"), s, s+1, S("A"));
+    test(S("1234567890"), s, s+10, S("ABCDEFGHIJ"));
+    test(S("1234567890"), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), s, s, S());
+    test(S("12345678901234567890"), s, s+1, S("A"));
+    test(S("12345678901234567890"), s, s+10, S("ABCDEFGHIJ"));
+    test(S("12345678901234567890"), s, s+52,
+         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S());
+    test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A"));
+    test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("ABCDEFGHIJ"));
+    test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S());
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("A"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("ABCDEFGHIJ"));
+    test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S());
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("A"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("ABCDEFGHIJ"));
+    test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s),
+         S());
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1),
+         S("A"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10),
+         S("ABCDEFGHIJ"));
+    test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52),
+         S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer.pass.cpp
new file mode 100644
index 0000000..62c1ce3
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& assign(const charT* s);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, const typename S::value_type* str, S expected)
+{
+    s.assign(str);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), "", S());
+    test(S(), "12345", S("12345"));
+    test(S(), "12345678901234567890", S("12345678901234567890"));
+
+    test(S("12345"), "", S());
+    test(S("12345"), "12345", S("12345"));
+    test(S("12345"), "1234567890", S("1234567890"));
+
+    test(S("12345678901234567890"), "", S());
+    test(S("12345678901234567890"), "12345", S("12345"));
+    test(S("12345678901234567890"), "12345678901234567890",
+         S("12345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer_size.pass.cpp
new file mode 100644
index 0000000..7e90b24
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/pointer_size.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   assign(const charT* s, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, const typename S::value_type* str, typename S::size_type n, S expected)
+{
+    s.assign(str, n);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), "", 0, S());
+    test(S(), "12345", 3, S("123"));
+    test(S(), "12345", 4, S("1234"));
+    test(S(), "12345678901234567890", 0, S());
+    test(S(), "12345678901234567890", 1, S("1"));
+    test(S(), "12345678901234567890", 3, S("123"));
+    test(S(), "12345678901234567890", 20, S("12345678901234567890"));
+
+    test(S("12345"), "", 0, S());
+    test(S("12345"), "12345", 5, S("12345"));
+    test(S("12345"), "1234567890", 10, S("1234567890"));
+
+    test(S("12345678901234567890"), "", 0, S());
+    test(S("12345678901234567890"), "12345", 5, S("12345"));
+    test(S("12345678901234567890"), "12345678901234567890", 20,
+         S("12345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/rv_string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/rv_string.pass.cpp
new file mode 100644
index 0000000..e62152c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/rv_string.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   assign(basic_string<charT,traits>&& str);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s, S str, S expected)
+{
+    s.assign(std::move(str));
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), S(), S());
+    test(S(), S("12345"), S("12345"));
+    test(S(), S("1234567890"), S("1234567890"));
+    test(S(), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("12345"), S(), S());
+    test(S("12345"), S("12345"), S("12345"));
+    test(S("12345"), S("1234567890"), S("1234567890"));
+    test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("1234567890"), S(), S());
+    test(S("1234567890"), S("12345"), S("12345"));
+    test(S("1234567890"), S("1234567890"), S("1234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S());
+    test(S("12345678901234567890"), S("12345"), S("12345"));
+    test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("12345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/size_char.pass.cpp
new file mode 100644
index 0000000..eb4eaad
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/size_char.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   assign(size_type n, charT c);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s, typename S::size_type n, typename S::value_type c, S expected)
+{
+    s.assign(n, c);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), 0, 'a', S());
+    test(S(), 1, 'a', S(1, 'a'));
+    test(S(), 10, 'a', S(10, 'a'));
+    test(S(), 100, 'a', S(100, 'a'));
+
+    test(S("12345"), 0, 'a', S());
+    test(S("12345"), 1, 'a', S(1, 'a'));
+    test(S("12345"), 10, 'a', S(10, 'a'));
+
+    test(S("12345678901234567890"), 0, 'a', S());
+    test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
+    test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string.pass.cpp
new file mode 100644
index 0000000..d9dccb3
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   assign(const basic_string<charT,traits>& str);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S s, S str, S expected)
+{
+    s.assign(str);
+    assert(s.__invariants());
+    assert(s == expected);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), S(), S());
+    test(S(), S("12345"), S("12345"));
+    test(S(), S("1234567890"), S("1234567890"));
+    test(S(), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("12345"), S(), S());
+    test(S("12345"), S("12345"), S("12345"));
+    test(S("12345"), S("1234567890"), S("1234567890"));
+    test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("1234567890"), S(), S());
+    test(S("1234567890"), S("12345"), S("12345"));
+    test(S("1234567890"), S("1234567890"), S("1234567890"));
+    test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
+
+    test(S("12345678901234567890"), S(), S());
+    test(S("12345678901234567890"), S("12345"), S("12345"));
+    test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
+    test(S("12345678901234567890"), S("12345678901234567890"),
+         S("12345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::assign/string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string_size_size.pass.cpp
new file mode 100644
index 0000000..d5bfc39
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::assign/string_size_size.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   assign(const basic_string<charT,traits>& str, size_type pos, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+template <class S>
+void
+test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
+{
+    try
+    {
+        s.assign(str, pos, n);
+        assert(s.__invariants());
+        assert(pos <= str.size());
+        assert(s == expected);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > str.size());
+    }
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(), S(), 0, 0, S());
+    test(S(), S(), 1, 0, S());
+    test(S(), S("12345"), 0, 3, S("123"));
+    test(S(), S("12345"), 1, 4, S("2345"));
+    test(S(), S("12345"), 3, 15, S("45"));
+    test(S(), S("12345"), 5, 15, S(""));
+    test(S(), S("12345"), 6, 15, S("not happening"));
+    test(S(), S("12345678901234567890"), 0, 0, S());
+    test(S(), S("12345678901234567890"), 1, 1, S("2"));
+    test(S(), S("12345678901234567890"), 2, 3, S("345"));
+    test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
+    test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
+
+    test(S("12345"), S(), 0, 0, S());
+    test(S("12345"), S("12345"), 2, 2, S("34"));
+    test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
+
+    test(S("12345678901234567890"), S(), 0, 0, S());
+    test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
+    test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
+         S("6789012345"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::copy/copy.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::copy/copy.pass.cpp
new file mode 100644
index 0000000..71c82b5
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::copy/copy.pass.cpp
@@ -0,0 +1,102 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. 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>
+
+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);
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter.pass.cpp
new file mode 100644
index 0000000..348ded3
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// iterator erase(const_iterator p);
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter_iter.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter_iter.pass.cpp
new file mode 100644
index 0000000..97c405f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::erase/iter_iter.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// iterator erase(const_iterator first, const_iterator last);
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::erase/pop_back.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::erase/pop_back.pass.cpp
new file mode 100644
index 0000000..5af7784
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::erase/pop_back.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void pop_back();
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::erase/size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::erase/size_size.pass.cpp
new file mode 100644
index 0000000..86a7b29
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::erase/size_size.pass.cpp
@@ -0,0 +1,171 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   erase(size_type pos = 0, size_type n = npos);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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(""));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_char.pass.cpp
new file mode 100644
index 0000000..358d40e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_char.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// iterator insert(const_iterator p, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_initializer_list.pass.cpp
new file mode 100644
index 0000000..ad95511
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_initializer_list.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// iterator insert(const_iterator p, initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("123456");
+        std::string::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'});
+        assert(i - s.begin() == 3);
+        assert(s == "123abc456");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_iter_iter.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_iter_iter.pass.cpp
new file mode 100644
index 0000000..87304c6
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_iter_iter.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class InputIterator> 
+//   iterator insert(const_iterator p, InputIterator first, InputIterator last);
+
+#include <string>
+#include <cassert>
+
+#include "../../input_iterator.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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_size_char.pass.cpp
new file mode 100644
index 0000000..89d6e5c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/iter_size_char.pass.cpp
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// iterator insert(const_iterator p, size_type n, charT c);
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer.pass.cpp
new file mode 100644
index 0000000..a36e42e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer.pass.cpp
@@ -0,0 +1,122 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   insert(size_type pos, const charT* s);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer_size.pass.cpp
new file mode 100644
index 0000000..40460c0
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_pointer_size.pass.cpp
@@ -0,0 +1,363 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   insert(size_type pos, const charT* s, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_size_char.pass.cpp
new file mode 100644
index 0000000..280789a
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_size_char.pass.cpp
@@ -0,0 +1,123 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   insert(size_type pos, size_type n, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string.pass.cpp
new file mode 100644
index 0000000..7b2bd84
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string.pass.cpp
@@ -0,0 +1,122 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   insert(size_type pos1, const basic_string& str);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string_size_size.pass.cpp
new file mode 100644
index 0000000..aa076a5
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::insert/size_string_size_size.pass.cpp
@@ -0,0 +1,1674 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   insert(size_type pos1, const basic_string<charT,traits,Allocator>& str, 
+//          size_type pos2, size_type n);
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S str, S::size_type pos2,
+     S::size_type n, S expected)
+{
+    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);
+    }
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+    test9();
+    test10();
+    test11();
+    test12();
+    test13();
+    test14();
+    test15();
+    test16();
+    test17();
+    test18();
+    test19();
+    test20();
+    test21();
+    test22();
+    test23();
+    test24();
+    test25();
+    test26();
+    test27();
+    test28();
+    test29();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::op+=/char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/char.pass.cpp
new file mode 100644
index 0000000..a3b2cbe
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/char.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& operator+=(charT c);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S 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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::op+=/initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/initializer_list.pass.cpp
new file mode 100644
index 0000000..cae4a08
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/initializer_list.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& operator+=(initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("123");
+        s += {'a', 'b', 'c'};
+        assert(s == "123abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::op+=/pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/pointer.pass.cpp
new file mode 100644
index 0000000..4216fd4
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/pointer.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& operator+=(const charT* s);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(S 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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::op+=/string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/string.pass.cpp
new file mode 100644
index 0000000..e5aea3f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::op+=/string.pass.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   operator+=(const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <cassert>
+
+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"));
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_initializer_list.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_initializer_list.pass.cpp
new file mode 100644
index 0000000..8b697e0
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_initializer_list.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string& replace(iterator i1, iterator i2, initializer_list<charT> il);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("123def456");
+        s.replace(s.begin() + 3, s.begin() + 6, {'a', 'b', 'c'});
+        assert(s == "123abc456");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_iter_iter.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_iter_iter.pass.cpp
new file mode 100644
index 0000000..63736c8
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_iter_iter.pass.cpp
@@ -0,0 +1,952 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class InputIterator> 
+//   basic_string&
+//   replace(iterator i1, iterator i2, InputIterator j1, InputIterator j2);
+
+#include <string>
+#include <iterator>
+#include <cassert>
+
+#include <stdio.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::iterator first = s.begin() + pos1;
+    typename S::iterator last = s.begin() + pos1 + n1;
+    s.replace(first, last, f, l);
+    assert(s.__invariants());
+    assert(s == expected);
+    typename S::size_type xlen = last - first;
+    typename S::size_type rlen = std::distance(f, l);
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+typedef std::string S;
+
+const char* str = "12345678901234567890";
+
+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"));
+}
+/*
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+//     test1();
+//     test2();
+//     test3();
+//     test4();
+//     test5();
+//     test6();
+//     test7();
+//     test8();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer.pass.cpp
new file mode 100644
index 0000000..19fb890
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer.pass.cpp
@@ -0,0 +1,270 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(iterator i1, iterator i2, const charT* s);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S::size_type n1, const S::value_type* str, S expected)
+{
+    S::size_type old_size = s.size();
+    S::iterator first = s.begin() + pos1;
+    S::iterator last = s.begin() + pos1 + n1;
+    s.replace(first, last, str);
+    assert(s.__invariants());
+    assert(s == expected);
+    S::size_type xlen = last - first;
+    S::size_type rlen = S::traits_type::length(str);
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer_size.pass.cpp
new file mode 100644
index 0000000..e52f2ab
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_pointer_size.pass.cpp
@@ -0,0 +1,949 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(iterator i1, iterator i2, const charT* s, size_type n);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S::size_type n1, const S::value_type* str,
+     S::size_type n2, S expected)
+{
+    S::size_type old_size = s.size();
+    S::iterator first = s.begin() + pos1;
+    S::iterator last = s.begin() + pos1 + n1;
+    s.replace(first, last, str, n2);
+    assert(s.__invariants());
+    assert(s == expected);
+    S::size_type xlen = last - first;
+    S::size_type rlen = n2;
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_size_char.pass.cpp
new file mode 100644
index 0000000..51d7e14
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_size_char.pass.cpp
@@ -0,0 +1,271 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(iterator i1, iterator i2, size_type n, charT c);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S::size_type n1, S::size_type n2,
+     S::value_type c, S expected)
+{
+    S::size_type old_size = s.size();
+    S::iterator first = s.begin() + pos1;
+    S::iterator last = s.begin() + pos1 + n1;
+    s.replace(first, last, n2, c);
+    assert(s.__invariants());
+    assert(s == expected);
+    S::size_type xlen = last - first;
+    S::size_type rlen = n2;
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_string.pass.cpp
new file mode 100644
index 0000000..9cfaafb
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/iter_iter_string.pass.cpp
@@ -0,0 +1,270 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(iterator i1, iterator i2, const basic_string& str);
+
+#include <stdio.h>
+
+#include <string>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S::size_type n1, S str, S expected)
+{
+    S::size_type old_size = s.size();
+    S::iterator first = s.begin() + pos1;
+    S::iterator last = s.begin() + pos1 + n1;
+    s.replace(first, last, str);
+    assert(s.__invariants());
+    assert(s == expected);
+    S::size_type xlen = last - first;
+    S::size_type rlen = str.size();
+    assert(s.size() == old_size - xlen + rlen);
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer.pass.cpp
new file mode 100644
index 0000000..299dc57
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer.pass.cpp
@@ -0,0 +1,360 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(size_type pos, size_type n1, const charT* s);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s,   S::size_type pos, S::size_type n1,
+     const S::value_type* str, S expected)
+{
+    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);
+        S::size_type xlen = std::min(n1, old_size - pos);
+        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);
+    }
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer_size.pass.cpp
new file mode 100644
index 0000000..4719fe4
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_pointer_size.pass.cpp
@@ -0,0 +1,1294 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(size_type pos, size_type n1, const charT* s, size_type n2);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s,   S::size_type pos, S::size_type n1,
+     const S::value_type* str, S::size_type n2,
+     S expected)
+{
+    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);
+        S::size_type xlen = std::min(n1, old_size - pos);
+        S::size_type rlen = n2;
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+    test9();
+    test10();
+    test11();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_size_char.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_size_char.pass.cpp
new file mode 100644
index 0000000..738c62d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_size_char.pass.cpp
@@ -0,0 +1,359 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(size_type pos, size_type n1, size_type n2, charT c);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s,   S::size_type pos, S::size_type n1,
+     S::size_type n2, S::value_type c,
+     S expected)
+{
+    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);
+        S::size_type xlen = std::min(n1, old_size - pos);
+        S::size_type rlen = n2;
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > old_size);
+        assert(s == s0);
+    }
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string.pass.cpp
new file mode 100644
index 0000000..49c4955
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string.pass.cpp
@@ -0,0 +1,359 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(size_type pos1, size_type n1, const basic_string<charT,traits,Allocator>& str);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s, S::size_type pos1, S::size_type n1, S str, S expected)
+{
+    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);
+        S::size_type xlen = std::min(n1, old_size - pos1);
+        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);
+    }
+}
+
+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"));
+}
+
+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"));
+}
+
+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()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string_size_size.pass.cpp
new file mode 100644
index 0000000..25cf951
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::replace/size_size_string_size_size.pass.cpp
@@ -0,0 +1,5802 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string<charT,traits,Allocator>& 
+//   replace(size_type pos1, size_type n1, const basic_string<charT,traits,Allocator>& str, 
+//           size_type pos2, size_type n2);
+
+#include <stdio.h>
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+typedef std::string S;
+
+void
+test(S s,   S::size_type pos1, S::size_type n1,
+     S str, S::size_type pos2, S::size_type n2,
+     S expected)
+{
+    S::size_type old_size = s.size();
+    S s0 = s;
+    try
+    {
+        s.replace(pos1, n1, str, pos2, n2);
+        assert(s.__invariants());
+        assert(pos1 <= old_size && pos2 <= str.size());
+        assert(s == expected);
+        S::size_type xlen = std::min(n1, old_size - pos1);
+        S::size_type rlen = std::min(n2, str.size() - pos2);
+        assert(s.size() == old_size - xlen + rlen);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > old_size || pos2 > str.size());
+        assert(s == s0);
+    }
+}
+
+void test0()
+{
+    test(S(""), 0, 0, S(""), 0, 0, S(""));
+    test(S(""), 0, 0, S(""), 0, 1, S(""));
+    test(S(""), 0, 0, S(""), 1, 0, S("can't happen"));
+    test(S(""), 0, 0, S("12345"), 0, 0, S(""));
+    test(S(""), 0, 0, S("12345"), 0, 1, S("1"));
+    test(S(""), 0, 0, S("12345"), 0, 2, S("12"));
+    test(S(""), 0, 0, S("12345"), 0, 4, S("1234"));
+    test(S(""), 0, 0, S("12345"), 0, 5, S("12345"));
+    test(S(""), 0, 0, S("12345"), 0, 6, S("12345"));
+    test(S(""), 0, 0, S("12345"), 1, 0, S(""));
+    test(S(""), 0, 0, S("12345"), 1, 1, S("2"));
+    test(S(""), 0, 0, S("12345"), 1, 2, S("23"));
+    test(S(""), 0, 0, S("12345"), 1, 3, S("234"));
+    test(S(""), 0, 0, S("12345"), 1, 4, S("2345"));
+    test(S(""), 0, 0, S("12345"), 1, 5, S("2345"));
+    test(S(""), 0, 0, S("12345"), 2, 0, S(""));
+    test(S(""), 0, 0, S("12345"), 2, 1, S("3"));
+    test(S(""), 0, 0, S("12345"), 2, 2, S("34"));
+    test(S(""), 0, 0, S("12345"), 2, 3, S("345"));
+    test(S(""), 0, 0, S("12345"), 2, 4, S("345"));
+    test(S(""), 0, 0, S("12345"), 4, 0, S(""));
+    test(S(""), 0, 0, S("12345"), 4, 1, S("5"));
+    test(S(""), 0, 0, S("12345"), 4, 2, S("5"));
+    test(S(""), 0, 0, S("12345"), 5, 0, S(""));
+    test(S(""), 0, 0, S("12345"), 5, 1, S(""));
+    test(S(""), 0, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S(""), 0, 0, S("1234567890"), 0, 0, S(""));
+    test(S(""), 0, 0, S("1234567890"), 0, 1, S("1"));
+    test(S(""), 0, 0, S("1234567890"), 0, 5, S("12345"));
+    test(S(""), 0, 0, S("1234567890"), 0, 9, S("123456789"));
+    test(S(""), 0, 0, S("1234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, 0, S("1234567890"), 0, 11, S("1234567890"));
+    test(S(""), 0, 0, S("1234567890"), 1, 0, S(""));
+    test(S(""), 0, 0, S("1234567890"), 1, 1, S("2"));
+    test(S(""), 0, 0, S("1234567890"), 1, 4, S("2345"));
+    test(S(""), 0, 0, S("1234567890"), 1, 8, S("23456789"));
+    test(S(""), 0, 0, S("1234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, 0, S("1234567890"), 1, 10, S("234567890"));
+    test(S(""), 0, 0, S("1234567890"), 5, 0, S(""));
+    test(S(""), 0, 0, S("1234567890"), 5, 1, S("6"));
+    test(S(""), 0, 0, S("1234567890"), 5, 2, S("67"));
+    test(S(""), 0, 0, S("1234567890"), 5, 4, S("6789"));
+    test(S(""), 0, 0, S("1234567890"), 5, 5, S("67890"));
+    test(S(""), 0, 0, S("1234567890"), 5, 6, S("67890"));
+    test(S(""), 0, 0, S("1234567890"), 9, 0, S(""));
+    test(S(""), 0, 0, S("1234567890"), 9, 1, S("0"));
+    test(S(""), 0, 0, S("1234567890"), 9, 2, S("0"));
+    test(S(""), 0, 0, S("1234567890"), 10, 0, S(""));
+    test(S(""), 0, 0, S("1234567890"), 10, 1, S(""));
+    test(S(""), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 0, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 1, S("1"));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 0, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 1, S("2"));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 0, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 1, S("1"));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S(""), 0, 0, S("12345678901234567890"), 19, 0, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 19, 1, S("0"));
+    test(S(""), 0, 0, S("12345678901234567890"), 19, 2, S("0"));
+    test(S(""), 0, 0, S("12345678901234567890"), 20, 0, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 20, 1, S(""));
+    test(S(""), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S(""), 0, 1, S(""), 0, 0, S(""));
+    test(S(""), 0, 1, S(""), 0, 1, S(""));
+    test(S(""), 0, 1, S(""), 1, 0, S("can't happen"));
+    test(S(""), 0, 1, S("12345"), 0, 0, S(""));
+    test(S(""), 0, 1, S("12345"), 0, 1, S("1"));
+    test(S(""), 0, 1, S("12345"), 0, 2, S("12"));
+    test(S(""), 0, 1, S("12345"), 0, 4, S("1234"));
+    test(S(""), 0, 1, S("12345"), 0, 5, S("12345"));
+    test(S(""), 0, 1, S("12345"), 0, 6, S("12345"));
+    test(S(""), 0, 1, S("12345"), 1, 0, S(""));
+    test(S(""), 0, 1, S("12345"), 1, 1, S("2"));
+    test(S(""), 0, 1, S("12345"), 1, 2, S("23"));
+    test(S(""), 0, 1, S("12345"), 1, 3, S("234"));
+    test(S(""), 0, 1, S("12345"), 1, 4, S("2345"));
+    test(S(""), 0, 1, S("12345"), 1, 5, S("2345"));
+    test(S(""), 0, 1, S("12345"), 2, 0, S(""));
+    test(S(""), 0, 1, S("12345"), 2, 1, S("3"));
+    test(S(""), 0, 1, S("12345"), 2, 2, S("34"));
+    test(S(""), 0, 1, S("12345"), 2, 3, S("345"));
+    test(S(""), 0, 1, S("12345"), 2, 4, S("345"));
+    test(S(""), 0, 1, S("12345"), 4, 0, S(""));
+    test(S(""), 0, 1, S("12345"), 4, 1, S("5"));
+    test(S(""), 0, 1, S("12345"), 4, 2, S("5"));
+    test(S(""), 0, 1, S("12345"), 5, 0, S(""));
+    test(S(""), 0, 1, S("12345"), 5, 1, S(""));
+    test(S(""), 0, 1, S("12345"), 6, 0, S("can't happen"));
+}
+
+void test1()
+{
+    test(S(""), 0, 1, S("1234567890"), 0, 0, S(""));
+    test(S(""), 0, 1, S("1234567890"), 0, 1, S("1"));
+    test(S(""), 0, 1, S("1234567890"), 0, 5, S("12345"));
+    test(S(""), 0, 1, S("1234567890"), 0, 9, S("123456789"));
+    test(S(""), 0, 1, S("1234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, 1, S("1234567890"), 0, 11, S("1234567890"));
+    test(S(""), 0, 1, S("1234567890"), 1, 0, S(""));
+    test(S(""), 0, 1, S("1234567890"), 1, 1, S("2"));
+    test(S(""), 0, 1, S("1234567890"), 1, 4, S("2345"));
+    test(S(""), 0, 1, S("1234567890"), 1, 8, S("23456789"));
+    test(S(""), 0, 1, S("1234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, 1, S("1234567890"), 1, 10, S("234567890"));
+    test(S(""), 0, 1, S("1234567890"), 5, 0, S(""));
+    test(S(""), 0, 1, S("1234567890"), 5, 1, S("6"));
+    test(S(""), 0, 1, S("1234567890"), 5, 2, S("67"));
+    test(S(""), 0, 1, S("1234567890"), 5, 4, S("6789"));
+    test(S(""), 0, 1, S("1234567890"), 5, 5, S("67890"));
+    test(S(""), 0, 1, S("1234567890"), 5, 6, S("67890"));
+    test(S(""), 0, 1, S("1234567890"), 9, 0, S(""));
+    test(S(""), 0, 1, S("1234567890"), 9, 1, S("0"));
+    test(S(""), 0, 1, S("1234567890"), 9, 2, S("0"));
+    test(S(""), 0, 1, S("1234567890"), 10, 0, S(""));
+    test(S(""), 0, 1, S("1234567890"), 10, 1, S(""));
+    test(S(""), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 0, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 1, S("1"));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 0, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 1, S("2"));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 0, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 1, S("1"));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S(""), 0, 1, S("12345678901234567890"), 19, 0, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 19, 1, S("0"));
+    test(S(""), 0, 1, S("12345678901234567890"), 19, 2, S("0"));
+    test(S(""), 0, 1, S("12345678901234567890"), 20, 0, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 20, 1, S(""));
+    test(S(""), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S(""), 1, 0, S(""), 0, 0, S("can't happen"));
+    test(S(""), 1, 0, S(""), 0, 1, S("can't happen"));
+    test(S(""), 1, 0, S(""), 1, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 2, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 4, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 5, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 0, 6, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 2, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 3, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 4, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 1, 5, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 2, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 2, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 2, 2, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 2, 3, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 2, 4, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 4, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 4, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 4, 2, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 5, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 5, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 1, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 5, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 9, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 10, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 0, 11, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 1, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 4, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 8, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 9, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 1, 10, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 1, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 2, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 4, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 5, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 5, 6, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 9, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 9, 1, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 9, 2, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 10, 0, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 10, 1, S("can't happen"));
+    test(S(""), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
+}
+
+void test2()
+{
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S(""), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 0, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 1, S("1abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 2, S("12abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 4, S("1234abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 0, 6, S("12345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 2, S("23abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 3, S("234abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 4, S("2345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 1, 5, S("2345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 2, 1, S("3abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 2, 2, S("34abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 2, 3, S("345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 2, 4, S("345abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 4, 1, S("5abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 4, 2, S("5abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 1, S("1abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 9, S("123456789abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 4, S("2345abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 8, S("23456789abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 9, S("234567890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 1, 10, S("234567890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 1, S("6abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 2, S("67abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 4, S("6789abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 5, S("67890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 5, 6, S("67890abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 9, 1, S("0abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 9, 2, S("0abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 1, S(""), 0, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S(""), 0, 1, S("bcde"));
+    test(S("abcde"), 0, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 1, S("12345"), 0, 0, S("bcde"));
+}
+
+void test3()
+{
+    test(S("abcde"), 0, 1, S("12345"), 0, 1, S("1bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 0, 2, S("12bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 0, 4, S("1234bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 0, 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 0, 6, S("12345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 1, S("2bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 2, S("23bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 3, S("234bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 4, S("2345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 1, 5, S("2345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 2, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 2, 1, S("3bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 2, 2, S("34bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 2, 3, S("345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 2, 4, S("345bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 4, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 4, 1, S("5bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 4, 2, S("5bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 5, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 5, 1, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 1, S("1bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 9, S("123456789bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 1, S("2bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 4, S("2345bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 8, S("23456789bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 9, S("234567890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 1, 10, S("234567890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 1, S("6bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 2, S("67bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 4, S("6789bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 5, S("67890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 5, 6, S("67890bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 9, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 9, 1, S("0bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 9, 2, S("0bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 10, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 10, 1, S("bcde"));
+    test(S("abcde"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 20, 0, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 20, 1, S("bcde"));
+    test(S("abcde"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 2, S(""), 0, 0, S("cde"));
+    test(S("abcde"), 0, 2, S(""), 0, 1, S("cde"));
+    test(S("abcde"), 0, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 1, S("1cde"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 2, S("12cde"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 4, S("1234cde"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 5, S("12345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 0, 6, S("12345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 1, S("2cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 2, S("23cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 3, S("234cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 4, S("2345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 1, 5, S("2345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 2, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 2, 1, S("3cde"));
+    test(S("abcde"), 0, 2, S("12345"), 2, 2, S("34cde"));
+    test(S("abcde"), 0, 2, S("12345"), 2, 3, S("345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 2, 4, S("345cde"));
+    test(S("abcde"), 0, 2, S("12345"), 4, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 4, 1, S("5cde"));
+    test(S("abcde"), 0, 2, S("12345"), 4, 2, S("5cde"));
+    test(S("abcde"), 0, 2, S("12345"), 5, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 5, 1, S("cde"));
+    test(S("abcde"), 0, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 1, S("1cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 5, S("12345cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 9, S("123456789cde"));
+}
+
+void test4()
+{
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 0, 11, S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 1, S("2cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 4, S("2345cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 8, S("23456789cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 9, S("234567890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 1, 10, S("234567890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 1, S("6cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 2, S("67cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 4, S("6789cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 5, S("67890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 5, 6, S("67890cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 9, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 9, 1, S("0cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 9, 2, S("0cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 10, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 10, 1, S("cde"));
+    test(S("abcde"), 0, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 1, S("1cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 19, S("1234567890123456789cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 20, S("12345678901234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 0, 21, S("12345678901234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 1, S("2cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 9, S("234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 18, S("234567890123456789cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 19, S("2345678901234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 1, 20, S("2345678901234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 1, S("1cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 5, S("12345cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 9, S("123456789cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 10, S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 10, 11, S("1234567890cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 1, S("0cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 19, 2, S("0cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 20, 0, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 20, 1, S("cde"));
+    test(S("abcde"), 0, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 4, S(""), 0, 0, S("e"));
+    test(S("abcde"), 0, 4, S(""), 0, 1, S("e"));
+    test(S("abcde"), 0, 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 1, S("1e"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 2, S("12e"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 4, S("1234e"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 5, S("12345e"));
+    test(S("abcde"), 0, 4, S("12345"), 0, 6, S("12345e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 1, S("2e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 2, S("23e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 3, S("234e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 4, S("2345e"));
+    test(S("abcde"), 0, 4, S("12345"), 1, 5, S("2345e"));
+    test(S("abcde"), 0, 4, S("12345"), 2, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 2, 1, S("3e"));
+    test(S("abcde"), 0, 4, S("12345"), 2, 2, S("34e"));
+    test(S("abcde"), 0, 4, S("12345"), 2, 3, S("345e"));
+    test(S("abcde"), 0, 4, S("12345"), 2, 4, S("345e"));
+    test(S("abcde"), 0, 4, S("12345"), 4, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 4, 1, S("5e"));
+    test(S("abcde"), 0, 4, S("12345"), 4, 2, S("5e"));
+    test(S("abcde"), 0, 4, S("12345"), 5, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 5, 1, S("e"));
+    test(S("abcde"), 0, 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 0, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 1, S("1e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 5, S("12345e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 9, S("123456789e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 0, 11, S("1234567890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 0, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 1, S("2e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 4, S("2345e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 8, S("23456789e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 9, S("234567890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 1, 10, S("234567890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 0, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 1, S("6e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 2, S("67e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 4, S("6789e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 5, S("67890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 5, 6, S("67890e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 9, 0, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 9, 1, S("0e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 9, 2, S("0e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 10, 0, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 10, 1, S("e"));
+    test(S("abcde"), 0, 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 1, S("1e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 19, S("1234567890123456789e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 20, S("12345678901234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 0, 21, S("12345678901234567890e"));
+}
+
+void test5()
+{
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 1, S("2e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 9, S("234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 18, S("234567890123456789e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 19, S("2345678901234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 1, 20, S("2345678901234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 1, S("1e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 5, S("12345e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 9, S("123456789e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 10, S("1234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 10, 11, S("1234567890e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 1, S("0e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 19, 2, S("0e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 20, 0, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 20, 1, S("e"));
+    test(S("abcde"), 0, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 5, S(""), 0, 0, S(""));
+    test(S("abcde"), 0, 5, S(""), 0, 1, S(""));
+    test(S("abcde"), 0, 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 5, S("12345"), 0, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 0, 1, S("1"));
+    test(S("abcde"), 0, 5, S("12345"), 0, 2, S("12"));
+    test(S("abcde"), 0, 5, S("12345"), 0, 4, S("1234"));
+    test(S("abcde"), 0, 5, S("12345"), 0, 5, S("12345"));
+    test(S("abcde"), 0, 5, S("12345"), 0, 6, S("12345"));
+    test(S("abcde"), 0, 5, S("12345"), 1, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 1, 1, S("2"));
+    test(S("abcde"), 0, 5, S("12345"), 1, 2, S("23"));
+    test(S("abcde"), 0, 5, S("12345"), 1, 3, S("234"));
+    test(S("abcde"), 0, 5, S("12345"), 1, 4, S("2345"));
+    test(S("abcde"), 0, 5, S("12345"), 1, 5, S("2345"));
+    test(S("abcde"), 0, 5, S("12345"), 2, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 2, 1, S("3"));
+    test(S("abcde"), 0, 5, S("12345"), 2, 2, S("34"));
+    test(S("abcde"), 0, 5, S("12345"), 2, 3, S("345"));
+    test(S("abcde"), 0, 5, S("12345"), 2, 4, S("345"));
+    test(S("abcde"), 0, 5, S("12345"), 4, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 4, 1, S("5"));
+    test(S("abcde"), 0, 5, S("12345"), 4, 2, S("5"));
+    test(S("abcde"), 0, 5, S("12345"), 5, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 5, 1, S(""));
+    test(S("abcde"), 0, 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 0, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 1, S("1"));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 9, S("123456789"));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 0, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 1, S("2"));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 0, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 1, S("6"));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 2, S("67"));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcde"), 0, 5, S("1234567890"), 9, 0, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 9, 1, S("0"));
+    test(S("abcde"), 0, 5, S("1234567890"), 9, 2, S("0"));
+    test(S("abcde"), 0, 5, S("1234567890"), 10, 0, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 10, 1, S(""));
+    test(S("abcde"), 0, 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcde"), 0, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 0, 6, S(""), 0, 0, S(""));
+    test(S("abcde"), 0, 6, S(""), 0, 1, S(""));
+    test(S("abcde"), 0, 6, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 0, 6, S("12345"), 0, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 0, 1, S("1"));
+    test(S("abcde"), 0, 6, S("12345"), 0, 2, S("12"));
+    test(S("abcde"), 0, 6, S("12345"), 0, 4, S("1234"));
+    test(S("abcde"), 0, 6, S("12345"), 0, 5, S("12345"));
+}
+
+void test6()
+{
+    test(S("abcde"), 0, 6, S("12345"), 0, 6, S("12345"));
+    test(S("abcde"), 0, 6, S("12345"), 1, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 1, 1, S("2"));
+    test(S("abcde"), 0, 6, S("12345"), 1, 2, S("23"));
+    test(S("abcde"), 0, 6, S("12345"), 1, 3, S("234"));
+    test(S("abcde"), 0, 6, S("12345"), 1, 4, S("2345"));
+    test(S("abcde"), 0, 6, S("12345"), 1, 5, S("2345"));
+    test(S("abcde"), 0, 6, S("12345"), 2, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 2, 1, S("3"));
+    test(S("abcde"), 0, 6, S("12345"), 2, 2, S("34"));
+    test(S("abcde"), 0, 6, S("12345"), 2, 3, S("345"));
+    test(S("abcde"), 0, 6, S("12345"), 2, 4, S("345"));
+    test(S("abcde"), 0, 6, S("12345"), 4, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 4, 1, S("5"));
+    test(S("abcde"), 0, 6, S("12345"), 4, 2, S("5"));
+    test(S("abcde"), 0, 6, S("12345"), 5, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 5, 1, S(""));
+    test(S("abcde"), 0, 6, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 0, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 1, S("1"));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 9, S("123456789"));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 0, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 1, S("2"));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 0, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 1, S("6"));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 2, S("67"));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcde"), 0, 6, S("1234567890"), 9, 0, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 9, 1, S("0"));
+    test(S("abcde"), 0, 6, S("1234567890"), 9, 2, S("0"));
+    test(S("abcde"), 0, 6, S("1234567890"), 10, 0, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 10, 1, S(""));
+    test(S("abcde"), 0, 6, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcde"), 0, 6, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 1, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 2, S("a12bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 4, S("a1234bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 0, 6, S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 1, S("a2bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 2, S("a23bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 3, S("a234bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 4, S("a2345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 1, 5, S("a2345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 2, 1, S("a3bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 2, 2, S("a34bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 2, 3, S("a345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 2, 4, S("a345bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 4, 1, S("a5bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 4, 2, S("a5bcde"));
+    test(S("abcde"), 1, 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 1, S("a2bcde"));
+}
+
+void test7()
+{
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 4, S("a2345bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 1, S("a6bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 2, S("a67bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 4, S("a6789bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 5, S("a67890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 5, 6, S("a67890bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 9, 1, S("a0bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 9, 2, S("a0bcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 1, S(""), 0, 0, S("acde"));
+    test(S("abcde"), 1, 1, S(""), 0, 1, S("acde"));
+    test(S("abcde"), 1, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 1, S("a1cde"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 2, S("a12cde"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 4, S("a1234cde"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 0, 6, S("a12345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 1, S("a2cde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 2, S("a23cde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 3, S("a234cde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 4, S("a2345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 1, 5, S("a2345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 2, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 2, 1, S("a3cde"));
+    test(S("abcde"), 1, 1, S("12345"), 2, 2, S("a34cde"));
+    test(S("abcde"), 1, 1, S("12345"), 2, 3, S("a345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 2, 4, S("a345cde"));
+    test(S("abcde"), 1, 1, S("12345"), 4, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 4, 1, S("a5cde"));
+    test(S("abcde"), 1, 1, S("12345"), 4, 2, S("a5cde"));
+    test(S("abcde"), 1, 1, S("12345"), 5, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 5, 1, S("acde"));
+    test(S("abcde"), 1, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 1, S("a1cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 9, S("a123456789cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 1, S("a2cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 4, S("a2345cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 8, S("a23456789cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 9, S("a234567890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 1, 10, S("a234567890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 1, S("a6cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 2, S("a67cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 4, S("a6789cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 5, S("a67890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 5, 6, S("a67890cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 9, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 9, 1, S("a0cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 9, 2, S("a0cde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 10, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 10, 1, S("acde"));
+    test(S("abcde"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cde"));
+}
+
+void test8()
+{
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 20, 0, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 20, 1, S("acde"));
+    test(S("abcde"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 2, S(""), 0, 0, S("ade"));
+    test(S("abcde"), 1, 2, S(""), 0, 1, S("ade"));
+    test(S("abcde"), 1, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 1, S("a1de"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 2, S("a12de"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 4, S("a1234de"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 5, S("a12345de"));
+    test(S("abcde"), 1, 2, S("12345"), 0, 6, S("a12345de"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 1, S("a2de"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 2, S("a23de"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 3, S("a234de"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 4, S("a2345de"));
+    test(S("abcde"), 1, 2, S("12345"), 1, 5, S("a2345de"));
+    test(S("abcde"), 1, 2, S("12345"), 2, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 2, 1, S("a3de"));
+    test(S("abcde"), 1, 2, S("12345"), 2, 2, S("a34de"));
+    test(S("abcde"), 1, 2, S("12345"), 2, 3, S("a345de"));
+    test(S("abcde"), 1, 2, S("12345"), 2, 4, S("a345de"));
+    test(S("abcde"), 1, 2, S("12345"), 4, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 4, 1, S("a5de"));
+    test(S("abcde"), 1, 2, S("12345"), 4, 2, S("a5de"));
+    test(S("abcde"), 1, 2, S("12345"), 5, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 5, 1, S("ade"));
+    test(S("abcde"), 1, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 1, S("a1de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 5, S("a12345de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 9, S("a123456789de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 0, 11, S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 1, S("a2de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 4, S("a2345de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 8, S("a23456789de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 9, S("a234567890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 1, 10, S("a234567890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 1, S("a6de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 2, S("a67de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 4, S("a6789de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 5, S("a67890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 5, 6, S("a67890de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 9, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 9, 1, S("a0de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 9, 2, S("a0de"));
+    test(S("abcde"), 1, 2, S("1234567890"), 10, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 10, 1, S("ade"));
+    test(S("abcde"), 1, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 1, S("a1de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 19, S("a1234567890123456789de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 20, S("a12345678901234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 0, 21, S("a12345678901234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 1, S("a2de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 9, S("a234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 18, S("a234567890123456789de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 19, S("a2345678901234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 1, 20, S("a2345678901234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 1, S("a1de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 5, S("a12345de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 9, S("a123456789de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 10, S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 10, 11, S("a1234567890de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 1, S("a0de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 19, 2, S("a0de"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 20, 0, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 20, 1, S("ade"));
+    test(S("abcde"), 1, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 3, S(""), 0, 0, S("ae"));
+    test(S("abcde"), 1, 3, S(""), 0, 1, S("ae"));
+    test(S("abcde"), 1, 3, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 1, S("a1e"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 2, S("a12e"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 4, S("a1234e"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 5, S("a12345e"));
+    test(S("abcde"), 1, 3, S("12345"), 0, 6, S("a12345e"));
+    test(S("abcde"), 1, 3, S("12345"), 1, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 1, 1, S("a2e"));
+    test(S("abcde"), 1, 3, S("12345"), 1, 2, S("a23e"));
+}
+
+void test9()
+{
+    test(S("abcde"), 1, 3, S("12345"), 1, 3, S("a234e"));
+    test(S("abcde"), 1, 3, S("12345"), 1, 4, S("a2345e"));
+    test(S("abcde"), 1, 3, S("12345"), 1, 5, S("a2345e"));
+    test(S("abcde"), 1, 3, S("12345"), 2, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 2, 1, S("a3e"));
+    test(S("abcde"), 1, 3, S("12345"), 2, 2, S("a34e"));
+    test(S("abcde"), 1, 3, S("12345"), 2, 3, S("a345e"));
+    test(S("abcde"), 1, 3, S("12345"), 2, 4, S("a345e"));
+    test(S("abcde"), 1, 3, S("12345"), 4, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 4, 1, S("a5e"));
+    test(S("abcde"), 1, 3, S("12345"), 4, 2, S("a5e"));
+    test(S("abcde"), 1, 3, S("12345"), 5, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 5, 1, S("ae"));
+    test(S("abcde"), 1, 3, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 1, S("a1e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 5, S("a12345e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 9, S("a123456789e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 0, 11, S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 1, S("a2e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 4, S("a2345e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 8, S("a23456789e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 9, S("a234567890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 1, 10, S("a234567890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 1, S("a6e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 2, S("a67e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 4, S("a6789e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 5, S("a67890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 5, 6, S("a67890e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 9, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 9, 1, S("a0e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 9, 2, S("a0e"));
+    test(S("abcde"), 1, 3, S("1234567890"), 10, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 10, 1, S("ae"));
+    test(S("abcde"), 1, 3, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 1, S("a1e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 19, S("a1234567890123456789e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 20, S("a12345678901234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 0, 21, S("a12345678901234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 1, S("a2e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 9, S("a234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 18, S("a234567890123456789e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 19, S("a2345678901234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 1, 20, S("a2345678901234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 1, S("a1e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 5, S("a12345e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 9, S("a123456789e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 10, S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 10, 11, S("a1234567890e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 1, S("a0e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 19, 2, S("a0e"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 20, 0, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 20, 1, S("ae"));
+    test(S("abcde"), 1, 3, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 4, S(""), 0, 0, S("a"));
+    test(S("abcde"), 1, 4, S(""), 0, 1, S("a"));
+    test(S("abcde"), 1, 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 2, S("a12"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 4, S("a1234"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 5, S("a12345"));
+    test(S("abcde"), 1, 4, S("12345"), 0, 6, S("a12345"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 2, S("a23"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 3, S("a234"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 4, S("a2345"));
+    test(S("abcde"), 1, 4, S("12345"), 1, 5, S("a2345"));
+    test(S("abcde"), 1, 4, S("12345"), 2, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 2, 1, S("a3"));
+    test(S("abcde"), 1, 4, S("12345"), 2, 2, S("a34"));
+    test(S("abcde"), 1, 4, S("12345"), 2, 3, S("a345"));
+    test(S("abcde"), 1, 4, S("12345"), 2, 4, S("a345"));
+    test(S("abcde"), 1, 4, S("12345"), 4, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 4, 1, S("a5"));
+    test(S("abcde"), 1, 4, S("12345"), 4, 2, S("a5"));
+    test(S("abcde"), 1, 4, S("12345"), 5, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 5, 1, S("a"));
+    test(S("abcde"), 1, 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 0, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 0, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 8, S("a23456789"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcde"), 1, 4, S("1234567890"), 1, 10, S("a234567890"));
+}
+
+void test10()
+{
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 0, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcde"), 1, 4, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcde"), 1, 4, S("1234567890"), 9, 0, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcde"), 1, 4, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcde"), 1, 4, S("1234567890"), 10, 0, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 10, 1, S("a"));
+    test(S("abcde"), 1, 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 1, S("a1"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcde"), 1, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 1, 5, S(""), 0, 0, S("a"));
+    test(S("abcde"), 1, 5, S(""), 0, 1, S("a"));
+    test(S("abcde"), 1, 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 2, S("a12"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 4, S("a1234"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 5, S("a12345"));
+    test(S("abcde"), 1, 5, S("12345"), 0, 6, S("a12345"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 2, S("a23"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 3, S("a234"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 4, S("a2345"));
+    test(S("abcde"), 1, 5, S("12345"), 1, 5, S("a2345"));
+    test(S("abcde"), 1, 5, S("12345"), 2, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 2, 1, S("a3"));
+    test(S("abcde"), 1, 5, S("12345"), 2, 2, S("a34"));
+    test(S("abcde"), 1, 5, S("12345"), 2, 3, S("a345"));
+    test(S("abcde"), 1, 5, S("12345"), 2, 4, S("a345"));
+    test(S("abcde"), 1, 5, S("12345"), 4, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 4, 1, S("a5"));
+    test(S("abcde"), 1, 5, S("12345"), 4, 2, S("a5"));
+    test(S("abcde"), 1, 5, S("12345"), 5, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 5, 1, S("a"));
+    test(S("abcde"), 1, 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 0, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 0, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 8, S("a23456789"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 1, 10, S("a234567890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 0, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcde"), 1, 5, S("1234567890"), 9, 0, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcde"), 1, 5, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcde"), 1, 5, S("1234567890"), 10, 0, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 10, 1, S("a"));
+    test(S("abcde"), 1, 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 1, S("a1"));
+}
+
+void test11()
+{
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcde"), 1, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 2, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 2, S("ab12cde"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 4, S("ab1234cde"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 0, 6, S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 2, S("ab23cde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 3, S("ab234cde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 4, S("ab2345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 1, 5, S("ab2345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 2, 1, S("ab3cde"));
+    test(S("abcde"), 2, 0, S("12345"), 2, 2, S("ab34cde"));
+    test(S("abcde"), 2, 0, S("12345"), 2, 3, S("ab345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 2, 4, S("ab345cde"));
+    test(S("abcde"), 2, 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 4, 1, S("ab5cde"));
+    test(S("abcde"), 2, 0, S("12345"), 4, 2, S("ab5cde"));
+    test(S("abcde"), 2, 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 9, S("ab123456789cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 0, 11, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 4, S("ab2345cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 8, S("ab23456789cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 9, S("ab234567890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 1, 10, S("ab234567890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 1, S("ab6cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 2, S("ab67cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 4, S("ab6789cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 5, S("ab67890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 5, 6, S("ab67890cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 9, 1, S("ab0cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 9, 2, S("ab0cde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 2, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 19, S("ab1234567890123456789cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 20, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 0, 21, S("ab12345678901234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 1, S("ab2cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 9, S("ab234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 18, S("ab234567890123456789cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 19, S("ab2345678901234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 1, 20, S("ab2345678901234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 1, S("ab1cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 5, S("ab12345cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 9, S("ab123456789cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 10, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 10, 11, S("ab1234567890cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 1, S("ab0cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 19, 2, S("ab0cde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 2, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, 1, S(""), 0, 0, S("abde"));
+    test(S("abcde"), 2, 1, S(""), 0, 1, S("abde"));
+    test(S("abcde"), 2, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 1, S("ab1de"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 2, S("ab12de"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 4, S("ab1234de"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, S("12345"), 0, 6, S("ab12345de"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 1, S("ab2de"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 2, S("ab23de"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 3, S("ab234de"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 4, S("ab2345de"));
+    test(S("abcde"), 2, 1, S("12345"), 1, 5, S("ab2345de"));
+    test(S("abcde"), 2, 1, S("12345"), 2, 0, S("abde"));
+}
+
+void test12()
+{
+    test(S("abcde"), 2, 1, S("12345"), 2, 1, S("ab3de"));
+    test(S("abcde"), 2, 1, S("12345"), 2, 2, S("ab34de"));
+    test(S("abcde"), 2, 1, S("12345"), 2, 3, S("ab345de"));
+    test(S("abcde"), 2, 1, S("12345"), 2, 4, S("ab345de"));
+    test(S("abcde"), 2, 1, S("12345"), 4, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), 4, 1, S("ab5de"));
+    test(S("abcde"), 2, 1, S("12345"), 4, 2, S("ab5de"));
+    test(S("abcde"), 2, 1, S("12345"), 5, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), 5, 1, S("abde"));
+    test(S("abcde"), 2, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 1, S("ab1de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 9, S("ab123456789de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 0, 11, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 1, S("ab2de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 4, S("ab2345de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 8, S("ab23456789de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 9, S("ab234567890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 1, 10, S("ab234567890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 1, S("ab6de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 2, S("ab67de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 4, S("ab6789de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 5, S("ab67890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 5, 6, S("ab67890de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 9, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 9, 1, S("ab0de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 9, 2, S("ab0de"));
+    test(S("abcde"), 2, 1, S("1234567890"), 10, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 10, 1, S("abde"));
+    test(S("abcde"), 2, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 1, S("ab1de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 19, S("ab1234567890123456789de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 20, S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 0, 21, S("ab12345678901234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 1, S("ab2de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 9, S("ab234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 18, S("ab234567890123456789de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 19, S("ab2345678901234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 1, 20, S("ab2345678901234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 1, S("ab1de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 5, S("ab12345de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 9, S("ab123456789de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 10, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 10, 11, S("ab1234567890de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 1, S("ab0de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 19, 2, S("ab0de"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 20, 0, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 20, 1, S("abde"));
+    test(S("abcde"), 2, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, 2, S(""), 0, 0, S("abe"));
+    test(S("abcde"), 2, 2, S(""), 0, 1, S("abe"));
+    test(S("abcde"), 2, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 1, S("ab1e"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 2, S("ab12e"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 4, S("ab1234e"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, S("12345"), 0, 6, S("ab12345e"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 1, S("ab2e"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 2, S("ab23e"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 3, S("ab234e"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 4, S("ab2345e"));
+    test(S("abcde"), 2, 2, S("12345"), 1, 5, S("ab2345e"));
+    test(S("abcde"), 2, 2, S("12345"), 2, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 2, 1, S("ab3e"));
+    test(S("abcde"), 2, 2, S("12345"), 2, 2, S("ab34e"));
+    test(S("abcde"), 2, 2, S("12345"), 2, 3, S("ab345e"));
+    test(S("abcde"), 2, 2, S("12345"), 2, 4, S("ab345e"));
+    test(S("abcde"), 2, 2, S("12345"), 4, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 4, 1, S("ab5e"));
+    test(S("abcde"), 2, 2, S("12345"), 4, 2, S("ab5e"));
+    test(S("abcde"), 2, 2, S("12345"), 5, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 5, 1, S("abe"));
+    test(S("abcde"), 2, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 1, S("ab1e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 9, S("ab123456789e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 0, 11, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 1, S("ab2e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 4, S("ab2345e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 8, S("ab23456789e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 9, S("ab234567890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 1, 10, S("ab234567890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 1, S("ab6e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 2, S("ab67e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 4, S("ab6789e"));
+}
+
+void test13()
+{
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 5, S("ab67890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 5, 6, S("ab67890e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 9, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 9, 1, S("ab0e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 9, 2, S("ab0e"));
+    test(S("abcde"), 2, 2, S("1234567890"), 10, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 10, 1, S("abe"));
+    test(S("abcde"), 2, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 1, S("ab1e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 19, S("ab1234567890123456789e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 20, S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 0, 21, S("ab12345678901234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 1, S("ab2e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 9, S("ab234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 18, S("ab234567890123456789e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 19, S("ab2345678901234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 1, 20, S("ab2345678901234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 1, S("ab1e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 5, S("ab12345e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 9, S("ab123456789e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 10, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 10, 11, S("ab1234567890e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 1, S("ab0e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 19, 2, S("ab0e"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 20, 0, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 20, 1, S("abe"));
+    test(S("abcde"), 2, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, 3, S(""), 0, 0, S("ab"));
+    test(S("abcde"), 2, 3, S(""), 0, 1, S("ab"));
+    test(S("abcde"), 2, 3, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 2, S("ab12"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 4, S("ab1234"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 5, S("ab12345"));
+    test(S("abcde"), 2, 3, S("12345"), 0, 6, S("ab12345"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 2, S("ab23"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 3, S("ab234"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 4, S("ab2345"));
+    test(S("abcde"), 2, 3, S("12345"), 1, 5, S("ab2345"));
+    test(S("abcde"), 2, 3, S("12345"), 2, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 2, 1, S("ab3"));
+    test(S("abcde"), 2, 3, S("12345"), 2, 2, S("ab34"));
+    test(S("abcde"), 2, 3, S("12345"), 2, 3, S("ab345"));
+    test(S("abcde"), 2, 3, S("12345"), 2, 4, S("ab345"));
+    test(S("abcde"), 2, 3, S("12345"), 4, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 4, 1, S("ab5"));
+    test(S("abcde"), 2, 3, S("12345"), 4, 2, S("ab5"));
+    test(S("abcde"), 2, 3, S("12345"), 5, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 5, 1, S("ab"));
+    test(S("abcde"), 2, 3, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 5, S("ab12345"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 9, S("ab123456789"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 0, 11, S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 4, S("ab2345"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 8, S("ab23456789"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 9, S("ab234567890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 1, 10, S("ab234567890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 1, S("ab6"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 2, S("ab67"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 4, S("ab6789"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 5, S("ab67890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 5, 6, S("ab67890"));
+    test(S("abcde"), 2, 3, S("1234567890"), 9, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 9, 1, S("ab0"));
+    test(S("abcde"), 2, 3, S("1234567890"), 9, 2, S("ab0"));
+    test(S("abcde"), 2, 3, S("1234567890"), 10, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 10, 1, S("ab"));
+    test(S("abcde"), 2, 3, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 9, S("ab234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 18, S("ab234567890123456789"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 1, S("ab1"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 5, S("ab12345"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 9, S("ab123456789"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 10, 11, S("ab1234567890"));
+}
+
+void test14()
+{
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 1, S("ab0"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 19, 2, S("ab0"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 20, 0, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 20, 1, S("ab"));
+    test(S("abcde"), 2, 3, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 2, 4, S(""), 0, 0, S("ab"));
+    test(S("abcde"), 2, 4, S(""), 0, 1, S("ab"));
+    test(S("abcde"), 2, 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 2, S("ab12"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 4, S("ab1234"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 5, S("ab12345"));
+    test(S("abcde"), 2, 4, S("12345"), 0, 6, S("ab12345"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 2, S("ab23"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 3, S("ab234"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 4, S("ab2345"));
+    test(S("abcde"), 2, 4, S("12345"), 1, 5, S("ab2345"));
+    test(S("abcde"), 2, 4, S("12345"), 2, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 2, 1, S("ab3"));
+    test(S("abcde"), 2, 4, S("12345"), 2, 2, S("ab34"));
+    test(S("abcde"), 2, 4, S("12345"), 2, 3, S("ab345"));
+    test(S("abcde"), 2, 4, S("12345"), 2, 4, S("ab345"));
+    test(S("abcde"), 2, 4, S("12345"), 4, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 4, 1, S("ab5"));
+    test(S("abcde"), 2, 4, S("12345"), 4, 2, S("ab5"));
+    test(S("abcde"), 2, 4, S("12345"), 5, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 5, 1, S("ab"));
+    test(S("abcde"), 2, 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 5, S("ab12345"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 9, S("ab123456789"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 0, 11, S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 4, S("ab2345"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 8, S("ab23456789"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 9, S("ab234567890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 1, 10, S("ab234567890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 1, S("ab6"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 2, S("ab67"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 4, S("ab6789"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 5, S("ab67890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 5, 6, S("ab67890"));
+    test(S("abcde"), 2, 4, S("1234567890"), 9, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 9, 1, S("ab0"));
+    test(S("abcde"), 2, 4, S("1234567890"), 9, 2, S("ab0"));
+    test(S("abcde"), 2, 4, S("1234567890"), 10, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 10, 1, S("ab"));
+    test(S("abcde"), 2, 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 1, S("ab1"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 19, S("ab1234567890123456789"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 20, S("ab12345678901234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 0, 21, S("ab12345678901234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 1, S("ab2"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 9, S("ab234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 18, S("ab234567890123456789"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 19, S("ab2345678901234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 1, 20, S("ab2345678901234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 1, S("ab1"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 5, S("ab12345"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 9, S("ab123456789"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 10, S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 10, 11, S("ab1234567890"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 1, S("ab0"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 19, 2, S("ab0"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 20, 0, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 20, 1, S("ab"));
+    test(S("abcde"), 2, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 4, 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 4, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 2, S("abcd12e"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 4, S("abcd1234e"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("12345"), 0, 6, S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 2, S("abcd23e"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 3, S("abcd234e"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 4, S("abcd2345e"));
+    test(S("abcde"), 4, 0, S("12345"), 1, 5, S("abcd2345e"));
+    test(S("abcde"), 4, 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 2, 1, S("abcd3e"));
+    test(S("abcde"), 4, 0, S("12345"), 2, 2, S("abcd34e"));
+    test(S("abcde"), 4, 0, S("12345"), 2, 3, S("abcd345e"));
+    test(S("abcde"), 4, 0, S("12345"), 2, 4, S("abcd345e"));
+}
+
+void test15()
+{
+    test(S("abcde"), 4, 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 4, 1, S("abcd5e"));
+    test(S("abcde"), 4, 0, S("12345"), 4, 2, S("abcd5e"));
+    test(S("abcde"), 4, 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 9, S("abcd123456789e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 0, 11, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 4, S("abcd2345e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 8, S("abcd23456789e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 9, S("abcd234567890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 1, 10, S("abcd234567890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 1, S("abcd6e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 2, S("abcd67e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 4, S("abcd6789e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 5, S("abcd67890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 5, 6, S("abcd67890e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 9, 1, S("abcd0e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 9, 2, S("abcd0e"));
+    test(S("abcde"), 4, 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 4, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 1, S("abcd2e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 9, S("abcd234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 18, S("abcd234567890123456789e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 1, S("abcd1e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 5, S("abcd12345e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 9, S("abcd123456789e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 10, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 10, 11, S("abcd1234567890e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 1, S("abcd0e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 19, 2, S("abcd0e"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 4, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 4, 1, S(""), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S(""), 0, 1, S("abcd"));
+    test(S("abcde"), 4, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 2, S("abcd12"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 4, S("abcd1234"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, S("12345"), 0, 6, S("abcd12345"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 2, S("abcd23"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 3, S("abcd234"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 4, S("abcd2345"));
+    test(S("abcde"), 4, 1, S("12345"), 1, 5, S("abcd2345"));
+    test(S("abcde"), 4, 1, S("12345"), 2, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 2, 1, S("abcd3"));
+    test(S("abcde"), 4, 1, S("12345"), 2, 2, S("abcd34"));
+    test(S("abcde"), 4, 1, S("12345"), 2, 3, S("abcd345"));
+    test(S("abcde"), 4, 1, S("12345"), 2, 4, S("abcd345"));
+    test(S("abcde"), 4, 1, S("12345"), 4, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 4, 1, S("abcd5"));
+    test(S("abcde"), 4, 1, S("12345"), 4, 2, S("abcd5"));
+    test(S("abcde"), 4, 1, S("12345"), 5, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 5, 1, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 9, S("abcd123456789"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 0, 11, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 4, S("abcd2345"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 8, S("abcd23456789"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 9, S("abcd234567890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 1, 10, S("abcd234567890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 1, S("abcd6"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 2, S("abcd67"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 4, S("abcd6789"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 5, S("abcd67890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 5, 6, S("abcd67890"));
+    test(S("abcde"), 4, 1, S("1234567890"), 9, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 9, 1, S("abcd0"));
+}
+
+void test16()
+{
+    test(S("abcde"), 4, 1, S("1234567890"), 9, 2, S("abcd0"));
+    test(S("abcde"), 4, 1, S("1234567890"), 10, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 10, 1, S("abcd"));
+    test(S("abcde"), 4, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 9, S("abcd234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 1, S("abcd1"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 5, S("abcd12345"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 9, S("abcd123456789"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 10, 11, S("abcd1234567890"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 1, S("abcd0"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 19, 2, S("abcd0"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 20, 0, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 20, 1, S("abcd"));
+    test(S("abcde"), 4, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 4, 2, S(""), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S(""), 0, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 2, S("abcd12"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 4, S("abcd1234"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 5, S("abcd12345"));
+    test(S("abcde"), 4, 2, S("12345"), 0, 6, S("abcd12345"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 2, S("abcd23"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 3, S("abcd234"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 4, S("abcd2345"));
+    test(S("abcde"), 4, 2, S("12345"), 1, 5, S("abcd2345"));
+    test(S("abcde"), 4, 2, S("12345"), 2, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 2, 1, S("abcd3"));
+    test(S("abcde"), 4, 2, S("12345"), 2, 2, S("abcd34"));
+    test(S("abcde"), 4, 2, S("12345"), 2, 3, S("abcd345"));
+    test(S("abcde"), 4, 2, S("12345"), 2, 4, S("abcd345"));
+    test(S("abcde"), 4, 2, S("12345"), 4, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 4, 1, S("abcd5"));
+    test(S("abcde"), 4, 2, S("12345"), 4, 2, S("abcd5"));
+    test(S("abcde"), 4, 2, S("12345"), 5, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 5, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 5, S("abcd12345"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 9, S("abcd123456789"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 0, 11, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 4, S("abcd2345"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 8, S("abcd23456789"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 9, S("abcd234567890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 1, 10, S("abcd234567890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 1, S("abcd6"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 2, S("abcd67"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 4, S("abcd6789"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 5, S("abcd67890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 5, 6, S("abcd67890"));
+    test(S("abcde"), 4, 2, S("1234567890"), 9, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 9, 1, S("abcd0"));
+    test(S("abcde"), 4, 2, S("1234567890"), 9, 2, S("abcd0"));
+    test(S("abcde"), 4, 2, S("1234567890"), 10, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 10, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 1, S("abcd1"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 19, S("abcd1234567890123456789"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 20, S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 0, 21, S("abcd12345678901234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 1, S("abcd2"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 9, S("abcd234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 18, S("abcd234567890123456789"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 19, S("abcd2345678901234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 1, 20, S("abcd2345678901234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 1, S("abcd1"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 5, S("abcd12345"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 9, S("abcd123456789"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 10, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 10, 11, S("abcd1234567890"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 0, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 1, S("abcd0"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 19, 2, S("abcd0"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 20, 0, S("abcd"));
+}
+
+void test17()
+{
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 20, 1, S("abcd"));
+    test(S("abcde"), 4, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 5, 0, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 5, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 2, S("abcde12"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 4, S("abcde1234"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, S("12345"), 0, 6, S("abcde12345"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 2, S("abcde23"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 3, S("abcde234"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, 0, S("12345"), 1, 5, S("abcde2345"));
+    test(S("abcde"), 5, 0, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 2, 1, S("abcde3"));
+    test(S("abcde"), 5, 0, S("12345"), 2, 2, S("abcde34"));
+    test(S("abcde"), 5, 0, S("12345"), 2, 3, S("abcde345"));
+    test(S("abcde"), 5, 0, S("12345"), 2, 4, S("abcde345"));
+    test(S("abcde"), 5, 0, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 4, 1, S("abcde5"));
+    test(S("abcde"), 5, 0, S("12345"), 4, 2, S("abcde5"));
+    test(S("abcde"), 5, 0, S("12345"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 9, S("abcde123456789"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 0, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 8, S("abcde23456789"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 1, 10, S("abcde234567890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 1, S("abcde6"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 2, S("abcde67"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 4, S("abcde6789"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 5, S("abcde67890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 5, 6, S("abcde67890"));
+    test(S("abcde"), 5, 0, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 9, 1, S("abcde0"));
+    test(S("abcde"), 5, 0, S("1234567890"), 9, 2, S("abcde0"));
+    test(S("abcde"), 5, 0, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 5, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 1, S("abcde1"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 5, S("abcde12345"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 9, S("abcde123456789"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 1, S("abcde0"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 19, 2, S("abcde0"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 5, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 5, 1, S(""), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S(""), 0, 1, S("abcde"));
+    test(S("abcde"), 5, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 2, S("abcde12"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 4, S("abcde1234"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, 1, S("12345"), 0, 6, S("abcde12345"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 2, S("abcde23"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 3, S("abcde234"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, 1, S("12345"), 1, 5, S("abcde2345"));
+    test(S("abcde"), 5, 1, S("12345"), 2, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), 2, 1, S("abcde3"));
+    test(S("abcde"), 5, 1, S("12345"), 2, 2, S("abcde34"));
+    test(S("abcde"), 5, 1, S("12345"), 2, 3, S("abcde345"));
+    test(S("abcde"), 5, 1, S("12345"), 2, 4, S("abcde345"));
+    test(S("abcde"), 5, 1, S("12345"), 4, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), 4, 1, S("abcde5"));
+    test(S("abcde"), 5, 1, S("12345"), 4, 2, S("abcde5"));
+    test(S("abcde"), 5, 1, S("12345"), 5, 0, S("abcde"));
+}
+
+void test18()
+{
+    test(S("abcde"), 5, 1, S("12345"), 5, 1, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 5, S("abcde12345"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 9, S("abcde123456789"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 0, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 4, S("abcde2345"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 8, S("abcde23456789"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 1, 10, S("abcde234567890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 1, S("abcde6"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 2, S("abcde67"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 4, S("abcde6789"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 5, S("abcde67890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 5, 6, S("abcde67890"));
+    test(S("abcde"), 5, 1, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 9, 1, S("abcde0"));
+    test(S("abcde"), 5, 1, S("1234567890"), 9, 2, S("abcde0"));
+    test(S("abcde"), 5, 1, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcde"), 5, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 1, S("abcde1"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 1, S("abcde2"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 1, S("abcde1"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 5, S("abcde12345"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 9, S("abcde123456789"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 1, S("abcde0"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 19, 2, S("abcde0"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcde"), 5, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S(""), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S(""), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 0, 11, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 1, 10, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 5, 6, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("1234567890"), 11, 0, S("can't happen"));
+}
+
+void test19()
+{
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcde"), 6, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 2, S("12abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 4, S("1234abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 0, 6, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 1, S("2abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 2, S("23abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 3, S("234abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 4, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 1, 5, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 2, 1, S("3abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 2, 2, S("34abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 2, 3, S("345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 2, 4, S("345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 4, 1, S("5abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 4, 2, S("5abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 1, S("2abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 4, S("2345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 8, S("23456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 9, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 1, 10, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 1, S("6abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 2, S("67abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 4, S("6789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 5, S("67890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 5, 6, S("67890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 1, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 9, 2, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 1, S(""), 0, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S(""), 0, 1, S("bcdefghij"));
+}
+
+void test20()
+{
+    test(S("abcdefghij"), 0, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 2, S("12bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 4, S("1234bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 0, 6, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 1, S("2bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 2, S("23bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 3, S("234bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 4, S("2345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 1, 5, S("2345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 2, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 2, 1, S("3bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 2, 2, S("34bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 2, 3, S("345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 2, 4, S("345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 4, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 4, 1, S("5bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 4, 2, S("5bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 5, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 5, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 9, S("123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 1, S("2bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 4, S("2345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 8, S("23456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 9, S("234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 1, 10, S("234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 1, S("6bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 2, S("67bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 4, S("6789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 5, S("67890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 5, 6, S("67890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 1, S("0bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 9, 2, S("0bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 10, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 10, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 20, 0, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 20, 1, S("bcdefghij"));
+    test(S("abcdefghij"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 5, S(""), 0, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S(""), 0, 1, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 2, S("12fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 4, S("1234fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 0, 6, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 1, S("2fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 2, S("23fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 3, S("234fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 4, S("2345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 1, 5, S("2345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 2, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 2, 1, S("3fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 2, 2, S("34fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 2, 3, S("345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 2, 4, S("345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 4, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 4, 1, S("5fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 4, 2, S("5fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 5, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 5, 1, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 1, S("1fghij"));
+}
+
+void test21()
+{
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 9, S("123456789fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 0, 11, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 1, S("2fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 4, S("2345fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 8, S("23456789fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 9, S("234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 1, 10, S("234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 1, S("6fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 2, S("67fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 4, S("6789fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 5, S("67890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 5, 6, S("67890fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 1, S("0fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 9, 2, S("0fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 10, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 10, 1, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 19, S("1234567890123456789fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 20, S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 0, 21, S("12345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 1, S("2fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 9, S("234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 18, S("234567890123456789fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 19, S("2345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 1, 20, S("2345678901234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 1, S("1fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 5, S("12345fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 9, S("123456789fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 10, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 10, 11, S("1234567890fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 1, S("0fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 19, 2, S("0fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 20, 0, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 20, 1, S("fghij"));
+    test(S("abcdefghij"), 0, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 9, S(""), 0, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S(""), 0, 1, S("j"));
+    test(S("abcdefghij"), 0, 9, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 2, S("12j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 4, S("1234j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 0, 6, S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 1, S("2j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 2, S("23j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 3, S("234j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 4, S("2345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 1, 5, S("2345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 2, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 2, 1, S("3j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 2, 2, S("34j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 2, 3, S("345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 2, 4, S("345j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 4, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 4, 1, S("5j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 4, 2, S("5j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 5, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 5, 1, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 9, S("123456789j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 0, 11, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 1, S("2j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 4, S("2345j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 8, S("23456789j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 9, S("234567890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 1, 10, S("234567890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 1, S("6j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 2, S("67j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 4, S("6789j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 5, S("67890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 5, 6, S("67890j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 1, S("0j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 9, 2, S("0j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 10, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 10, 1, S("j"));
+    test(S("abcdefghij"), 0, 9, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 19, S("1234567890123456789j"));
+}
+
+void test22()
+{
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 20, S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 0, 21, S("12345678901234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 1, S("2j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 9, S("234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 18, S("234567890123456789j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 19, S("2345678901234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 1, 20, S("2345678901234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 1, S("1j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 5, S("12345j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 9, S("123456789j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 10, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 10, 11, S("1234567890j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 1, S("0j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 19, 2, S("0j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 20, 0, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 20, 1, S("j"));
+    test(S("abcdefghij"), 0, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 10, S(""), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S(""), 0, 1, S(""));
+    test(S("abcdefghij"), 0, 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 2, S("12"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 4, S("1234"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 0, 6, S("12345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 2, S("23"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 3, S("234"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 4, S("2345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 1, 5, S("2345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 2, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 2, 1, S("3"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 2, 2, S("34"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 2, 3, S("345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 2, 4, S("345"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 4, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 4, 1, S("5"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 4, 2, S("5"));
+    test(S("abcdefghij"), 0, 10, S("12345"), 5, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 5, 1, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 9, S("123456789"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 1, S("6"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 2, S("67"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 1, S("0"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 9, 2, S("0"));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 10, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 10, 1, S(""));
+    test(S("abcdefghij"), 0, 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcdefghij"), 0, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 11, S(""), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S(""), 0, 1, S(""));
+    test(S("abcdefghij"), 0, 11, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 2, S("12"));
+}
+
+void test23()
+{
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 4, S("1234"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 5, S("12345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 0, 6, S("12345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 2, S("23"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 3, S("234"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 4, S("2345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 1, 5, S("2345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 2, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 2, 1, S("3"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 2, 2, S("34"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 2, 3, S("345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 2, 4, S("345"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 4, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 4, 1, S("5"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 4, 2, S("5"));
+    test(S("abcdefghij"), 0, 11, S("12345"), 5, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 5, 1, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 9, S("123456789"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 1, S("6"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 2, S("67"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 1, S("0"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 9, 2, S("0"));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 10, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 10, 1, S(""));
+    test(S("abcdefghij"), 0, 11, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcdefghij"), 0, 11, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 2, S("a12bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 4, S("a1234bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 0, 6, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 1, S("a2bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 2, S("a23bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 3, S("a234bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 4, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 1, 5, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 2, 1, S("a3bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 2, 2, S("a34bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 2, 3, S("a345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 2, 4, S("a345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 4, 1, S("a5bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 4, 2, S("a5bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcdefghij"));
+}
+
+void test24()
+{
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 1, S("a2bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 4, S("a2345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 1, S("a6bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 2, S("a67bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 4, S("a6789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 5, S("a67890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 5, 6, S("a67890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 1, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 9, 2, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 1, S(""), 0, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S(""), 0, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 2, S("a12cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 4, S("a1234cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 0, 6, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 1, S("a2cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 2, S("a23cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 3, S("a234cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 4, S("a2345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 1, 5, S("a2345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 2, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 2, 1, S("a3cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 2, 2, S("a34cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 2, 3, S("a345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 2, 4, S("a345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 4, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 4, 1, S("a5cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 4, 2, S("a5cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 5, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 5, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 9, S("a123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 1, S("a2cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 4, S("a2345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 8, S("a23456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 9, S("a234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 1, 10, S("a234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 1, S("a6cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 2, S("a67cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 4, S("a6789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 5, S("a67890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 5, 6, S("a67890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 1, S("a0cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 9, 2, S("a0cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 10, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 10, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cdefghij"));
+}
+
+void test25()
+{
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 20, 0, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 20, 1, S("acdefghij"));
+    test(S("abcdefghij"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 4, S(""), 0, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S(""), 0, 1, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 2, S("a12fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 4, S("a1234fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 0, 6, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 1, S("a2fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 2, S("a23fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 3, S("a234fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 4, S("a2345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 1, 5, S("a2345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 2, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 2, 1, S("a3fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 2, 2, S("a34fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 2, 3, S("a345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 2, 4, S("a345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 4, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 4, 1, S("a5fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 4, 2, S("a5fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 5, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 5, 1, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 9, S("a123456789fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 0, 11, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 1, S("a2fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 4, S("a2345fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 8, S("a23456789fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 9, S("a234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 1, 10, S("a234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 1, S("a6fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 2, S("a67fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 4, S("a6789fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 5, S("a67890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 5, 6, S("a67890fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 1, S("a0fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 9, 2, S("a0fghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 10, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 10, 1, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 19, S("a1234567890123456789fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 20, S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 0, 21, S("a12345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 1, S("a2fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 9, S("a234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 18, S("a234567890123456789fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 19, S("a2345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 1, 20, S("a2345678901234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 1, S("a1fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 5, S("a12345fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 9, S("a123456789fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 10, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 10, 11, S("a1234567890fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 1, S("a0fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 19, 2, S("a0fghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 20, 0, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 20, 1, S("afghij"));
+    test(S("abcdefghij"), 1, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 8, S(""), 0, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S(""), 0, 1, S("aj"));
+    test(S("abcdefghij"), 1, 8, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 2, S("a12j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 4, S("a1234j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 0, 6, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 0, S("aj"));
+}
+
+void test26()
+{
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 1, S("a2j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 2, S("a23j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 3, S("a234j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 4, S("a2345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 1, 5, S("a2345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 2, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 2, 1, S("a3j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 2, 2, S("a34j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 2, 3, S("a345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 2, 4, S("a345j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 4, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 4, 1, S("a5j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 4, 2, S("a5j"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 5, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 5, 1, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 9, S("a123456789j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 0, 11, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 1, S("a2j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 4, S("a2345j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 8, S("a23456789j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 9, S("a234567890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 1, 10, S("a234567890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 1, S("a6j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 2, S("a67j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 4, S("a6789j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 5, S("a67890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 5, 6, S("a67890j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 1, S("a0j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 9, 2, S("a0j"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 10, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 10, 1, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 19, S("a1234567890123456789j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 20, S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 0, 21, S("a12345678901234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 1, S("a2j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 9, S("a234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 18, S("a234567890123456789j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 19, S("a2345678901234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 1, 20, S("a2345678901234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 1, S("a1j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 5, S("a12345j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 9, S("a123456789j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 10, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 10, 11, S("a1234567890j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 1, S("a0j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 19, 2, S("a0j"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 20, 0, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 20, 1, S("aj"));
+    test(S("abcdefghij"), 1, 8, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 9, S(""), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S(""), 0, 1, S("a"));
+    test(S("abcdefghij"), 1, 9, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 2, S("a12"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 4, S("a1234"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 0, 6, S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 2, S("a23"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 3, S("a234"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 4, S("a2345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 1, 5, S("a2345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 2, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 2, 1, S("a3"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 2, 2, S("a34"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 2, 3, S("a345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 2, 4, S("a345"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 4, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 4, 1, S("a5"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 4, 2, S("a5"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 5, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 5, 1, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 8, S("a23456789"));
+}
+
+void test27()
+{
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 1, 10, S("a234567890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 10, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 10, 1, S("a"));
+    test(S("abcdefghij"), 1, 9, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 1, S("a1"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcdefghij"), 1, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 10, S(""), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S(""), 0, 1, S("a"));
+    test(S("abcdefghij"), 1, 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 2, S("a12"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 4, S("a1234"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 0, 6, S("a12345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 2, S("a23"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 3, S("a234"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 4, S("a2345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 1, 5, S("a2345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 2, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 2, 1, S("a3"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 2, 2, S("a34"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 2, 3, S("a345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 2, 4, S("a345"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 4, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 4, 1, S("a5"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 4, 2, S("a5"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 5, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 5, 1, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 8, S("a23456789"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 1, 10, S("a234567890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 10, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 10, 1, S("a"));
+    test(S("abcdefghij"), 1, 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+}
+
+void test28()
+{
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 1, S("a1"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcdefghij"), 1, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 2, S("abcde12fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 4, S("abcde1234fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 0, 6, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 2, S("abcde23fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 3, S("abcde234fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 4, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 1, 5, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 2, 1, S("abcde3fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 2, 2, S("abcde34fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 2, 3, S("abcde345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 2, 4, S("abcde345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 4, 1, S("abcde5fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 4, 2, S("abcde5fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 0, 11, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 4, S("abcde2345fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 8, S("abcde23456789fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 9, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 1, 10, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 1, S("abcde6fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 2, S("abcde67fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 4, S("abcde6789fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 5, S("abcde67890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 5, 6, S("abcde67890fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 1, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 9, 2, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 1, S("abcde2fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 9, S("abcde234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 18, S("abcde234567890123456789fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 1, S("abcde1fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 5, S("abcde12345fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 9, S("abcde123456789fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 10, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 10, 11, S("abcde1234567890fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 1, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 19, 2, S("abcde0fghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 5, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 1, S(""), 0, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S(""), 0, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 2, S("abcde12ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 4, S("abcde1234ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 0, 6, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 1, S("abcde2ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 2, S("abcde23ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 3, S("abcde234ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 4, S("abcde2345ghij"));
+}
+
+void test29()
+{
+    test(S("abcdefghij"), 5, 1, S("12345"), 1, 5, S("abcde2345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 2, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 2, 1, S("abcde3ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 2, 2, S("abcde34ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 2, 3, S("abcde345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 2, 4, S("abcde345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 4, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 4, 1, S("abcde5ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 4, 2, S("abcde5ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 5, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 5, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 9, S("abcde123456789ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 0, 11, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 1, S("abcde2ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 4, S("abcde2345ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 8, S("abcde23456789ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 9, S("abcde234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 1, 10, S("abcde234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 1, S("abcde6ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 2, S("abcde67ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 4, S("abcde6789ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 5, S("abcde67890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 5, 6, S("abcde67890ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 1, S("abcde0ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 9, 2, S("abcde0ghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 10, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 10, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 1, S("abcde2ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 9, S("abcde234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 18, S("abcde234567890123456789ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 1, S("abcde1ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 5, S("abcde12345ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 9, S("abcde123456789ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 10, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 10, 11, S("abcde1234567890ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 1, S("abcde0ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 19, 2, S("abcde0ghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 20, 0, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 20, 1, S("abcdeghij"));
+    test(S("abcdefghij"), 5, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 2, S(""), 0, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S(""), 0, 1, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 2, S("abcde12hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 4, S("abcde1234hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 0, 6, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 1, S("abcde2hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 2, S("abcde23hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 3, S("abcde234hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 4, S("abcde2345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 1, 5, S("abcde2345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 2, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 2, 1, S("abcde3hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 2, 2, S("abcde34hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 2, 3, S("abcde345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 2, 4, S("abcde345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 4, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 4, 1, S("abcde5hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 4, 2, S("abcde5hij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 5, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 5, 1, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 9, S("abcde123456789hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 0, 11, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 1, S("abcde2hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 4, S("abcde2345hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 8, S("abcde23456789hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 9, S("abcde234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 1, 10, S("abcde234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 1, S("abcde6hij"));
+}
+
+void test30()
+{
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 2, S("abcde67hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 4, S("abcde6789hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 5, S("abcde67890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 5, 6, S("abcde67890hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 1, S("abcde0hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 9, 2, S("abcde0hij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 10, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 10, 1, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 1, S("abcde2hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 9, S("abcde234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 18, S("abcde234567890123456789hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 1, S("abcde1hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 5, S("abcde12345hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 9, S("abcde123456789hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 10, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 10, 11, S("abcde1234567890hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 1, S("abcde0hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 19, 2, S("abcde0hij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 20, 0, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 20, 1, S("abcdehij"));
+    test(S("abcdefghij"), 5, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 4, S(""), 0, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S(""), 0, 1, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 2, S("abcde12j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 4, S("abcde1234j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 0, 6, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 1, S("abcde2j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 2, S("abcde23j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 3, S("abcde234j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 4, S("abcde2345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 1, 5, S("abcde2345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 2, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 2, 1, S("abcde3j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 2, 2, S("abcde34j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 2, 3, S("abcde345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 2, 4, S("abcde345j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 4, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 4, 1, S("abcde5j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 4, 2, S("abcde5j"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 5, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 5, 1, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 9, S("abcde123456789j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 0, 11, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 1, S("abcde2j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 4, S("abcde2345j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 8, S("abcde23456789j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 9, S("abcde234567890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 1, 10, S("abcde234567890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 1, S("abcde6j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 2, S("abcde67j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 4, S("abcde6789j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 5, S("abcde67890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 5, 6, S("abcde67890j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 1, S("abcde0j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 9, 2, S("abcde0j"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 10, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 10, 1, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 1, S("abcde2j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 9, S("abcde234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 18, S("abcde234567890123456789j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 1, S("abcde1j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 5, S("abcde12345j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 9, S("abcde123456789j"));
+}
+
+void test31()
+{
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 10, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 10, 11, S("abcde1234567890j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 1, S("abcde0j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 19, 2, S("abcde0j"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 20, 0, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 20, 1, S("abcdej"));
+    test(S("abcdefghij"), 5, 4, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 5, S(""), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S(""), 0, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 2, S("abcde12"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 0, 6, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 2, S("abcde23"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 3, S("abcde234"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 4, S("abcde2345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 1, 5, S("abcde2345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 2, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 2, 1, S("abcde3"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 2, 2, S("abcde34"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 2, 3, S("abcde345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 2, 4, S("abcde345"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 4, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 4, 1, S("abcde5"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 4, 2, S("abcde5"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 5, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 0, 11, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 4, S("abcde2345"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 8, S("abcde23456789"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 1, 10, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 1, S("abcde6"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 2, S("abcde67"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 4, S("abcde6789"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 5, S("abcde67890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 5, 6, S("abcde67890"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 1, S("abcde0"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 9, 2, S("abcde0"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 1, S("abcde0"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 19, 2, S("abcde0"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 6, S(""), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S(""), 0, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 2, S("abcde12"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 4, S("abcde1234"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 0, 6, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 2, S("abcde23"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 3, S("abcde234"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 4, S("abcde2345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 1, 5, S("abcde2345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 2, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 2, 1, S("abcde3"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 2, 2, S("abcde34"));
+}
+
+void test32()
+{
+    test(S("abcdefghij"), 5, 6, S("12345"), 2, 3, S("abcde345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 2, 4, S("abcde345"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 4, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 4, 1, S("abcde5"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 4, 2, S("abcde5"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 5, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 0, 11, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 4, S("abcde2345"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 8, S("abcde23456789"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 1, 10, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 1, S("abcde6"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 2, S("abcde67"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 4, S("abcde6789"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 5, S("abcde67890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 5, 6, S("abcde67890"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 1, S("abcde0"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 9, 2, S("abcde0"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 10, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 10, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 19, S("abcde1234567890123456789"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 20, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 0, 21, S("abcde12345678901234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 1, S("abcde2"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 9, S("abcde234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 18, S("abcde234567890123456789"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 19, S("abcde2345678901234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 1, 20, S("abcde2345678901234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 1, S("abcde1"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 5, S("abcde12345"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 9, S("abcde123456789"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 10, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 10, 11, S("abcde1234567890"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 1, S("abcde0"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 19, 2, S("abcde0"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 20, 0, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 20, 1, S("abcde"));
+    test(S("abcdefghij"), 5, 6, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 2, S("abcdefghi12j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 4, S("abcdefghi1234j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 0, 6, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 2, S("abcdefghi23j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 3, S("abcdefghi234j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 4, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 1, 5, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 2, 1, S("abcdefghi3j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 2, 2, S("abcdefghi34j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 2, 3, S("abcdefghi345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 2, 4, S("abcdefghi345j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 4, 1, S("abcdefghi5j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 4, 2, S("abcdefghi5j"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 0, 11, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 4, S("abcdefghi2345j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 8, S("abcdefghi23456789j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 9, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 1, 10, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 1, S("abcdefghi6j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 2, S("abcdefghi67j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 4, S("abcdefghi6789j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 5, S("abcdefghi67890j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 5, 6, S("abcdefghi67890j"));
+}
+
+void test33()
+{
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 1, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 9, 2, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 1, S("abcdefghi2j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 9, S("abcdefghi234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 1, S("abcdefghi1j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 5, S("abcdefghi12345j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 9, S("abcdefghi123456789j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 1, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 19, 2, S("abcdefghi0j"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 9, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 1, S(""), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S(""), 0, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 0, 6, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 2, S("abcdefghi23"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 3, S("abcdefghi234"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 4, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 1, 5, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 2, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 2, 1, S("abcdefghi3"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 2, 2, S("abcdefghi34"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 2, 3, S("abcdefghi345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 2, 4, S("abcdefghi345"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 4, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 4, 1, S("abcdefghi5"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 4, 2, S("abcdefghi5"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 5, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 5, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 0, 11, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 4, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 8, S("abcdefghi23456789"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 9, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 1, 10, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 1, S("abcdefghi6"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 2, S("abcdefghi67"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 4, S("abcdefghi6789"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 5, S("abcdefghi67890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 5, 6, S("abcdefghi67890"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 1, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 9, 2, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 10, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 10, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 1, S("abcdefghi0"));
+}
+
+void test34()
+{
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, 2, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 2, S(""), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S(""), 0, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 2, S("abcdefghi12"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 4, S("abcdefghi1234"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 0, 6, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 2, S("abcdefghi23"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 3, S("abcdefghi234"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 4, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 1, 5, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 2, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 2, 1, S("abcdefghi3"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 2, 2, S("abcdefghi34"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 2, 3, S("abcdefghi345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 2, 4, S("abcdefghi345"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 4, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 4, 1, S("abcdefghi5"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 4, 2, S("abcdefghi5"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 5, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 5, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 0, 11, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 4, S("abcdefghi2345"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 8, S("abcdefghi23456789"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 9, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 1, 10, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 1, S("abcdefghi6"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 2, S("abcdefghi67"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 4, S("abcdefghi6789"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 5, S("abcdefghi67890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 5, 6, S("abcdefghi67890"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 1, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 9, 2, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 10, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 10, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 19, S("abcdefghi1234567890123456789"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 20, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 0, 21, S("abcdefghi12345678901234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 1, S("abcdefghi2"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 9, S("abcdefghi234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 18, S("abcdefghi234567890123456789"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 19, S("abcdefghi2345678901234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 1, 20, S("abcdefghi2345678901234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 1, S("abcdefghi1"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 5, S("abcdefghi12345"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 9, S("abcdefghi123456789"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 10, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 10, 11, S("abcdefghi1234567890"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 1, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 19, 2, S("abcdefghi0"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 20, 0, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 20, 1, S("abcdefghi"));
+    test(S("abcdefghij"), 9, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 0, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 0, 6, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 2, S("abcdefghij23"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 3, S("abcdefghij234"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 1, 5, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 2, 1, S("abcdefghij3"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 2, 2, S("abcdefghij34"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 2, 3, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 2, 4, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 4, 1, S("abcdefghij5"));
+}
+
+void test35()
+{
+    test(S("abcdefghij"), 10, 0, S("12345"), 4, 2, S("abcdefghij5"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 8, S("abcdefghij23456789"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 1, 10, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 1, S("abcdefghij6"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 2, S("abcdefghij67"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 4, S("abcdefghij6789"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 5, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 5, 6, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 9, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 1, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 2, S("abcdefghij12"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 4, S("abcdefghij1234"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 0, 6, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 2, S("abcdefghij23"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 3, S("abcdefghij234"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 1, 5, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 2, 1, S("abcdefghij3"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 2, 2, S("abcdefghij34"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 2, 3, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 2, 4, S("abcdefghij345"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 4, 1, S("abcdefghij5"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 4, 2, S("abcdefghij5"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 8, S("abcdefghij23456789"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 1, 10, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 1, S("abcdefghij6"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 2, S("abcdefghij67"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 4, S("abcdefghij6789"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 5, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 5, 6, S("abcdefghij67890"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 9, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 10, 0, S("abcdefghij"));
+}
+
+void test36()
+{
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghij"), 10, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S(""), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S(""), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 0, 11, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 1, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 5, 6, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcdefghij"), 11, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+}
+
+void test37()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 2, S("12abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 4, S("1234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 0, 6, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 2, S("23abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 3, S("234abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 4, S("2345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 1, 5, S("2345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 1, S("3abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 2, S("34abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 3, S("345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 2, 4, S("345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 1, S("5abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 4, 2, S("5abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 0, 11, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 4, S("2345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 8, S("23456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 1, 10, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 1, S("6abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 2, S("67abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 4, S("6789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 5, S("67890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 5, 6, S("67890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 1, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 9, 2, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 19, S("1234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 20, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 0, 21, S("12345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 1, S("2abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 9, S("234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 18, S("234567890123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 19, S("2345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 1, 20, S("2345678901234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 1, S("1abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 5, S("12345abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 9, S("123456789abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 10, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 10, 11, S("1234567890abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 1, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 19, 2, S("0abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 2, S("12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 4, S("1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 0, 6, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 1, S("2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 2, S("23bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 3, S("234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 4, S("2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 1, 5, S("2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 1, S("3bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 2, S("34bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 3, S("345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 2, 4, S("345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 1, S("5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 4, 2, S("5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 5, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 5, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345"), 6, 0, S("can't happen"));
+}
+
+void test38()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 9, S("123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 0, 11, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 4, S("2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 8, S("23456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 1, 10, S("234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 1, S("6bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 2, S("67bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 4, S("6789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 5, S("67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 5, 6, S("67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 1, S("0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 9, 2, S("0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 10, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 10, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 19, S("1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 20, S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 0, 21, S("12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 1, S("2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 9, S("234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 18, S("234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 19, S("2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 1, 20, S("2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 1, S("1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 5, S("12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 9, S("123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 10, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 10, 11, S("1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 1, S("0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 19, 2, S("0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 20, 0, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 20, 1, S("bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 1, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 2, S("12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 4, S("1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 0, 6, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 1, S("2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 2, S("23klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 3, S("234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 4, S("2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 1, 5, S("2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 1, S("3klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 2, S("34klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 3, S("345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 2, 4, S("345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 1, S("5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 4, 2, S("5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 5, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 5, 1, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 9, S("123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 0, 11, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 1, S("2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 4, S("2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 8, S("23456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 9, S("234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 1, 10, S("234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 1, S("6klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 2, S("67klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 4, S("6789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 5, S("67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 5, 6, S("67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 1, S("0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 9, 2, S("0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 10, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 10, 1, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 1, S("1klmnopqrst"));
+}
+
+void test39()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 19, S("1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 20, S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 0, 21, S("12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 1, S("2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 9, S("234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 18, S("234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 19, S("2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 1, 20, S("2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 1, S("1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 5, S("12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 9, S("123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 10, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 10, 11, S("1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 1, S("0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 19, 2, S("0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 20, 0, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 20, 1, S("klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 1, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 2, S("12t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 4, S("1234t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 0, 6, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 1, S("2t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 2, S("23t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 3, S("234t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 4, S("2345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 1, 5, S("2345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 1, S("3t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 2, S("34t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 3, S("345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 2, 4, S("345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 1, S("5t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 4, 2, S("5t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 5, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 5, 1, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 9, S("123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 0, 11, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 1, S("2t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 4, S("2345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 8, S("23456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 9, S("234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 1, 10, S("234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 1, S("6t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 2, S("67t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 4, S("6789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 5, S("67890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 5, 6, S("67890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 1, S("0t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 9, 2, S("0t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 10, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 10, 1, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 19, S("1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 20, S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 0, 21, S("12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 1, S("2t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 9, S("234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 18, S("234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 19, S("2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 1, 20, S("2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 1, S("1t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 5, S("12345t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 9, S("123456789t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 10, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 10, 11, S("1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 1, S("0t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 19, 2, S("0t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 20, 0, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 20, 1, S("t"));
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 0, S(""));
+}
+
+void test40()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 0, 6, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 2, S("23"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 3, S("234"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 4, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 1, 5, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 1, S("3"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 2, S("34"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 3, S("345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 2, 4, S("345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 1, S("5"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 4, 2, S("5"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 5, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 5, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 1, S("6"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 2, S("67"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 1, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 9, 2, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 10, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 10, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 2, S("12"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 4, S("1234"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 0, 6, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 2, S("23"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 3, S("234"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 4, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 1, 5, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 1, S("3"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 2, S("34"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 3, S("345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 2, 4, S("345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 1, S("5"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 4, 2, S("5"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 5, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 5, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 9, S("123456789"));
+}
+
+void test41()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 0, 11, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 4, S("2345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 8, S("23456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 1, 10, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 1, S("6"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 2, S("67"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 4, S("6789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 5, S("67890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 5, 6, S("67890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 1, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 9, 2, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 10, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 10, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 19, S("1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 20, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 0, 21, S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 1, S("2"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 9, S("234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 18, S("234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 19, S("2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 1, 20, S("2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 1, S("1"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 5, S("12345"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 9, S("123456789"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 10, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 10, 11, S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 1, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 19, 2, S("0"));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 20, 0, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 20, 1, S(""));
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 2, S("a12bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 4, S("a1234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 0, 6, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 2, S("a23bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 3, S("a234bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 4, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 1, 5, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 1, S("a3bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 2, S("a34bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 3, S("a345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 2, 4, S("a345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 1, S("a5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 4, 2, S("a5bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 0, 11, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 4, S("a2345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 8, S("a23456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 1, 10, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 1, S("a6bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 2, S("a67bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 4, S("a6789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 5, S("a67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 5, 6, S("a67890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 1, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 9, 2, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 19, S("a1234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 20, S("a12345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 0, 21, S("a12345678901234567890bcdefghijklmnopqrst"));
+}
+
+void test42()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 1, S("a2bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 9, S("a234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 18, S("a234567890123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 19, S("a2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 1, 20, S("a2345678901234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 1, S("a1bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 5, S("a12345bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 9, S("a123456789bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 10, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 10, 11, S("a1234567890bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 1, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 19, 2, S("a0bcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 2, S("a12cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 4, S("a1234cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 0, 6, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 1, S("a2cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 2, S("a23cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 3, S("a234cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 4, S("a2345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 1, 5, S("a2345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 1, S("a3cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 2, S("a34cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 3, S("a345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 2, 4, S("a345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 1, S("a5cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 4, 2, S("a5cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 5, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 5, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 9, S("a123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 0, 11, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 4, S("a2345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 8, S("a23456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 1, 10, S("a234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 1, S("a6cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 2, S("a67cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 4, S("a6789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 5, S("a67890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 5, 6, S("a67890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 1, S("a0cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 9, 2, S("a0cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 10, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 10, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 19, S("a1234567890123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 20, S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 0, 21, S("a12345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 1, S("a2cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 9, S("a234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 18, S("a234567890123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 19, S("a2345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 1, 20, S("a2345678901234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 1, S("a1cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 5, S("a12345cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 9, S("a123456789cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 10, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 10, 11, S("a1234567890cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 1, S("a0cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 19, 2, S("a0cdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 20, 0, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 20, 1, S("acdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 1, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 2, S("a12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 4, S("a1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 5, S("a12345klmnopqrst"));
+}
+
+void test43()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 0, 6, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 1, S("a2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 2, S("a23klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 3, S("a234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 4, S("a2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 1, 5, S("a2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 1, S("a3klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 2, S("a34klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 3, S("a345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 2, 4, S("a345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 1, S("a5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 4, 2, S("a5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 5, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 5, 1, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 9, S("a123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 0, 11, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 1, S("a2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 4, S("a2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 8, S("a23456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 9, S("a234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 1, 10, S("a234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 1, S("a6klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 2, S("a67klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 4, S("a6789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 5, S("a67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 5, 6, S("a67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 1, S("a0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 9, 2, S("a0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 10, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 10, 1, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 19, S("a1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 20, S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 0, 21, S("a12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 1, S("a2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 9, S("a234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 18, S("a234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 19, S("a2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 1, 20, S("a2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 1, S("a1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 5, S("a12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 9, S("a123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 10, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 10, 11, S("a1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 1, S("a0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 19, 2, S("a0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 20, 0, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 20, 1, S("aklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 1, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 2, S("a12t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 4, S("a1234t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 0, 6, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 1, S("a2t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 2, S("a23t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 3, S("a234t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 4, S("a2345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 1, 5, S("a2345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 1, S("a3t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 2, S("a34t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 3, S("a345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 2, 4, S("a345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 1, S("a5t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 4, 2, S("a5t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 5, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 5, 1, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 9, S("a123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 0, 11, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 1, S("a2t"));
+}
+
+void test44()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 4, S("a2345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 8, S("a23456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 9, S("a234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 1, 10, S("a234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 1, S("a6t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 2, S("a67t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 4, S("a6789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 5, S("a67890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 5, 6, S("a67890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 1, S("a0t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 9, 2, S("a0t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 10, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 10, 1, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 19, S("a1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 20, S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 0, 21, S("a12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 1, S("a2t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 9, S("a234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 18, S("a234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 19, S("a2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 1, 20, S("a2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 1, S("a1t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 5, S("a12345t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 9, S("a123456789t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 10, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 10, 11, S("a1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 1, S("a0t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 19, 2, S("a0t"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 20, 0, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 20, 1, S("at"));
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 0, 6, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 2, S("a23"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 3, S("a234"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 4, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 1, 5, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 1, S("a3"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 2, S("a34"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 3, S("a345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 2, 4, S("a345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 1, S("a5"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 4, 2, S("a5"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 5, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 5, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 8, S("a23456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 1, 10, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 10, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 10, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+}
+
+void test45()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 2, S("a12"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 4, S("a1234"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 0, 6, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 2, S("a23"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 3, S("a234"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 4, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 1, 5, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 1, S("a3"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 2, S("a34"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 3, S("a345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 2, 4, S("a345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 1, S("a5"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 4, 2, S("a5"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 5, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 5, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 0, 11, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 4, S("a2345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 8, S("a23456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 1, 10, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 1, S("a6"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 2, S("a67"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 4, S("a6789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 5, S("a67890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 5, 6, S("a67890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 1, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 9, 2, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 10, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 10, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 19, S("a1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 20, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 0, 21, S("a12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 1, S("a2"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 9, S("a234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 18, S("a234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 19, S("a2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 1, 20, S("a2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 1, S("a1"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 5, S("a12345"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 9, S("a123456789"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 10, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 10, 11, S("a1234567890"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 1, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 19, 2, S("a0"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 20, 0, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 20, 1, S("a"));
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 2, S("abcdefghij12klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 4, S("abcdefghij1234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 0, 6, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 2, S("abcdefghij23klmnopqrst"));
+}
+
+void test46()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 3, S("abcdefghij234klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 4, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 1, 5, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 1, S("abcdefghij3klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 2, S("abcdefghij34klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 3, S("abcdefghij345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 2, 4, S("abcdefghij345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 1, S("abcdefghij5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 4, 2, S("abcdefghij5klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 0, 11, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 4, S("abcdefghij2345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 8, S("abcdefghij23456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 1, 10, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 1, S("abcdefghij6klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 2, S("abcdefghij67klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 4, S("abcdefghij6789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 5, S("abcdefghij67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 5, 6, S("abcdefghij67890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 1, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 9, 2, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 1, S("abcdefghij2klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 9, S("abcdefghij234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 1, S("abcdefghij1klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 5, S("abcdefghij12345klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 9, S("abcdefghij123456789klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 1, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 19, 2, S("abcdefghij0klmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 2, S("abcdefghij12lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 4, S("abcdefghij1234lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 0, 6, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 1, S("abcdefghij2lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 2, S("abcdefghij23lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 3, S("abcdefghij234lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 4, S("abcdefghij2345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 1, 5, S("abcdefghij2345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 1, S("abcdefghij3lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 2, S("abcdefghij34lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 3, S("abcdefghij345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 2, 4, S("abcdefghij345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 1, S("abcdefghij5lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 4, 2, S("abcdefghij5lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 5, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 5, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 9, S("abcdefghij123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 0, 11, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 4, S("abcdefghij2345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 8, S("abcdefghij23456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 1, 10, S("abcdefghij234567890lmnopqrst"));
+}
+
+void test47()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 1, S("abcdefghij6lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 2, S("abcdefghij67lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 4, S("abcdefghij6789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 5, S("abcdefghij67890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 5, 6, S("abcdefghij67890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 1, S("abcdefghij0lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 9, 2, S("abcdefghij0lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 10, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 10, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 1, S("abcdefghij2lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 9, S("abcdefghij234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 1, S("abcdefghij1lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 5, S("abcdefghij12345lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 9, S("abcdefghij123456789lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 1, S("abcdefghij0lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 19, 2, S("abcdefghij0lmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 20, 0, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 20, 1, S("abcdefghijlmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 1, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 2, S("abcdefghij12pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 4, S("abcdefghij1234pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 0, 6, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 1, S("abcdefghij2pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 2, S("abcdefghij23pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 3, S("abcdefghij234pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 4, S("abcdefghij2345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 1, 5, S("abcdefghij2345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 1, S("abcdefghij3pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 2, S("abcdefghij34pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 3, S("abcdefghij345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 2, 4, S("abcdefghij345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 1, S("abcdefghij5pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 4, 2, S("abcdefghij5pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 5, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 5, 1, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 9, S("abcdefghij123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 0, 11, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 1, S("abcdefghij2pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 4, S("abcdefghij2345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 8, S("abcdefghij23456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 9, S("abcdefghij234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 1, 10, S("abcdefghij234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 1, S("abcdefghij6pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 2, S("abcdefghij67pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 4, S("abcdefghij6789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 5, S("abcdefghij67890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 5, 6, S("abcdefghij67890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 1, S("abcdefghij0pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 9, 2, S("abcdefghij0pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 10, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 10, 1, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 1, S("abcdefghij1pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 1, S("abcdefghij2pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 9, S("abcdefghij234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 1, S("abcdefghij1pqrst"));
+}
+
+void test48()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 5, S("abcdefghij12345pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 9, S("abcdefghij123456789pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 1, S("abcdefghij0pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 19, 2, S("abcdefghij0pqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 20, 0, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 20, 1, S("abcdefghijpqrst"));
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 1, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 2, S("abcdefghij12t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 4, S("abcdefghij1234t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 0, 6, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 1, S("abcdefghij2t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 2, S("abcdefghij23t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 3, S("abcdefghij234t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 4, S("abcdefghij2345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 1, 5, S("abcdefghij2345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 1, S("abcdefghij3t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 2, S("abcdefghij34t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 3, S("abcdefghij345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 2, 4, S("abcdefghij345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 1, S("abcdefghij5t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 4, 2, S("abcdefghij5t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 5, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 5, 1, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 9, S("abcdefghij123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 0, 11, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 1, S("abcdefghij2t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 4, S("abcdefghij2345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 8, S("abcdefghij23456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 9, S("abcdefghij234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 1, 10, S("abcdefghij234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 1, S("abcdefghij6t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 2, S("abcdefghij67t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 4, S("abcdefghij6789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 5, S("abcdefghij67890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 5, 6, S("abcdefghij67890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 1, S("abcdefghij0t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 9, 2, S("abcdefghij0t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 10, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 10, 1, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 1, S("abcdefghij2t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 9, S("abcdefghij234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 1, S("abcdefghij1t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 5, S("abcdefghij12345t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 9, S("abcdefghij123456789t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 1, S("abcdefghij0t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 19, 2, S("abcdefghij0t"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 20, 0, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 20, 1, S("abcdefghijt"));
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 0, 6, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 2, S("abcdefghij23"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 3, S("abcdefghij234"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 1, 5, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 0, S("abcdefghij"));
+}
+
+void test49()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 1, S("abcdefghij3"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 2, S("abcdefghij34"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 3, S("abcdefghij345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 2, 4, S("abcdefghij345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 1, S("abcdefghij5"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 4, 2, S("abcdefghij5"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 8, S("abcdefghij23456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 1, 10, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 1, S("abcdefghij6"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 2, S("abcdefghij67"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 4, S("abcdefghij6789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 5, S("abcdefghij67890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 5, 6, S("abcdefghij67890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 1, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 9, 2, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 2, S("abcdefghij12"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 4, S("abcdefghij1234"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 0, 6, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 2, S("abcdefghij23"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 3, S("abcdefghij234"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 1, 5, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 1, S("abcdefghij3"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 2, S("abcdefghij34"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 3, S("abcdefghij345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 2, 4, S("abcdefghij345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 1, S("abcdefghij5"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 4, 2, S("abcdefghij5"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 5, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 0, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 4, S("abcdefghij2345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 8, S("abcdefghij23456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 1, 10, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 1, S("abcdefghij6"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 2, S("abcdefghij67"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 4, S("abcdefghij6789"));
+}
+
+void test50()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 5, S("abcdefghij67890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 5, 6, S("abcdefghij67890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 1, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 9, 2, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 10, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 19, S("abcdefghij1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 20, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 0, 21, S("abcdefghij12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 1, S("abcdefghij2"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 9, S("abcdefghij234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 18, S("abcdefghij234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 19, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 1, 20, S("abcdefghij2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 1, S("abcdefghij1"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 5, S("abcdefghij12345"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 9, S("abcdefghij123456789"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 10, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 10, 11, S("abcdefghij1234567890"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 1, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 19, 2, S("abcdefghij0"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 20, 0, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 20, 1, S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 2, S("abcdefghijklmnopqrs12t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 2, S("abcdefghijklmnopqrs23t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 3, S("abcdefghijklmnopqrs234t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 1, S("abcdefghijklmnopqrs3t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 2, S("abcdefghijklmnopqrs34t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 3, S("abcdefghijklmnopqrs345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 2, 4, S("abcdefghijklmnopqrs345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 1, S("abcdefghijklmnopqrs5t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 4, 2, S("abcdefghijklmnopqrs5t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890t"));
+}
+
+void test51()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0t"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 5, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 5, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 2, S("abcdefghijklmnopqrs12"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 4, S("abcdefghijklmnopqrs1234"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 0, 6, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 2, S("abcdefghijklmnopqrs23"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 3, S("abcdefghijklmnopqrs234"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 4, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 1, 5, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 1, S("abcdefghijklmnopqrs3"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 2, S("abcdefghijklmnopqrs34"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 3, S("abcdefghijklmnopqrs345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 2, 4, S("abcdefghijklmnopqrs345"));
+}
+
+void test52()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 1, S("abcdefghijklmnopqrs5"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 4, 2, S("abcdefghijklmnopqrs5"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 5, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 5, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 0, 11, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 4, S("abcdefghijklmnopqrs2345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 8, S("abcdefghijklmnopqrs23456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 1, 10, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 1, S("abcdefghijklmnopqrs6"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 2, S("abcdefghijklmnopqrs67"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 4, S("abcdefghijklmnopqrs6789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 5, S("abcdefghijklmnopqrs67890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 5, 6, S("abcdefghijklmnopqrs67890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 1, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 9, 2, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 10, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 10, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrs1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrs12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrs2"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrs234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrs234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrs2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrs2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrs1"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrs12345"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrs123456789"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrs1234567890"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrs0"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrs"));
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
+}
+
+void test53()
+{
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 2, S("abcdefghijklmnopqrst12"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 4, S("abcdefghijklmnopqrst1234"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 0, 6, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 2, S("abcdefghijklmnopqrst23"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 3, S("abcdefghijklmnopqrst234"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 1, 5, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 1, S("abcdefghijklmnopqrst3"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 2, S("abcdefghijklmnopqrst34"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 3, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 2, 4, S("abcdefghijklmnopqrst345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 1, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 4, 2, S("abcdefghijklmnopqrst5"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 5, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 0, 11, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 4, S("abcdefghijklmnopqrst2345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 8, S("abcdefghijklmnopqrst23456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 1, 10, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 1, S("abcdefghijklmnopqrst6"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 2, S("abcdefghijklmnopqrst67"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 4, S("abcdefghijklmnopqrst6789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 5, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 5, 6, S("abcdefghijklmnopqrst67890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 1, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 9, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 10, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 19, S("abcdefghijklmnopqrst1234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 20, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 0, 21, S("abcdefghijklmnopqrst12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 1, S("abcdefghijklmnopqrst2"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 9, S("abcdefghijklmnopqrst234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 18, S("abcdefghijklmnopqrst234567890123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 19, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 1, 20, S("abcdefghijklmnopqrst2345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 1, S("abcdefghijklmnopqrst1"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 5, S("abcdefghijklmnopqrst12345"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 9, S("abcdefghijklmnopqrst123456789"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 10, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 10, 11, S("abcdefghijklmnopqrst1234567890"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 0, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 1, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 19, 2, S("abcdefghijklmnopqrst0"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 20, 0, S("abcdefghijklmnopqrst"));
+}
+
+void test54()
+{
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 20, 1, S("abcdefghijklmnopqrst"));
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("12345678901234567890"), 21, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 0, 6, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 3, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 1, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 3, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 2, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 4, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 5, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 5, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345"), 6, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 0, 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 8, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 1, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 4, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 5, 6, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 9, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("1234567890"), 11, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 0, 21, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 18, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 19, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 1, 20, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 5, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 9, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 10, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 10, 11, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 19, 2, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 20, 0, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 20, 1, S("can't happen"));
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+    test9();
+    test10();
+    test11();
+    test12();
+    test13();
+    test14();
+    test15();
+    test16();
+    test17();
+    test18();
+    test19();
+    test20();
+    test21();
+    test22();
+    test23();
+    test24();
+    test25();
+    test26();
+    test27();
+    test28();
+    test29();
+    test30();
+    test31();
+    test32();
+    test33();
+    test34();
+    test35();
+    test36();
+    test37();
+    test38();
+    test39();
+    test40();
+    test41();
+    test42();
+    test43();
+    test44();
+    test45();
+    test46();
+    test47();
+    test48();
+    test49();
+    test50();
+    test51();
+    test52();
+    test53();
+    test54();
+}
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string::swap/swap.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string::swap/swap.pass.cpp
new file mode 100644
index 0000000..a6d0468
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.modifiers/string::swap/swap.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// void swap(basic_string& s);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+template <class S>
+void
+test(S s1, S s2)
+{
+    S s1_ = s1;
+    S s2_ = s2;
+    s1.swap(s2);
+    assert(s1.__invariants());
+    assert(s2.__invariants());
+    assert(s1 == s2_);
+    assert(s2 == s1_);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(""), S(""));
+    test(S(""), S("12345"));
+    test(S(""), S("1234567890"));
+    test(S(""), S("12345678901234567890"));
+    test(S("abcde"), S(""));
+    test(S("abcde"), S("12345"));
+    test(S("abcde"), S("1234567890"));
+    test(S("abcde"), S("12345678901234567890"));
+    test(S("abcdefghij"), S(""));
+    test(S("abcdefghij"), S("12345"));
+    test(S("abcdefghij"), S("1234567890"));
+    test(S("abcdefghij"), S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), S(""));
+    test(S("abcdefghijklmnopqrst"), S("12345"));
+    test(S("abcdefghijklmnopqrst"), S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/nothing_to_do.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp
new file mode 100644
index 0000000..5991c1c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_istream<charT,traits>&
+//   getline(basic_istream<charT,traits>& is,
+//           basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        std::istringstream in(" abc\n  def\n   ghij");
+        std::string s("initial text");
+        getline(in, s);
+        assert(in.good());
+        assert(s == " abc");
+        getline(in, s);
+        assert(in.good());
+        assert(s == "  def");
+        getline(in, s);
+        assert(in.eof());
+        assert(s == "   ghij");
+    }
+    {
+        std::wistringstream in(L" abc\n  def\n   ghij");
+        std::wstring s(L"initial text");
+        getline(in, s);
+        assert(in.good());
+        assert(s == L" abc");
+        getline(in, s);
+        assert(in.good());
+        assert(s == L"  def");
+        getline(in, s);
+        assert(in.eof());
+        assert(s == L"   ghij");
+    }
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp
new file mode 100644
index 0000000..97f4ffd
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_istream<charT,traits>&
+//   getline(basic_istream<charT,traits>& is,
+//           basic_string<charT,traits,Allocator>& str, charT delim);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        std::istringstream in(" abc*  def*   ghij");
+        std::string s("initial text");
+        getline(in, s, '*');
+        assert(in.good());
+        assert(s == " abc");
+        getline(in, s, '*');
+        assert(in.good());
+        assert(s == "  def");
+        getline(in, s, '*');
+        assert(in.eof());
+        assert(s == "   ghij");
+    }
+    {
+        std::wistringstream in(L" abc*  def*   ghij");
+        std::wstring s(L"initial text");
+        getline(in, s, L'*');
+        assert(in.good());
+        assert(s == L" abc");
+        getline(in, s, L'*');
+        assert(in.good());
+        assert(s == L"  def");
+        getline(in, s, L'*');
+        assert(in.eof());
+        assert(s == L"   ghij");
+    }
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim_rv.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim_rv.pass.cpp
new file mode 100644
index 0000000..cd9b711
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_delim_rv.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_istream<charT,traits>&
+//   getline(basic_istream<charT,traits>&& is,
+//           basic_string<charT,traits,Allocator>& str, charT delim);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("initial text");
+        getline(std::istringstream(" abc*  def*   ghij"), s, '*');
+        assert(s == " abc");
+    }
+    {
+        std::wstring s(L"initial text");
+        getline(std::wistringstream(L" abc*  def*   ghij"), s, L'*');
+        assert(s == L" abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_rv.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_rv.pass.cpp
new file mode 100644
index 0000000..6541f46
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/get_line_rv.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_istream<charT,traits>&
+//   getline(basic_istream<charT,traits>&& is,
+//           basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+#ifdef _LIBCPP_MOVE
+    {
+        std::string s("initial text");
+        getline(std::istringstream(" abc\n  def\n   ghij"), s);
+        assert(s == " abc");
+    }
+    {
+        std::wstring s(L"initial text");
+        getline(std::wistringstream(L" abc\n  def\n   ghij"), s);
+        assert(s == L" abc");
+    }
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp
new file mode 100644
index 0000000..cf50090
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_extract.pass.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_istream<charT,traits>&
+//   operator>>(basic_istream<charT,traits>& is,
+//              basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        std::istringstream in("a bc defghij");
+        std::string s("initial text");
+        in >> s;
+        assert(in.good());
+        assert(s == "a");
+        assert(in.peek() == ' ');
+        in >> s;
+        assert(in.good());
+        assert(s == "bc");
+        assert(in.peek() == ' ');
+        in.width(3);
+        in >> s;
+        assert(in.good());
+        assert(s == "def");
+        assert(in.peek() == 'g');
+        in >> s;
+        assert(in.eof());
+        assert(s == "ghij");
+        in >> s;
+        assert(in.fail());
+    }
+    {
+        std::wistringstream in(L"a bc defghij");
+        std::wstring s(L"initial text");
+        in >> s;
+        assert(in.good());
+        assert(s == L"a");
+        assert(in.peek() == L' ');
+        in >> s;
+        assert(in.good());
+        assert(s == L"bc");
+        assert(in.peek() == L' ');
+        in.width(3);
+        in >> s;
+        assert(in.good());
+        assert(s == L"def");
+        assert(in.peek() == L'g');
+        in >> s;
+        assert(in.eof());
+        assert(s == L"ghij");
+        in >> s;
+        assert(in.fail());
+    }
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_insert.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_insert.pass.cpp
new file mode 100644
index 0000000..d50c498
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.io/stream_insert.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+//   basic_ostream<charT, traits>&
+//   operator<<(basic_ostream<charT, traits>& os,
+//              const basic_string<charT,traits,Allocator>& str);
+
+#include <string>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        std::ostringstream out;
+        std::string s("some text");
+        out << s;
+        assert(out.good());
+        assert(s == out.str());
+    }
+    {
+        std::ostringstream out;
+        std::string s("some text");
+        out.width(12);
+        out << s;
+        assert(out.good());
+        assert("   " + s == out.str());
+    }
+    {
+        std::wostringstream out;
+        std::wstring s(L"some text");
+        out << s;
+        assert(out.good());
+        assert(s == out.str());
+    }
+    {
+        std::wostringstream out;
+        std::wstring s(L"some text");
+        out.width(12);
+        out << s;
+        assert(out.good());
+        assert(L"   " + s == out.str());
+    }
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
new file mode 100644
index 0000000..91ed562
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   void swap(basic_string<charT,traits,Allocator>& lhs, 
+//             basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+template <class S>
+void
+test(S s1, S s2)
+{
+    S s1_ = s1;
+    S s2_ = s2;
+    swap(s1, s2);
+    assert(s1.__invariants());
+    assert(s2.__invariants());
+    assert(s1 == s2_);
+    assert(s2 == s1_);
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(""), S(""));
+    test(S(""), S("12345"));
+    test(S(""), S("1234567890"));
+    test(S(""), S("12345678901234567890"));
+    test(S("abcde"), S(""));
+    test(S("abcde"), S("12345"));
+    test(S("abcde"), S("1234567890"));
+    test(S("abcde"), S("12345678901234567890"));
+    test(S("abcdefghij"), S(""));
+    test(S("abcdefghij"), S("12345"));
+    test(S("abcdefghij"), S("1234567890"));
+    test(S("abcdefghij"), S("12345678901234567890"));
+    test(S("abcdefghijklmnopqrst"), S(""));
+    test(S("abcdefghijklmnopqrst"), S("12345"));
+    test(S("abcdefghijklmnopqrst"), S("1234567890"));
+    test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
+}
diff --git "a/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/pointer_string.pass.cpp" "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/pointer_string.pass.cpp"
new file mode 100644
index 0000000..2c1d596
--- /dev/null
+++ "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/pointer_string.pass.cpp"
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator!=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs != rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), false);
+    test("", S("abcde"), true);
+    test("", S("abcdefghij"), true);
+    test("", S("abcdefghijklmnopqrst"), true);
+    test("abcde", S(""), true);
+    test("abcde", S("abcde"), false);
+    test("abcde", S("abcdefghij"), true);
+    test("abcde", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghij", S(""), true);
+    test("abcdefghij", S("abcde"), true);
+    test("abcdefghij", S("abcdefghij"), false);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghijklmnopqrst", S(""), true);
+    test("abcdefghijklmnopqrst", S("abcde"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
+}
diff --git "a/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_pointer.pass.cpp" "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_pointer.pass.cpp"
new file mode 100644
index 0000000..7c82fd7
--- /dev/null
+++ "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_pointer.pass.cpp"
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator!=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs != rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", false);
+    test(S(""), "abcde", true);
+    test(S(""), "abcdefghij", true);
+    test(S(""), "abcdefghijklmnopqrst", true);
+    test(S("abcde"), "", true);
+    test(S("abcde"), "abcde", false);
+    test(S("abcde"), "abcdefghij", true);
+    test(S("abcde"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghij"), "", true);
+    test(S("abcdefghij"), "abcde", true);
+    test(S("abcdefghij"), "abcdefghij", false);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghijklmnopqrst"), "", true);
+    test(S("abcdefghijklmnopqrst"), "abcde", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
+}
diff --git "a/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_string.pass.cpp" "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_string.pass.cpp"
new file mode 100644
index 0000000..5472626
--- /dev/null
+++ "b/libcxx/test/strings/basic.string/string.nonmembers/string::op\041=/string_string.pass.cpp"
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator!=(const basic_string<charT,traits,Allocator>& lhs, 
+//                   const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs != rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), false);
+    test(S(""), S("abcde"), true);
+    test(S(""), S("abcdefghij"), true);
+    test(S(""), S("abcdefghijklmnopqrst"), true);
+    test(S("abcde"), S(""), true);
+    test(S("abcde"), S("abcde"), false);
+    test(S("abcde"), S("abcdefghij"), true);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghij"), S(""), true);
+    test(S("abcdefghij"), S("abcde"), true);
+    test(S("abcdefghij"), S("abcdefghij"), false);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghijklmnopqrst"), S(""), true);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::op+/char_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/char_string.pass.cpp
new file mode 100644
index 0000000..0355616
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/char_string.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator> 
+//   operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(charT lhs, basic_string<charT,traits,Allocator>&& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test0(typename S::value_type lhs, const S& rhs, const S& x)
+{
+    assert(lhs + rhs == x);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class S>
+void
+test1(typename S::value_type lhs, S&& rhs, const S& x)
+{
+    assert(lhs + move(rhs) == x);
+}
+
+#endif
+
+typedef std::string S;
+
+int main()
+{
+    test0('a', S(""), S("a"));
+    test0('a', S("12345"), S("a12345"));
+    test0('a', S("1234567890"), S("a1234567890"));
+    test0('a', S("12345678901234567890"), S("a12345678901234567890"));
+
+#ifdef _LIBCPP_MOVE
+
+    test1('a', S(""), S("a"));
+    test1('a', S("12345"), S("a12345"));
+    test1('a', S("1234567890"), S("a1234567890"));
+    test1('a', S("12345678901234567890"), S("a12345678901234567890"));
+
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::op+/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/pointer_string.pass.cpp
new file mode 100644
index 0000000..9556770
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/pointer_string.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator> 
+//   operator+(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(const charT* lhs, basic_string<charT,traits,Allocator>&& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test0(const typename S::value_type* lhs, const S& rhs, const S& x)
+{
+    assert(lhs + rhs == x);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class S>
+void
+test1(const typename S::value_type* lhs, S&& rhs, const S& x)
+{
+    assert(lhs + move(rhs) == x);
+}
+
+#endif
+
+typedef std::string S;
+
+int main()
+{
+    test0("", S(""), S(""));
+    test0("", S("12345"), S("12345"));
+    test0("", S("1234567890"), S("1234567890"));
+    test0("", S("12345678901234567890"), S("12345678901234567890"));
+    test0("abcde", S(""), S("abcde"));
+    test0("abcde", S("12345"), S("abcde12345"));
+    test0("abcde", S("1234567890"), S("abcde1234567890"));
+    test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
+    test0("abcdefghij", S(""), S("abcdefghij"));
+    test0("abcdefghij", S("12345"), S("abcdefghij12345"));
+    test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
+    test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
+    test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
+    test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+#ifdef _LIBCPP_MOVE
+
+    test1("", S(""), S(""));
+    test1("", S("12345"), S("12345"));
+    test1("", S("1234567890"), S("1234567890"));
+    test1("", S("12345678901234567890"), S("12345678901234567890"));
+    test1("abcde", S(""), S("abcde"));
+    test1("abcde", S("12345"), S("abcde12345"));
+    test1("abcde", S("1234567890"), S("abcde1234567890"));
+    test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
+    test1("abcdefghij", S(""), S("abcdefghij"));
+    test1("abcdefghij", S("12345"), S("abcdefghij12345"));
+    test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
+    test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
+    test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
+    test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_char.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_char.pass.cpp
new file mode 100644
index 0000000..2ac997d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_char.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>
+//   operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(basic_string<charT,traits,Allocator>&& lhs, charT rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test0(const S& lhs, typename S::value_type rhs, const S& x)
+{
+    assert(lhs + rhs == x);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class S>
+void
+test1(S&& lhs, typename S::value_type rhs, const S& x)
+{
+    assert(move(lhs) + rhs == x);
+}
+
+#endif
+
+typedef std::string S;
+
+int main()
+{
+    test0(S(""), '1', S("1"));
+    test0(S("abcde"), '1', S("abcde1"));
+    test0(S("abcdefghij"), '1', S("abcdefghij1"));
+    test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
+
+#ifdef _LIBCPP_MOVE
+
+    test1(S(""), '1', S("1"));
+    test1(S("abcde"), '1', S("abcde1"));
+    test1(S("abcdefghij"), '1', S("abcdefghij1"));
+    test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
+
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_pointer.pass.cpp
new file mode 100644
index 0000000..5487bc1
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_pointer.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator> 
+//   operator+(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(basic_string<charT,traits,Allocator>&& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test0(const S& lhs, const typename S::value_type* rhs, const S& x)
+{
+    assert(lhs + rhs == x);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class S>
+void
+test1(S&& lhs, const typename S::value_type* rhs, const S& x)
+{
+    assert(move(lhs) + rhs == x);
+}
+
+#endif
+
+typedef std::string S;
+
+int main()
+{
+    test0(S(""), "", S(""));
+    test0(S(""), "12345", S("12345"));
+    test0(S(""), "1234567890", S("1234567890"));
+    test0(S(""), "12345678901234567890", S("12345678901234567890"));
+    test0(S("abcde"), "", S("abcde"));
+    test0(S("abcde"), "12345", S("abcde12345"));
+    test0(S("abcde"), "1234567890", S("abcde1234567890"));
+    test0(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
+    test0(S("abcdefghij"), "", S("abcdefghij"));
+    test0(S("abcdefghij"), "12345", S("abcdefghij12345"));
+    test0(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
+    test0(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test0(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
+    test0(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
+    test0(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test0(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+
+#ifdef _LIBCPP_MOVE
+
+    test1(S(""), "", S(""));
+    test1(S(""), "12345", S("12345"));
+    test1(S(""), "1234567890", S("1234567890"));
+    test1(S(""), "12345678901234567890", S("12345678901234567890"));
+    test1(S("abcde"), "", S("abcde"));
+    test1(S("abcde"), "12345", S("abcde12345"));
+    test1(S("abcde"), "1234567890", S("abcde1234567890"));
+    test1(S("abcde"), "12345678901234567890", S("abcde12345678901234567890"));
+    test1(S("abcdefghij"), "", S("abcdefghij"));
+    test1(S("abcdefghij"), "12345", S("abcdefghij12345"));
+    test1(S("abcdefghij"), "1234567890", S("abcdefghij1234567890"));
+    test1(S("abcdefghij"), "12345678901234567890", S("abcdefghij12345678901234567890"));
+    test1(S("abcdefghijklmnopqrst"), "", S("abcdefghijklmnopqrst"));
+    test1(S("abcdefghijklmnopqrst"), "12345", S("abcdefghijklmnopqrst12345"));
+    test1(S("abcdefghijklmnopqrst"), "1234567890", S("abcdefghijklmnopqrst1234567890"));
+    test1(S("abcdefghijklmnopqrst"), "12345678901234567890", S("abcdefghijklmnopqrst12345678901234567890"));
+
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_string.pass.cpp
new file mode 100644
index 0000000..b9ab0de
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::op+/string_string.pass.cpp
@@ -0,0 +1,142 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator> 
+//   operator+(const basic_string<charT,traits,Allocator>& lhs, 
+//             const basic_string<charT,traits,Allocator>& rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(const basic_string<charT,traits,Allocator>&& lhs, 
+//             const basic_string<charT,traits,Allocator>& rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(const basic_string<charT,traits,Allocator>& lhs, 
+//             const basic_string<charT,traits,Allocator>&& rhs);
+
+// template<class charT, class traits, class Allocator> 
+//   basic_string<charT,traits,Allocator>&&
+//   operator+(const basic_string<charT,traits,Allocator>&& lhs, 
+//             const basic_string<charT,traits,Allocator>&& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test0(const S& lhs, const S& rhs, const S& x)
+{
+    assert(lhs + rhs == x);
+}
+
+#ifdef _LIBCPP_MOVE
+
+template <class S>
+void
+test1(S&& lhs, const S& rhs, const S& x)
+{
+    assert(move(lhs) + rhs == x);
+}
+
+template <class S>
+void
+test2(const S& lhs, S&& rhs, const S& x)
+{
+    assert(lhs + move(rhs) == x);
+}
+
+template <class S>
+void
+test3(S&& lhs, S&& rhs, const S& x)
+{
+    assert(move(lhs) + move(rhs) == x);
+}
+
+#endif
+
+typedef std::string S;
+
+int main()
+{
+    test0(S(""), S(""), S(""));
+    test0(S(""), S("12345"), S("12345"));
+    test0(S(""), S("1234567890"), S("1234567890"));
+    test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
+    test0(S("abcde"), S(""), S("abcde"));
+    test0(S("abcde"), S("12345"), S("abcde12345"));
+    test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
+    test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
+    test0(S("abcdefghij"), S(""), S("abcdefghij"));
+    test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
+    test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
+    test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
+    test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
+    test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+#ifdef _LIBCPP_MOVE
+
+    test1(S(""), S(""), S(""));
+    test1(S(""), S("12345"), S("12345"));
+    test1(S(""), S("1234567890"), S("1234567890"));
+    test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
+    test1(S("abcde"), S(""), S("abcde"));
+    test1(S("abcde"), S("12345"), S("abcde12345"));
+    test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
+    test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
+    test1(S("abcdefghij"), S(""), S("abcdefghij"));
+    test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
+    test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
+    test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
+    test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
+    test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+    test2(S(""), S(""), S(""));
+    test2(S(""), S("12345"), S("12345"));
+    test2(S(""), S("1234567890"), S("1234567890"));
+    test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
+    test2(S("abcde"), S(""), S("abcde"));
+    test2(S("abcde"), S("12345"), S("abcde12345"));
+    test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
+    test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
+    test2(S("abcdefghij"), S(""), S("abcdefghij"));
+    test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
+    test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
+    test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
+    test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
+    test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+    test3(S(""), S(""), S(""));
+    test3(S(""), S("12345"), S("12345"));
+    test3(S(""), S("1234567890"), S("1234567890"));
+    test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
+    test3(S("abcde"), S(""), S("abcde"));
+    test3(S("abcde"), S("12345"), S("abcde12345"));
+    test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
+    test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
+    test3(S("abcdefghij"), S(""), S("abcdefghij"));
+    test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
+    test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
+    test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
+    test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
+    test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
+    test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
+    test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
+
+#endif
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/pointer_string.pass.cpp
new file mode 100644
index 0000000..9fce864
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/pointer_string.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator==(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs == rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), true);
+    test("", S("abcde"), false);
+    test("", S("abcdefghij"), false);
+    test("", S("abcdefghijklmnopqrst"), false);
+    test("abcde", S(""), false);
+    test("abcde", S("abcde"), true);
+    test("abcde", S("abcdefghij"), false);
+    test("abcde", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghij", S(""), false);
+    test("abcdefghij", S("abcde"), false);
+    test("abcdefghij", S("abcdefghij"), true);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghijklmnopqrst", S(""), false);
+    test("abcdefghijklmnopqrst", S("abcde"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_pointer.pass.cpp
new file mode 100644
index 0000000..e365c80
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_pointer.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs == rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", true);
+    test(S(""), "abcde", false);
+    test(S(""), "abcdefghij", false);
+    test(S(""), "abcdefghijklmnopqrst", false);
+    test(S("abcde"), "", false);
+    test(S("abcde"), "abcde", true);
+    test(S("abcde"), "abcdefghij", false);
+    test(S("abcde"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghij"), "", false);
+    test(S("abcdefghij"), "abcde", false);
+    test(S("abcdefghij"), "abcdefghij", true);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghijklmnopqrst"), "", false);
+    test(S("abcdefghijklmnopqrst"), "abcde", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_string.pass.cpp
new file mode 100644
index 0000000..065c1ff
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::operator==/string_string.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator==(const basic_string<charT,traits,Allocator>& lhs, 
+//                   const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs == rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), true);
+    test(S(""), S("abcde"), false);
+    test(S(""), S("abcdefghij"), false);
+    test(S(""), S("abcdefghijklmnopqrst"), false);
+    test(S("abcde"), S(""), false);
+    test(S("abcde"), S("abcde"), true);
+    test(S("abcde"), S("abcdefghij"), false);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghij"), S(""), false);
+    test(S("abcdefghij"), S("abcde"), false);
+    test(S("abcdefghij"), S("abcdefghij"), true);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghijklmnopqrst"), S(""), false);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/pointer_string.pass.cpp
new file mode 100644
index 0000000..8a0c10b
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/pointer_string.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs > rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), false);
+    test("", S("abcde"), false);
+    test("", S("abcdefghij"), false);
+    test("", S("abcdefghijklmnopqrst"), false);
+    test("abcde", S(""), true);
+    test("abcde", S("abcde"), false);
+    test("abcde", S("abcdefghij"), false);
+    test("abcde", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghij", S(""), true);
+    test("abcdefghij", S("abcde"), true);
+    test("abcdefghij", S("abcdefghij"), false);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghijklmnopqrst", S(""), true);
+    test("abcdefghijklmnopqrst", S("abcde"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_pointer.pass.cpp
new file mode 100644
index 0000000..40f398e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_pointer.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs > rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", false);
+    test(S(""), "abcde", false);
+    test(S(""), "abcdefghij", false);
+    test(S(""), "abcdefghijklmnopqrst", false);
+    test(S("abcde"), "", true);
+    test(S("abcde"), "abcde", false);
+    test(S("abcde"), "abcdefghij", false);
+    test(S("abcde"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghij"), "", true);
+    test(S("abcdefghij"), "abcde", true);
+    test(S("abcdefghij"), "abcdefghij", false);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghijklmnopqrst"), "", true);
+    test(S("abcdefghijklmnopqrst"), "abcde", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_string.pass.cpp
new file mode 100644
index 0000000..3c5a50c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt/string_string.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>(const basic_string<charT,traits,Allocator>& lhs, 
+//                  const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs > rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), false);
+    test(S(""), S("abcde"), false);
+    test(S(""), S("abcdefghij"), false);
+    test(S(""), S("abcdefghijklmnopqrst"), false);
+    test(S("abcde"), S(""), true);
+    test(S("abcde"), S("abcde"), false);
+    test(S("abcde"), S("abcdefghij"), false);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghij"), S(""), true);
+    test(S("abcdefghij"), S("abcde"), true);
+    test(S("abcdefghij"), S("abcdefghij"), false);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghijklmnopqrst"), S(""), true);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/pointer_string.pass.cpp
new file mode 100644
index 0000000..48df45b
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/pointer_string.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs >= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), true);
+    test("", S("abcde"), false);
+    test("", S("abcdefghij"), false);
+    test("", S("abcdefghijklmnopqrst"), false);
+    test("abcde", S(""), true);
+    test("abcde", S("abcde"), true);
+    test("abcde", S("abcdefghij"), false);
+    test("abcde", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghij", S(""), true);
+    test("abcdefghij", S("abcde"), true);
+    test("abcdefghij", S("abcdefghij"), true);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), false);
+    test("abcdefghijklmnopqrst", S(""), true);
+    test("abcdefghijklmnopqrst", S("abcde"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), true);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_pointer.pass.cpp
new file mode 100644
index 0000000..71f1896
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_pointer.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs >= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", true);
+    test(S(""), "abcde", false);
+    test(S(""), "abcdefghij", false);
+    test(S(""), "abcdefghijklmnopqrst", false);
+    test(S("abcde"), "", true);
+    test(S("abcde"), "abcde", true);
+    test(S("abcde"), "abcdefghij", false);
+    test(S("abcde"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghij"), "", true);
+    test(S("abcdefghij"), "abcde", true);
+    test(S("abcdefghij"), "abcdefghij", true);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", false);
+    test(S("abcdefghijklmnopqrst"), "", true);
+    test(S("abcdefghijklmnopqrst"), "abcde", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_string.pass.cpp
new file mode 100644
index 0000000..a2f76bea
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::opgt=/string_string.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator>=(const basic_string<charT,traits,Allocator>& lhs, 
+//                  const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs >= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), true);
+    test(S(""), S("abcde"), false);
+    test(S(""), S("abcdefghij"), false);
+    test(S(""), S("abcdefghijklmnopqrst"), false);
+    test(S("abcde"), S(""), true);
+    test(S("abcde"), S("abcde"), true);
+    test(S("abcde"), S("abcdefghij"), false);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghij"), S(""), true);
+    test(S("abcdefghij"), S("abcde"), true);
+    test(S("abcdefghij"), S("abcdefghij"), true);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), false);
+    test(S("abcdefghijklmnopqrst"), S(""), true);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), true);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/pointer_string.pass.cpp
new file mode 100644
index 0000000..6e7eb43
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/pointer_string.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs < rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), false);
+    test("", S("abcde"), true);
+    test("", S("abcdefghij"), true);
+    test("", S("abcdefghijklmnopqrst"), true);
+    test("abcde", S(""), false);
+    test("abcde", S("abcde"), false);
+    test("abcde", S("abcdefghij"), true);
+    test("abcde", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghij", S(""), false);
+    test("abcdefghij", S("abcde"), false);
+    test("abcdefghij", S("abcdefghij"), false);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghijklmnopqrst", S(""), false);
+    test("abcdefghijklmnopqrst", S("abcde"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_pointer.pass.cpp
new file mode 100644
index 0000000..0e7654e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_pointer.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs < rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", false);
+    test(S(""), "abcde", true);
+    test(S(""), "abcdefghij", true);
+    test(S(""), "abcdefghijklmnopqrst", true);
+    test(S("abcde"), "", false);
+    test(S("abcde"), "abcde", false);
+    test(S("abcde"), "abcdefghij", true);
+    test(S("abcde"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghij"), "", false);
+    test(S("abcdefghij"), "abcde", false);
+    test(S("abcdefghij"), "abcdefghij", false);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghijklmnopqrst"), "", false);
+    test(S("abcdefghijklmnopqrst"), "abcde", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_string.pass.cpp
new file mode 100644
index 0000000..4e3a7ad
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt/string_string.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<(const basic_string<charT,traits,Allocator>& lhs, 
+//                  const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs < rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), false);
+    test(S(""), S("abcde"), true);
+    test(S(""), S("abcdefghij"), true);
+    test(S(""), S("abcdefghijklmnopqrst"), true);
+    test(S("abcde"), S(""), false);
+    test(S("abcde"), S("abcde"), false);
+    test(S("abcde"), S("abcdefghij"), true);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghij"), S(""), false);
+    test(S("abcdefghij"), S("abcde"), false);
+    test(S("abcdefghij"), S("abcdefghij"), false);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghijklmnopqrst"), S(""), false);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/pointer_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/pointer_string.pass.cpp
new file mode 100644
index 0000000..7fe7d16
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/pointer_string.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const typename S::value_type* lhs, const S& rhs, bool x)
+{
+    assert((lhs <= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test("", S(""), true);
+    test("", S("abcde"), true);
+    test("", S("abcdefghij"), true);
+    test("", S("abcdefghijklmnopqrst"), true);
+    test("abcde", S(""), false);
+    test("abcde", S("abcde"), true);
+    test("abcde", S("abcdefghij"), true);
+    test("abcde", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghij", S(""), false);
+    test("abcdefghij", S("abcde"), false);
+    test("abcdefghij", S("abcdefghij"), true);
+    test("abcdefghij", S("abcdefghijklmnopqrst"), true);
+    test("abcdefghijklmnopqrst", S(""), false);
+    test("abcdefghijklmnopqrst", S("abcde"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghij"), false);
+    test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_pointer.pass.cpp
new file mode 100644
index 0000000..9df54c7
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_pointer.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const typename S::value_type* rhs, bool x)
+{
+    assert((lhs <= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", true);
+    test(S(""), "abcde", true);
+    test(S(""), "abcdefghij", true);
+    test(S(""), "abcdefghijklmnopqrst", true);
+    test(S("abcde"), "", false);
+    test(S("abcde"), "abcde", true);
+    test(S("abcde"), "abcdefghij", true);
+    test(S("abcde"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghij"), "", false);
+    test(S("abcdefghij"), "abcde", false);
+    test(S("abcdefghij"), "abcdefghij", true);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
+    test(S("abcdefghijklmnopqrst"), "", false);
+    test(S("abcdefghijklmnopqrst"), "abcde", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", false);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", true);
+}
diff --git a/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_string.pass.cpp b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_string.pass.cpp
new file mode 100644
index 0000000..28e0c9c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.nonmembers/string::oplt=/string_string.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator> 
+//   bool operator<=(const basic_string<charT,traits,Allocator>& lhs, 
+//                  const basic_string<charT,traits,Allocator>& rhs);
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& lhs, const S& rhs, bool x)
+{
+    assert((lhs <= rhs) == x);
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), true);
+    test(S(""), S("abcde"), true);
+    test(S(""), S("abcdefghij"), true);
+    test(S(""), S("abcdefghijklmnopqrst"), true);
+    test(S("abcde"), S(""), false);
+    test(S("abcde"), S("abcde"), true);
+    test(S("abcde"), S("abcdefghij"), true);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghij"), S(""), false);
+    test(S("abcdefghij"), S("abcde"), false);
+    test(S("abcdefghij"), S("abcdefghij"), true);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true);
+    test(S("abcdefghijklmnopqrst"), S(""), false);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/nothing_to_do.pass.cpp b/libcxx/test/strings/basic.string/string.ops/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string.accessors/c_str.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string.accessors/c_str.pass.cpp
new file mode 100644
index 0000000..1a32acb
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string.accessors/c_str.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const charT* c_str() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s)
+{
+    typedef typename S::traits_type T;
+    const typename S::value_type* str = s.c_str();
+    if (s.size() > 0)
+    {
+        assert(T::compare(str, &s[0], s.size()) == 0);
+        assert(T::eq(str[s.size()], typename S::value_type()));
+    }
+    else
+        assert(T::eq(str[0], typename S::value_type()));
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(""));
+    test(S("abcde"));
+    test(S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"));
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string.accessors/data.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string.accessors/data.pass.cpp
new file mode 100644
index 0000000..c4c9af6
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string.accessors/data.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// const charT* data() const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s)
+{
+    typedef typename S::traits_type T;
+    const typename S::value_type* str = s.data();
+    if (s.size() > 0)
+    {
+        assert(T::compare(str, &s[0], s.size()) == 0);
+        assert(T::eq(str[s.size()], typename S::value_type()));
+    }
+    else
+        assert(T::eq(str[0], typename S::value_type()));
+}
+
+int main()
+{
+    typedef std::string S;
+    test(S(""));
+    test(S("abcde"));
+    test(S("abcdefghij"));
+    test(S("abcdefghijklmnopqrst"));
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string.accessors/get_allocator.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string.accessors/get_allocator.pass.cpp
new file mode 100644
index 0000000..b03debe
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string.accessors/get_allocator.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// allocator_type get_allocator() const;
+
+#include <string>
+#include <cassert>
+
+#include "../../test_allocator.h"
+
+template <class S>
+void
+test(const S& s, const typename S::allocator_type& a)
+{
+    assert(s.get_allocator() == a);
+}
+
+int main()
+{
+    typedef test_allocator<char> A;
+    typedef std::basic_string<char, std::char_traits<char>, A> S;
+    test(S(""), A());
+    test(S("abcde", A(1)), A(1));
+    test(S("abcdefghij", A(2)), A(2));
+    test(S("abcdefghijklmnopqrst", A(3)), A(3));
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/pointer.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/pointer.pass.cpp
new file mode 100644
index 0000000..709478d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/pointer.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(const charT *s) const;
+
+#include <string>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, int x)
+{
+    assert(sign(s.compare(str)) == sign(x));
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), "", 0);
+    test(S(""), "abcde", -5);
+    test(S(""), "abcdefghij", -10);
+    test(S(""), "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), "", 5);
+    test(S("abcde"), "abcde", 0);
+    test(S("abcde"), "abcdefghij", -5);
+    test(S("abcde"), "abcdefghijklmnopqrst", -15);
+    test(S("abcdefghij"), "", 10);
+    test(S("abcdefghij"), "abcde", 5);
+    test(S("abcdefghij"), "abcdefghij", 0);
+    test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
+    test(S("abcdefghijklmnopqrst"), "", 20);
+    test(S("abcdefghijklmnopqrst"), "abcde", 15);
+    test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer.pass.cpp
new file mode 100644
index 0000000..11894dc
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer.pass.cpp
@@ -0,0 +1,358 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(size_type pos, size_type n1, const charT *s) const;
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, typename S::size_type pos1, typename S::size_type n1,
+     const typename S::value_type* str, int x)
+{
+    try
+    {
+        assert(sign(s.compare(pos1, n1, str)) == sign(x));
+        assert(pos1 <= s.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > s.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), 0, 0, "", 0);
+    test(S(""), 0, 0, "abcde", -5);
+    test(S(""), 0, 0, "abcdefghij", -10);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", -20);
+    test(S(""), 0, 1, "", 0);
+    test(S(""), 0, 1, "abcde", -5);
+    test(S(""), 0, 1, "abcdefghij", -10);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", -20);
+    test(S(""), 1, 0, "", 0);
+    test(S(""), 1, 0, "abcde", 0);
+    test(S(""), 1, 0, "abcdefghij", 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 0);
+    test(S("abcde"), 0, 0, "", 0);
+    test(S("abcde"), 0, 0, "abcde", -5);
+    test(S("abcde"), 0, 0, "abcdefghij", -10);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), 0, 1, "", 1);
+    test(S("abcde"), 0, 1, "abcde", -4);
+    test(S("abcde"), 0, 1, "abcdefghij", -9);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", -19);
+    test(S("abcde"), 0, 2, "", 2);
+    test(S("abcde"), 0, 2, "abcde", -3);
+    test(S("abcde"), 0, 2, "abcdefghij", -8);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", -18);
+    test(S("abcde"), 0, 4, "", 4);
+    test(S("abcde"), 0, 4, "abcde", -1);
+    test(S("abcde"), 0, 4, "abcdefghij", -6);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", -16);
+    test(S("abcde"), 0, 5, "", 5);
+    test(S("abcde"), 0, 5, "abcde", 0);
+    test(S("abcde"), 0, 5, "abcdefghij", -5);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", -15);
+    test(S("abcde"), 0, 6, "", 5);
+    test(S("abcde"), 0, 6, "abcde", 0);
+    test(S("abcde"), 0, 6, "abcdefghij", -5);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", -15);
+    test(S("abcde"), 1, 0, "", 0);
+    test(S("abcde"), 1, 0, "abcde", -5);
+    test(S("abcde"), 1, 0, "abcdefghij", -10);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), 1, 1, "", 1);
+    test(S("abcde"), 1, 1, "abcde", 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 1);
+    test(S("abcde"), 1, 2, "", 2);
+    test(S("abcde"), 1, 2, "abcde", 1);
+    test(S("abcde"), 1, 2, "abcdefghij", 1);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 1);
+    test(S("abcde"), 1, 3, "", 3);
+    test(S("abcde"), 1, 3, "abcde", 1);
+    test(S("abcde"), 1, 3, "abcdefghij", 1);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 1);
+    test(S("abcde"), 1, 4, "", 4);
+    test(S("abcde"), 1, 4, "abcde", 1);
+    test(S("abcde"), 1, 4, "abcdefghij", 1);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 1);
+    test(S("abcde"), 1, 5, "", 4);
+    test(S("abcde"), 1, 5, "abcde", 1);
+    test(S("abcde"), 1, 5, "abcdefghij", 1);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 1);
+    test(S("abcde"), 2, 0, "", 0);
+    test(S("abcde"), 2, 0, "abcde", -5);
+    test(S("abcde"), 2, 0, "abcdefghij", -10);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), 2, 1, "", 1);
+    test(S("abcde"), 2, 1, "abcde", 2);
+    test(S("abcde"), 2, 1, "abcdefghij", 2);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 2);
+    test(S("abcde"), 2, 2, "", 2);
+    test(S("abcde"), 2, 2, "abcde", 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 2);
+    test(S("abcde"), 2, 3, "", 3);
+    test(S("abcde"), 2, 3, "abcde", 2);
+    test(S("abcde"), 2, 3, "abcdefghij", 2);
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 2);
+    test(S("abcde"), 2, 4, "", 3);
+    test(S("abcde"), 2, 4, "abcde", 2);
+    test(S("abcde"), 2, 4, "abcdefghij", 2);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 2);
+    test(S("abcde"), 4, 0, "", 0);
+    test(S("abcde"), 4, 0, "abcde", -5);
+    test(S("abcde"), 4, 0, "abcdefghij", -10);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), 4, 1, "", 1);
+    test(S("abcde"), 4, 1, "abcde", 4);
+    test(S("abcde"), 4, 1, "abcdefghij", 4);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 4);
+    test(S("abcde"), 4, 2, "", 1);
+    test(S("abcde"), 4, 2, "abcde", 4);
+    test(S("abcde"), 4, 2, "abcdefghij", 4);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 4);
+    test(S("abcde"), 5, 0, "", 0);
+    test(S("abcde"), 5, 0, "abcde", -5);
+    test(S("abcde"), 5, 0, "abcdefghij", -10);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcde"), 5, 1, "", 0);
+    test(S("abcde"), 5, 1, "abcde", -5);
+    test(S("abcde"), 5, 1, "abcdefghij", -10);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", -20);
+}
+
+void test1()
+{
+    test(S("abcde"), 6, 0, "", 0);
+    test(S("abcde"), 6, 0, "abcde", 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 0);
+    test(S("abcdefghij"), 0, 0, "", 0);
+    test(S("abcdefghij"), 0, 0, "abcde", -5);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", -10);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 0, 1, "", 1);
+    test(S("abcdefghij"), 0, 1, "abcde", -4);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", -9);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", -19);
+    test(S("abcdefghij"), 0, 5, "", 5);
+    test(S("abcdefghij"), 0, 5, "abcde", 0);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", -5);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", -15);
+    test(S("abcdefghij"), 0, 9, "", 9);
+    test(S("abcdefghij"), 0, 9, "abcde", 4);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", -1);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", -11);
+    test(S("abcdefghij"), 0, 10, "", 10);
+    test(S("abcdefghij"), 0, 10, "abcde", 5);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 0);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", -10);
+    test(S("abcdefghij"), 0, 11, "", 10);
+    test(S("abcdefghij"), 0, 11, "abcde", 5);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 0);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", -10);
+    test(S("abcdefghij"), 1, 0, "", 0);
+    test(S("abcdefghij"), 1, 0, "abcde", -5);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", -10);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 1, 1, "", 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghij"), 1, 4, "", 4);
+    test(S("abcdefghij"), 1, 4, "abcde", 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghij"), 1, 8, "", 8);
+    test(S("abcdefghij"), 1, 8, "abcde", 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghij"), 1, 9, "", 9);
+    test(S("abcdefghij"), 1, 9, "abcde", 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghij"), 1, 10, "", 9);
+    test(S("abcdefghij"), 1, 10, "abcde", 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghij"), 5, 0, "", 0);
+    test(S("abcdefghij"), 5, 0, "abcde", -5);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", -10);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 5, 1, "", 1);
+    test(S("abcdefghij"), 5, 1, "abcde", 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 5);
+    test(S("abcdefghij"), 5, 2, "", 2);
+    test(S("abcdefghij"), 5, 2, "abcde", 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 5);
+    test(S("abcdefghij"), 5, 4, "", 4);
+    test(S("abcdefghij"), 5, 4, "abcde", 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 5);
+    test(S("abcdefghij"), 5, 5, "", 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 5);
+    test(S("abcdefghij"), 5, 6, "", 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 5);
+    test(S("abcdefghij"), 9, 0, "", 0);
+    test(S("abcdefghij"), 9, 0, "abcde", -5);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", -10);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 9, 1, "", 1);
+    test(S("abcdefghij"), 9, 1, "abcde", 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 9);
+    test(S("abcdefghij"), 9, 2, "", 1);
+    test(S("abcdefghij"), 9, 2, "abcde", 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 9);
+    test(S("abcdefghij"), 10, 0, "", 0);
+    test(S("abcdefghij"), 10, 0, "abcde", -5);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", -10);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 10, 1, "", 0);
+    test(S("abcdefghij"), 10, 1, "abcde", -5);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", -10);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghij"), 11, 0, "", 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 0);
+}
+
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", -19);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "", 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "", 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "", 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "", 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", -20);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "", 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer_size.pass.cpp
new file mode 100644
index 0000000..1a30a9e
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_pointer_size.pass.cpp
@@ -0,0 +1,1291 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(size_type pos, size_type n1, const charT *s, size_type n2) const;
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, typename S::size_type pos, typename S::size_type n1,
+     const typename S::value_type* str, typename S::size_type n2, int x)
+{
+    try
+    {
+        assert(sign(s.compare(pos, n1, str, n2)) == sign(x));
+        assert(pos <= s.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > s.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), 0, 0, "", 0, 0);
+    test(S(""), 0, 0, "abcde", 0, 0);
+    test(S(""), 0, 0, "abcde", 1, -1);
+    test(S(""), 0, 0, "abcde", 2, -2);
+    test(S(""), 0, 0, "abcde", 4, -4);
+    test(S(""), 0, 0, "abcde", 5, -5);
+    test(S(""), 0, 0, "abcdefghij", 0, 0);
+    test(S(""), 0, 0, "abcdefghij", 1, -1);
+    test(S(""), 0, 0, "abcdefghij", 5, -5);
+    test(S(""), 0, 0, "abcdefghij", 9, -9);
+    test(S(""), 0, 0, "abcdefghij", 10, -10);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S(""), 0, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S(""), 0, 1, "", 0, 0);
+    test(S(""), 0, 1, "abcde", 0, 0);
+    test(S(""), 0, 1, "abcde", 1, -1);
+    test(S(""), 0, 1, "abcde", 2, -2);
+    test(S(""), 0, 1, "abcde", 4, -4);
+    test(S(""), 0, 1, "abcde", 5, -5);
+    test(S(""), 0, 1, "abcdefghij", 0, 0);
+    test(S(""), 0, 1, "abcdefghij", 1, -1);
+    test(S(""), 0, 1, "abcdefghij", 5, -5);
+    test(S(""), 0, 1, "abcdefghij", 9, -9);
+    test(S(""), 0, 1, "abcdefghij", 10, -10);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", 0, 0);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", 1, -1);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", 10, -10);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", 19, -19);
+    test(S(""), 0, 1, "abcdefghijklmnopqrst", 20, -20);
+    test(S(""), 1, 0, "", 0, 0);
+    test(S(""), 1, 0, "abcde", 0, 0);
+    test(S(""), 1, 0, "abcde", 1, 0);
+    test(S(""), 1, 0, "abcde", 2, 0);
+    test(S(""), 1, 0, "abcde", 4, 0);
+    test(S(""), 1, 0, "abcde", 5, 0);
+    test(S(""), 1, 0, "abcdefghij", 0, 0);
+    test(S(""), 1, 0, "abcdefghij", 1, 0);
+    test(S(""), 1, 0, "abcdefghij", 5, 0);
+    test(S(""), 1, 0, "abcdefghij", 9, 0);
+    test(S(""), 1, 0, "abcdefghij", 10, 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 1, 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 10, 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 19, 0);
+    test(S(""), 1, 0, "abcdefghijklmnopqrst", 20, 0);
+    test(S("abcde"), 0, 0, "", 0, 0);
+    test(S("abcde"), 0, 0, "abcde", 0, 0);
+    test(S("abcde"), 0, 0, "abcde", 1, -1);
+    test(S("abcde"), 0, 0, "abcde", 2, -2);
+    test(S("abcde"), 0, 0, "abcde", 4, -4);
+    test(S("abcde"), 0, 0, "abcde", 5, -5);
+    test(S("abcde"), 0, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 0, 0, "abcdefghij", 1, -1);
+    test(S("abcde"), 0, 0, "abcdefghij", 5, -5);
+    test(S("abcde"), 0, 0, "abcdefghij", 9, -9);
+    test(S("abcde"), 0, 0, "abcdefghij", 10, -10);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 0, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcde"), 0, 1, "", 0, 1);
+    test(S("abcde"), 0, 1, "abcde", 0, 1);
+    test(S("abcde"), 0, 1, "abcde", 1, 0);
+    test(S("abcde"), 0, 1, "abcde", 2, -1);
+    test(S("abcde"), 0, 1, "abcde", 4, -3);
+    test(S("abcde"), 0, 1, "abcde", 5, -4);
+    test(S("abcde"), 0, 1, "abcdefghij", 0, 1);
+    test(S("abcde"), 0, 1, "abcdefghij", 1, 0);
+    test(S("abcde"), 0, 1, "abcdefghij", 5, -4);
+    test(S("abcde"), 0, 1, "abcdefghij", 9, -8);
+    test(S("abcde"), 0, 1, "abcdefghij", 10, -9);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", 10, -9);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", 19, -18);
+    test(S("abcde"), 0, 1, "abcdefghijklmnopqrst", 20, -19);
+    test(S("abcde"), 0, 2, "", 0, 2);
+    test(S("abcde"), 0, 2, "abcde", 0, 2);
+    test(S("abcde"), 0, 2, "abcde", 1, 1);
+    test(S("abcde"), 0, 2, "abcde", 2, 0);
+    test(S("abcde"), 0, 2, "abcde", 4, -2);
+    test(S("abcde"), 0, 2, "abcde", 5, -3);
+    test(S("abcde"), 0, 2, "abcdefghij", 0, 2);
+    test(S("abcde"), 0, 2, "abcdefghij", 1, 1);
+    test(S("abcde"), 0, 2, "abcdefghij", 5, -3);
+    test(S("abcde"), 0, 2, "abcdefghij", 9, -7);
+    test(S("abcde"), 0, 2, "abcdefghij", 10, -8);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", 0, 2);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", 10, -8);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", 19, -17);
+    test(S("abcde"), 0, 2, "abcdefghijklmnopqrst", 20, -18);
+    test(S("abcde"), 0, 4, "", 0, 4);
+    test(S("abcde"), 0, 4, "abcde", 0, 4);
+    test(S("abcde"), 0, 4, "abcde", 1, 3);
+    test(S("abcde"), 0, 4, "abcde", 2, 2);
+}
+
+void test1()
+{
+    test(S("abcde"), 0, 4, "abcde", 4, 0);
+    test(S("abcde"), 0, 4, "abcde", 5, -1);
+    test(S("abcde"), 0, 4, "abcdefghij", 0, 4);
+    test(S("abcde"), 0, 4, "abcdefghij", 1, 3);
+    test(S("abcde"), 0, 4, "abcdefghij", 5, -1);
+    test(S("abcde"), 0, 4, "abcdefghij", 9, -5);
+    test(S("abcde"), 0, 4, "abcdefghij", 10, -6);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", 0, 4);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", 1, 3);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", 10, -6);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", 19, -15);
+    test(S("abcde"), 0, 4, "abcdefghijklmnopqrst", 20, -16);
+    test(S("abcde"), 0, 5, "", 0, 5);
+    test(S("abcde"), 0, 5, "abcde", 0, 5);
+    test(S("abcde"), 0, 5, "abcde", 1, 4);
+    test(S("abcde"), 0, 5, "abcde", 2, 3);
+    test(S("abcde"), 0, 5, "abcde", 4, 1);
+    test(S("abcde"), 0, 5, "abcde", 5, 0);
+    test(S("abcde"), 0, 5, "abcdefghij", 0, 5);
+    test(S("abcde"), 0, 5, "abcdefghij", 1, 4);
+    test(S("abcde"), 0, 5, "abcdefghij", 5, 0);
+    test(S("abcde"), 0, 5, "abcdefghij", 9, -4);
+    test(S("abcde"), 0, 5, "abcdefghij", 10, -5);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", 0, 5);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", 1, 4);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", 10, -5);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", 19, -14);
+    test(S("abcde"), 0, 5, "abcdefghijklmnopqrst", 20, -15);
+    test(S("abcde"), 0, 6, "", 0, 5);
+    test(S("abcde"), 0, 6, "abcde", 0, 5);
+    test(S("abcde"), 0, 6, "abcde", 1, 4);
+    test(S("abcde"), 0, 6, "abcde", 2, 3);
+    test(S("abcde"), 0, 6, "abcde", 4, 1);
+    test(S("abcde"), 0, 6, "abcde", 5, 0);
+    test(S("abcde"), 0, 6, "abcdefghij", 0, 5);
+    test(S("abcde"), 0, 6, "abcdefghij", 1, 4);
+    test(S("abcde"), 0, 6, "abcdefghij", 5, 0);
+    test(S("abcde"), 0, 6, "abcdefghij", 9, -4);
+    test(S("abcde"), 0, 6, "abcdefghij", 10, -5);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", 0, 5);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", 1, 4);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", 10, -5);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", 19, -14);
+    test(S("abcde"), 0, 6, "abcdefghijklmnopqrst", 20, -15);
+    test(S("abcde"), 1, 0, "", 0, 0);
+    test(S("abcde"), 1, 0, "abcde", 0, 0);
+    test(S("abcde"), 1, 0, "abcde", 1, -1);
+    test(S("abcde"), 1, 0, "abcde", 2, -2);
+    test(S("abcde"), 1, 0, "abcde", 4, -4);
+    test(S("abcde"), 1, 0, "abcde", 5, -5);
+    test(S("abcde"), 1, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 1, 0, "abcdefghij", 1, -1);
+    test(S("abcde"), 1, 0, "abcdefghij", 5, -5);
+    test(S("abcde"), 1, 0, "abcdefghij", 9, -9);
+    test(S("abcde"), 1, 0, "abcdefghij", 10, -10);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 1, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcde"), 1, 1, "", 0, 1);
+    test(S("abcde"), 1, 1, "abcde", 0, 1);
+    test(S("abcde"), 1, 1, "abcde", 1, 1);
+    test(S("abcde"), 1, 1, "abcde", 2, 1);
+    test(S("abcde"), 1, 1, "abcde", 4, 1);
+    test(S("abcde"), 1, 1, "abcde", 5, 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 0, 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 1, 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 5, 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 9, 1);
+    test(S("abcde"), 1, 1, "abcdefghij", 10, 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcde"), 1, 1, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcde"), 1, 2, "", 0, 2);
+    test(S("abcde"), 1, 2, "abcde", 0, 2);
+    test(S("abcde"), 1, 2, "abcde", 1, 1);
+    test(S("abcde"), 1, 2, "abcde", 2, 1);
+    test(S("abcde"), 1, 2, "abcde", 4, 1);
+    test(S("abcde"), 1, 2, "abcde", 5, 1);
+    test(S("abcde"), 1, 2, "abcdefghij", 0, 2);
+    test(S("abcde"), 1, 2, "abcdefghij", 1, 1);
+    test(S("abcde"), 1, 2, "abcdefghij", 5, 1);
+    test(S("abcde"), 1, 2, "abcdefghij", 9, 1);
+    test(S("abcde"), 1, 2, "abcdefghij", 10, 1);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 0, 2);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcde"), 1, 2, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcde"), 1, 3, "", 0, 3);
+    test(S("abcde"), 1, 3, "abcde", 0, 3);
+    test(S("abcde"), 1, 3, "abcde", 1, 1);
+    test(S("abcde"), 1, 3, "abcde", 2, 1);
+    test(S("abcde"), 1, 3, "abcde", 4, 1);
+    test(S("abcde"), 1, 3, "abcde", 5, 1);
+    test(S("abcde"), 1, 3, "abcdefghij", 0, 3);
+    test(S("abcde"), 1, 3, "abcdefghij", 1, 1);
+}
+
+void test2()
+{
+    test(S("abcde"), 1, 3, "abcdefghij", 5, 1);
+    test(S("abcde"), 1, 3, "abcdefghij", 9, 1);
+    test(S("abcde"), 1, 3, "abcdefghij", 10, 1);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 0, 3);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcde"), 1, 3, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcde"), 1, 4, "", 0, 4);
+    test(S("abcde"), 1, 4, "abcde", 0, 4);
+    test(S("abcde"), 1, 4, "abcde", 1, 1);
+    test(S("abcde"), 1, 4, "abcde", 2, 1);
+    test(S("abcde"), 1, 4, "abcde", 4, 1);
+    test(S("abcde"), 1, 4, "abcde", 5, 1);
+    test(S("abcde"), 1, 4, "abcdefghij", 0, 4);
+    test(S("abcde"), 1, 4, "abcdefghij", 1, 1);
+    test(S("abcde"), 1, 4, "abcdefghij", 5, 1);
+    test(S("abcde"), 1, 4, "abcdefghij", 9, 1);
+    test(S("abcde"), 1, 4, "abcdefghij", 10, 1);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 0, 4);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcde"), 1, 4, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcde"), 1, 5, "", 0, 4);
+    test(S("abcde"), 1, 5, "abcde", 0, 4);
+    test(S("abcde"), 1, 5, "abcde", 1, 1);
+    test(S("abcde"), 1, 5, "abcde", 2, 1);
+    test(S("abcde"), 1, 5, "abcde", 4, 1);
+    test(S("abcde"), 1, 5, "abcde", 5, 1);
+    test(S("abcde"), 1, 5, "abcdefghij", 0, 4);
+    test(S("abcde"), 1, 5, "abcdefghij", 1, 1);
+    test(S("abcde"), 1, 5, "abcdefghij", 5, 1);
+    test(S("abcde"), 1, 5, "abcdefghij", 9, 1);
+    test(S("abcde"), 1, 5, "abcdefghij", 10, 1);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 0, 4);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcde"), 1, 5, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcde"), 2, 0, "", 0, 0);
+    test(S("abcde"), 2, 0, "abcde", 0, 0);
+    test(S("abcde"), 2, 0, "abcde", 1, -1);
+    test(S("abcde"), 2, 0, "abcde", 2, -2);
+    test(S("abcde"), 2, 0, "abcde", 4, -4);
+    test(S("abcde"), 2, 0, "abcde", 5, -5);
+    test(S("abcde"), 2, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 2, 0, "abcdefghij", 1, -1);
+    test(S("abcde"), 2, 0, "abcdefghij", 5, -5);
+    test(S("abcde"), 2, 0, "abcdefghij", 9, -9);
+    test(S("abcde"), 2, 0, "abcdefghij", 10, -10);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 2, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcde"), 2, 1, "", 0, 1);
+    test(S("abcde"), 2, 1, "abcde", 0, 1);
+    test(S("abcde"), 2, 1, "abcde", 1, 2);
+    test(S("abcde"), 2, 1, "abcde", 2, 2);
+    test(S("abcde"), 2, 1, "abcde", 4, 2);
+    test(S("abcde"), 2, 1, "abcde", 5, 2);
+    test(S("abcde"), 2, 1, "abcdefghij", 0, 1);
+    test(S("abcde"), 2, 1, "abcdefghij", 1, 2);
+    test(S("abcde"), 2, 1, "abcdefghij", 5, 2);
+    test(S("abcde"), 2, 1, "abcdefghij", 9, 2);
+    test(S("abcde"), 2, 1, "abcdefghij", 10, 2);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 1, 2);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 10, 2);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 19, 2);
+    test(S("abcde"), 2, 1, "abcdefghijklmnopqrst", 20, 2);
+    test(S("abcde"), 2, 2, "", 0, 2);
+    test(S("abcde"), 2, 2, "abcde", 0, 2);
+    test(S("abcde"), 2, 2, "abcde", 1, 2);
+    test(S("abcde"), 2, 2, "abcde", 2, 2);
+    test(S("abcde"), 2, 2, "abcde", 4, 2);
+    test(S("abcde"), 2, 2, "abcde", 5, 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 0, 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 1, 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 5, 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 9, 2);
+    test(S("abcde"), 2, 2, "abcdefghij", 10, 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 0, 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 1, 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 10, 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 19, 2);
+    test(S("abcde"), 2, 2, "abcdefghijklmnopqrst", 20, 2);
+    test(S("abcde"), 2, 3, "", 0, 3);
+    test(S("abcde"), 2, 3, "abcde", 0, 3);
+    test(S("abcde"), 2, 3, "abcde", 1, 2);
+    test(S("abcde"), 2, 3, "abcde", 2, 2);
+    test(S("abcde"), 2, 3, "abcde", 4, 2);
+    test(S("abcde"), 2, 3, "abcde", 5, 2);
+    test(S("abcde"), 2, 3, "abcdefghij", 0, 3);
+    test(S("abcde"), 2, 3, "abcdefghij", 1, 2);
+    test(S("abcde"), 2, 3, "abcdefghij", 5, 2);
+    test(S("abcde"), 2, 3, "abcdefghij", 9, 2);
+    test(S("abcde"), 2, 3, "abcdefghij", 10, 2);
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 0, 3);
+}
+
+void test3()
+{
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 1, 2);
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 10, 2);
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 19, 2);
+    test(S("abcde"), 2, 3, "abcdefghijklmnopqrst", 20, 2);
+    test(S("abcde"), 2, 4, "", 0, 3);
+    test(S("abcde"), 2, 4, "abcde", 0, 3);
+    test(S("abcde"), 2, 4, "abcde", 1, 2);
+    test(S("abcde"), 2, 4, "abcde", 2, 2);
+    test(S("abcde"), 2, 4, "abcde", 4, 2);
+    test(S("abcde"), 2, 4, "abcde", 5, 2);
+    test(S("abcde"), 2, 4, "abcdefghij", 0, 3);
+    test(S("abcde"), 2, 4, "abcdefghij", 1, 2);
+    test(S("abcde"), 2, 4, "abcdefghij", 5, 2);
+    test(S("abcde"), 2, 4, "abcdefghij", 9, 2);
+    test(S("abcde"), 2, 4, "abcdefghij", 10, 2);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 0, 3);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 1, 2);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 10, 2);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 19, 2);
+    test(S("abcde"), 2, 4, "abcdefghijklmnopqrst", 20, 2);
+    test(S("abcde"), 4, 0, "", 0, 0);
+    test(S("abcde"), 4, 0, "abcde", 0, 0);
+    test(S("abcde"), 4, 0, "abcde", 1, -1);
+    test(S("abcde"), 4, 0, "abcde", 2, -2);
+    test(S("abcde"), 4, 0, "abcde", 4, -4);
+    test(S("abcde"), 4, 0, "abcde", 5, -5);
+    test(S("abcde"), 4, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 4, 0, "abcdefghij", 1, -1);
+    test(S("abcde"), 4, 0, "abcdefghij", 5, -5);
+    test(S("abcde"), 4, 0, "abcdefghij", 9, -9);
+    test(S("abcde"), 4, 0, "abcdefghij", 10, -10);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 4, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcde"), 4, 1, "", 0, 1);
+    test(S("abcde"), 4, 1, "abcde", 0, 1);
+    test(S("abcde"), 4, 1, "abcde", 1, 4);
+    test(S("abcde"), 4, 1, "abcde", 2, 4);
+    test(S("abcde"), 4, 1, "abcde", 4, 4);
+    test(S("abcde"), 4, 1, "abcde", 5, 4);
+    test(S("abcde"), 4, 1, "abcdefghij", 0, 1);
+    test(S("abcde"), 4, 1, "abcdefghij", 1, 4);
+    test(S("abcde"), 4, 1, "abcdefghij", 5, 4);
+    test(S("abcde"), 4, 1, "abcdefghij", 9, 4);
+    test(S("abcde"), 4, 1, "abcdefghij", 10, 4);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 1, 4);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 10, 4);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 19, 4);
+    test(S("abcde"), 4, 1, "abcdefghijklmnopqrst", 20, 4);
+    test(S("abcde"), 4, 2, "", 0, 1);
+    test(S("abcde"), 4, 2, "abcde", 0, 1);
+    test(S("abcde"), 4, 2, "abcde", 1, 4);
+    test(S("abcde"), 4, 2, "abcde", 2, 4);
+    test(S("abcde"), 4, 2, "abcde", 4, 4);
+    test(S("abcde"), 4, 2, "abcde", 5, 4);
+    test(S("abcde"), 4, 2, "abcdefghij", 0, 1);
+    test(S("abcde"), 4, 2, "abcdefghij", 1, 4);
+    test(S("abcde"), 4, 2, "abcdefghij", 5, 4);
+    test(S("abcde"), 4, 2, "abcdefghij", 9, 4);
+    test(S("abcde"), 4, 2, "abcdefghij", 10, 4);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 1, 4);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 10, 4);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 19, 4);
+    test(S("abcde"), 4, 2, "abcdefghijklmnopqrst", 20, 4);
+    test(S("abcde"), 5, 0, "", 0, 0);
+    test(S("abcde"), 5, 0, "abcde", 0, 0);
+    test(S("abcde"), 5, 0, "abcde", 1, -1);
+    test(S("abcde"), 5, 0, "abcde", 2, -2);
+    test(S("abcde"), 5, 0, "abcde", 4, -4);
+    test(S("abcde"), 5, 0, "abcde", 5, -5);
+    test(S("abcde"), 5, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 5, 0, "abcdefghij", 1, -1);
+    test(S("abcde"), 5, 0, "abcdefghij", 5, -5);
+    test(S("abcde"), 5, 0, "abcdefghij", 9, -9);
+    test(S("abcde"), 5, 0, "abcdefghij", 10, -10);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 5, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcde"), 5, 1, "", 0, 0);
+    test(S("abcde"), 5, 1, "abcde", 0, 0);
+    test(S("abcde"), 5, 1, "abcde", 1, -1);
+    test(S("abcde"), 5, 1, "abcde", 2, -2);
+    test(S("abcde"), 5, 1, "abcde", 4, -4);
+    test(S("abcde"), 5, 1, "abcde", 5, -5);
+    test(S("abcde"), 5, 1, "abcdefghij", 0, 0);
+    test(S("abcde"), 5, 1, "abcdefghij", 1, -1);
+    test(S("abcde"), 5, 1, "abcdefghij", 5, -5);
+    test(S("abcde"), 5, 1, "abcdefghij", 9, -9);
+    test(S("abcde"), 5, 1, "abcdefghij", 10, -10);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcde"), 5, 1, "abcdefghijklmnopqrst", 20, -20);
+}
+
+void test4()
+{
+    test(S("abcde"), 6, 0, "", 0, 0);
+    test(S("abcde"), 6, 0, "abcde", 0, 0);
+    test(S("abcde"), 6, 0, "abcde", 1, 0);
+    test(S("abcde"), 6, 0, "abcde", 2, 0);
+    test(S("abcde"), 6, 0, "abcde", 4, 0);
+    test(S("abcde"), 6, 0, "abcde", 5, 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 0, 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 1, 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 5, 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 9, 0);
+    test(S("abcde"), 6, 0, "abcdefghij", 10, 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 19, 0);
+    test(S("abcde"), 6, 0, "abcdefghijklmnopqrst", 20, 0);
+    test(S("abcdefghij"), 0, 0, "", 0, 0);
+    test(S("abcdefghij"), 0, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 0, 0, "abcde", 1, -1);
+    test(S("abcdefghij"), 0, 0, "abcde", 2, -2);
+    test(S("abcdefghij"), 0, 0, "abcde", 4, -4);
+    test(S("abcdefghij"), 0, 0, "abcde", 5, -5);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 0, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 0, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 0, 1, "", 0, 1);
+    test(S("abcdefghij"), 0, 1, "abcde", 0, 1);
+    test(S("abcdefghij"), 0, 1, "abcde", 1, 0);
+    test(S("abcdefghij"), 0, 1, "abcde", 2, -1);
+    test(S("abcdefghij"), 0, 1, "abcde", 4, -3);
+    test(S("abcdefghij"), 0, 1, "abcde", 5, -4);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", 1, 0);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", 5, -4);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", 9, -8);
+    test(S("abcdefghij"), 0, 1, "abcdefghij", 10, -9);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", 10, -9);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", 19, -18);
+    test(S("abcdefghij"), 0, 1, "abcdefghijklmnopqrst", 20, -19);
+    test(S("abcdefghij"), 0, 5, "", 0, 5);
+    test(S("abcdefghij"), 0, 5, "abcde", 0, 5);
+    test(S("abcdefghij"), 0, 5, "abcde", 1, 4);
+    test(S("abcdefghij"), 0, 5, "abcde", 2, 3);
+    test(S("abcdefghij"), 0, 5, "abcde", 4, 1);
+    test(S("abcdefghij"), 0, 5, "abcde", 5, 0);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", 0, 5);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", 1, 4);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", 5, 0);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", 9, -4);
+    test(S("abcdefghij"), 0, 5, "abcdefghij", 10, -5);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", 0, 5);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", 1, 4);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", 10, -5);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", 19, -14);
+    test(S("abcdefghij"), 0, 5, "abcdefghijklmnopqrst", 20, -15);
+    test(S("abcdefghij"), 0, 9, "", 0, 9);
+    test(S("abcdefghij"), 0, 9, "abcde", 0, 9);
+    test(S("abcdefghij"), 0, 9, "abcde", 1, 8);
+    test(S("abcdefghij"), 0, 9, "abcde", 2, 7);
+    test(S("abcdefghij"), 0, 9, "abcde", 4, 5);
+    test(S("abcdefghij"), 0, 9, "abcde", 5, 4);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", 0, 9);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", 1, 8);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", 5, 4);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", 9, 0);
+    test(S("abcdefghij"), 0, 9, "abcdefghij", 10, -1);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", 0, 9);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", 1, 8);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", 10, -1);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", 19, -10);
+    test(S("abcdefghij"), 0, 9, "abcdefghijklmnopqrst", 20, -11);
+    test(S("abcdefghij"), 0, 10, "", 0, 10);
+    test(S("abcdefghij"), 0, 10, "abcde", 0, 10);
+    test(S("abcdefghij"), 0, 10, "abcde", 1, 9);
+    test(S("abcdefghij"), 0, 10, "abcde", 2, 8);
+    test(S("abcdefghij"), 0, 10, "abcde", 4, 6);
+    test(S("abcdefghij"), 0, 10, "abcde", 5, 5);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 0, 10);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 1, 9);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 0, 10, "abcdefghij", 10, 0);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", 0, 10);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", 1, 9);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", 19, -9);
+    test(S("abcdefghij"), 0, 10, "abcdefghijklmnopqrst", 20, -10);
+    test(S("abcdefghij"), 0, 11, "", 0, 10);
+    test(S("abcdefghij"), 0, 11, "abcde", 0, 10);
+    test(S("abcdefghij"), 0, 11, "abcde", 1, 9);
+    test(S("abcdefghij"), 0, 11, "abcde", 2, 8);
+}
+
+void test5()
+{
+    test(S("abcdefghij"), 0, 11, "abcde", 4, 6);
+    test(S("abcdefghij"), 0, 11, "abcde", 5, 5);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 0, 10);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 1, 9);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 0, 11, "abcdefghij", 10, 0);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", 0, 10);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", 1, 9);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", 19, -9);
+    test(S("abcdefghij"), 0, 11, "abcdefghijklmnopqrst", 20, -10);
+    test(S("abcdefghij"), 1, 0, "", 0, 0);
+    test(S("abcdefghij"), 1, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 1, 0, "abcde", 1, -1);
+    test(S("abcdefghij"), 1, 0, "abcde", 2, -2);
+    test(S("abcdefghij"), 1, 0, "abcde", 4, -4);
+    test(S("abcdefghij"), 1, 0, "abcde", 5, -5);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 1, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 1, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 1, 1, "", 0, 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 0, 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 1, 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 2, 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 4, 1);
+    test(S("abcdefghij"), 1, 1, "abcde", 5, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 1, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 5, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghij", 10, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghij"), 1, 1, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghij"), 1, 4, "", 0, 4);
+    test(S("abcdefghij"), 1, 4, "abcde", 0, 4);
+    test(S("abcdefghij"), 1, 4, "abcde", 1, 1);
+    test(S("abcdefghij"), 1, 4, "abcde", 2, 1);
+    test(S("abcdefghij"), 1, 4, "abcde", 4, 1);
+    test(S("abcdefghij"), 1, 4, "abcde", 5, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 0, 4);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 1, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 5, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghij", 10, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 0, 4);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghij"), 1, 4, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghij"), 1, 8, "", 0, 8);
+    test(S("abcdefghij"), 1, 8, "abcde", 0, 8);
+    test(S("abcdefghij"), 1, 8, "abcde", 1, 1);
+    test(S("abcdefghij"), 1, 8, "abcde", 2, 1);
+    test(S("abcdefghij"), 1, 8, "abcde", 4, 1);
+    test(S("abcdefghij"), 1, 8, "abcde", 5, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 0, 8);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 1, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 5, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghij", 10, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 0, 8);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghij"), 1, 8, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghij"), 1, 9, "", 0, 9);
+    test(S("abcdefghij"), 1, 9, "abcde", 0, 9);
+    test(S("abcdefghij"), 1, 9, "abcde", 1, 1);
+    test(S("abcdefghij"), 1, 9, "abcde", 2, 1);
+    test(S("abcdefghij"), 1, 9, "abcde", 4, 1);
+    test(S("abcdefghij"), 1, 9, "abcde", 5, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 0, 9);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 1, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 5, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghij", 10, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 0, 9);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghij"), 1, 9, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghij"), 1, 10, "", 0, 9);
+    test(S("abcdefghij"), 1, 10, "abcde", 0, 9);
+    test(S("abcdefghij"), 1, 10, "abcde", 1, 1);
+    test(S("abcdefghij"), 1, 10, "abcde", 2, 1);
+    test(S("abcdefghij"), 1, 10, "abcde", 4, 1);
+    test(S("abcdefghij"), 1, 10, "abcde", 5, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 0, 9);
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 1, 1);
+}
+
+void test6()
+{
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 5, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 9, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghij", 10, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 0, 9);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghij"), 1, 10, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghij"), 5, 0, "", 0, 0);
+    test(S("abcdefghij"), 5, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 5, 0, "abcde", 1, -1);
+    test(S("abcdefghij"), 5, 0, "abcde", 2, -2);
+    test(S("abcdefghij"), 5, 0, "abcde", 4, -4);
+    test(S("abcdefghij"), 5, 0, "abcde", 5, -5);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 5, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 5, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 5, 1, "", 0, 1);
+    test(S("abcdefghij"), 5, 1, "abcde", 0, 1);
+    test(S("abcdefghij"), 5, 1, "abcde", 1, 5);
+    test(S("abcdefghij"), 5, 1, "abcde", 2, 5);
+    test(S("abcdefghij"), 5, 1, "abcde", 4, 5);
+    test(S("abcdefghij"), 5, 1, "abcde", 5, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 1, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 9, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghij", 10, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 1, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 10, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 19, 5);
+    test(S("abcdefghij"), 5, 1, "abcdefghijklmnopqrst", 20, 5);
+    test(S("abcdefghij"), 5, 2, "", 0, 2);
+    test(S("abcdefghij"), 5, 2, "abcde", 0, 2);
+    test(S("abcdefghij"), 5, 2, "abcde", 1, 5);
+    test(S("abcdefghij"), 5, 2, "abcde", 2, 5);
+    test(S("abcdefghij"), 5, 2, "abcde", 4, 5);
+    test(S("abcdefghij"), 5, 2, "abcde", 5, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 0, 2);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 1, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 9, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghij", 10, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 0, 2);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 1, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 10, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 19, 5);
+    test(S("abcdefghij"), 5, 2, "abcdefghijklmnopqrst", 20, 5);
+    test(S("abcdefghij"), 5, 4, "", 0, 4);
+    test(S("abcdefghij"), 5, 4, "abcde", 0, 4);
+    test(S("abcdefghij"), 5, 4, "abcde", 1, 5);
+    test(S("abcdefghij"), 5, 4, "abcde", 2, 5);
+    test(S("abcdefghij"), 5, 4, "abcde", 4, 5);
+    test(S("abcdefghij"), 5, 4, "abcde", 5, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 0, 4);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 1, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 9, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghij", 10, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 0, 4);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 1, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 10, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 19, 5);
+    test(S("abcdefghij"), 5, 4, "abcdefghijklmnopqrst", 20, 5);
+    test(S("abcdefghij"), 5, 5, "", 0, 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 0, 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 1, 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 2, 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 4, 5);
+    test(S("abcdefghij"), 5, 5, "abcde", 5, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 0, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 1, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 9, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghij", 10, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 0, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 1, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 10, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 19, 5);
+    test(S("abcdefghij"), 5, 5, "abcdefghijklmnopqrst", 20, 5);
+    test(S("abcdefghij"), 5, 6, "", 0, 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 0, 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 1, 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 2, 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 4, 5);
+    test(S("abcdefghij"), 5, 6, "abcde", 5, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 0, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 1, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 5, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 9, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghij", 10, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 0, 5);
+}
+
+void test7()
+{
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 1, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 10, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 19, 5);
+    test(S("abcdefghij"), 5, 6, "abcdefghijklmnopqrst", 20, 5);
+    test(S("abcdefghij"), 9, 0, "", 0, 0);
+    test(S("abcdefghij"), 9, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 9, 0, "abcde", 1, -1);
+    test(S("abcdefghij"), 9, 0, "abcde", 2, -2);
+    test(S("abcdefghij"), 9, 0, "abcde", 4, -4);
+    test(S("abcdefghij"), 9, 0, "abcde", 5, -5);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 9, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 9, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 9, 1, "", 0, 1);
+    test(S("abcdefghij"), 9, 1, "abcde", 0, 1);
+    test(S("abcdefghij"), 9, 1, "abcde", 1, 9);
+    test(S("abcdefghij"), 9, 1, "abcde", 2, 9);
+    test(S("abcdefghij"), 9, 1, "abcde", 4, 9);
+    test(S("abcdefghij"), 9, 1, "abcde", 5, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 1, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 5, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 9, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghij", 10, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 1, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 10, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 19, 9);
+    test(S("abcdefghij"), 9, 1, "abcdefghijklmnopqrst", 20, 9);
+    test(S("abcdefghij"), 9, 2, "", 0, 1);
+    test(S("abcdefghij"), 9, 2, "abcde", 0, 1);
+    test(S("abcdefghij"), 9, 2, "abcde", 1, 9);
+    test(S("abcdefghij"), 9, 2, "abcde", 2, 9);
+    test(S("abcdefghij"), 9, 2, "abcde", 4, 9);
+    test(S("abcdefghij"), 9, 2, "abcde", 5, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 0, 1);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 1, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 5, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 9, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghij", 10, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 1, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 10, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 19, 9);
+    test(S("abcdefghij"), 9, 2, "abcdefghijklmnopqrst", 20, 9);
+    test(S("abcdefghij"), 10, 0, "", 0, 0);
+    test(S("abcdefghij"), 10, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 10, 0, "abcde", 1, -1);
+    test(S("abcdefghij"), 10, 0, "abcde", 2, -2);
+    test(S("abcdefghij"), 10, 0, "abcde", 4, -4);
+    test(S("abcdefghij"), 10, 0, "abcde", 5, -5);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 10, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 10, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 10, 1, "", 0, 0);
+    test(S("abcdefghij"), 10, 1, "abcde", 0, 0);
+    test(S("abcdefghij"), 10, 1, "abcde", 1, -1);
+    test(S("abcdefghij"), 10, 1, "abcde", 2, -2);
+    test(S("abcdefghij"), 10, 1, "abcde", 4, -4);
+    test(S("abcdefghij"), 10, 1, "abcde", 5, -5);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", 1, -1);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", 5, -5);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", 9, -9);
+    test(S("abcdefghij"), 10, 1, "abcdefghij", 10, -10);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghij"), 10, 1, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghij"), 11, 0, "", 0, 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 0, 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 1, 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 2, 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 4, 0);
+    test(S("abcdefghij"), 11, 0, "abcde", 5, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 1, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 5, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 9, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghij", 10, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 19, 0);
+    test(S("abcdefghij"), 11, 0, "abcdefghijklmnopqrst", 20, 0);
+}
+
+void test8()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", 4, -3);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcde", 5, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", 5, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", 9, -8);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghij", 10, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", 10, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", 19, -18);
+    test(S("abcdefghijklmnopqrst"), 0, 1, "abcdefghijklmnopqrst", 20, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 1, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 2, 8);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 4, 6);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcde", 5, 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 1, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 5, 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghij", 10, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", 1, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", 19, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, "abcdefghijklmnopqrst", 20, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 2, 17);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 4, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcde", 5, 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 5, 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghij", 10, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", 10, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", 19, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, "abcdefghijklmnopqrst", 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 2, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 4, 16);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcde", 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 9, 11);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, "abcdefghijklmnopqrst", 20, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 2, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 4, 16);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcde", 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 9, 11);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, "abcdefghijklmnopqrst", 20, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", 2, -2);
+}
+
+void test9()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 1, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcde", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghij", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcde", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghij", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "", 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcde", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghij", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcde", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghij", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcde", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghij", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, "abcdefghijklmnopqrst", 20, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", 2, -2);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", 1, -1);
+}
+
+void test10()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 10, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcde", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, "abcdefghijklmnopqrst", 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "", 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcde", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, "abcdefghijklmnopqrst", 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcde", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, "abcdefghijklmnopqrst", 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcde", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, "abcdefghijklmnopqrst", 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcde", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghij", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, "abcdefghijklmnopqrst", 20, 10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", 2, -2);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", 0, 0);
+}
+
+void test11()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 19, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 2, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 4, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcde", 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 9, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghij", 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 19, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, "abcdefghijklmnopqrst", 20, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 2, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 4, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcde", 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 9, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghij", 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 19, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, "abcdefghijklmnopqrst", 20, 19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcde", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghij", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 1, "abcdefghijklmnopqrst", 20, -20);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcde", 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 9, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghij", 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 19, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, "abcdefghijklmnopqrst", 20, 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+    test9();
+    test10();
+    test11();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string.pass.cpp
new file mode 100644
index 0000000..9eeb2d5
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string.pass.cpp
@@ -0,0 +1,358 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(size_type pos1, size_type n1, const basic_string& str) const;
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, typename S::size_type pos1, typename S::size_type n1,
+     const S& str, int x)
+{
+    try
+    {
+        assert(sign(s.compare(pos1, n1, str)) == sign(x));
+        assert(pos1 <= s.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > s.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), 0, 0, S(""), 0);
+    test(S(""), 0, 0, S("abcde"), -5);
+    test(S(""), 0, 0, S("abcdefghij"), -10);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S(""), 0, 1, S(""), 0);
+    test(S(""), 0, 1, S("abcde"), -5);
+    test(S(""), 0, 1, S("abcdefghij"), -10);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), -20);
+    test(S(""), 1, 0, S(""), 0);
+    test(S(""), 1, 0, S("abcde"), 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0);
+    test(S("abcde"), 0, 0, S(""), 0);
+    test(S("abcde"), 0, 0, S("abcde"), -5);
+    test(S("abcde"), 0, 0, S("abcdefghij"), -10);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), 0, 1, S(""), 1);
+    test(S("abcde"), 0, 1, S("abcde"), -4);
+    test(S("abcde"), 0, 1, S("abcdefghij"), -9);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), -19);
+    test(S("abcde"), 0, 2, S(""), 2);
+    test(S("abcde"), 0, 2, S("abcde"), -3);
+    test(S("abcde"), 0, 2, S("abcdefghij"), -8);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), -18);
+    test(S("abcde"), 0, 4, S(""), 4);
+    test(S("abcde"), 0, 4, S("abcde"), -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), -6);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), -16);
+    test(S("abcde"), 0, 5, S(""), 5);
+    test(S("abcde"), 0, 5, S("abcde"), 0);
+    test(S("abcde"), 0, 5, S("abcdefghij"), -5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), -15);
+    test(S("abcde"), 0, 6, S(""), 5);
+    test(S("abcde"), 0, 6, S("abcde"), 0);
+    test(S("abcde"), 0, 6, S("abcdefghij"), -5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), -15);
+    test(S("abcde"), 1, 0, S(""), 0);
+    test(S("abcde"), 1, 0, S("abcde"), -5);
+    test(S("abcde"), 1, 0, S("abcdefghij"), -10);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), 1, 1, S(""), 1);
+    test(S("abcde"), 1, 1, S("abcde"), 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcde"), 1, 2, S(""), 2);
+    test(S("abcde"), 1, 2, S("abcde"), 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcde"), 1, 3, S(""), 3);
+    test(S("abcde"), 1, 3, S("abcde"), 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcde"), 1, 4, S(""), 4);
+    test(S("abcde"), 1, 4, S("abcde"), 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcde"), 1, 5, S(""), 4);
+    test(S("abcde"), 1, 5, S("abcde"), 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcde"), 2, 0, S(""), 0);
+    test(S("abcde"), 2, 0, S("abcde"), -5);
+    test(S("abcde"), 2, 0, S("abcdefghij"), -10);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), 2, 1, S(""), 1);
+    test(S("abcde"), 2, 1, S("abcde"), 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 2);
+    test(S("abcde"), 2, 2, S(""), 2);
+    test(S("abcde"), 2, 2, S("abcde"), 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 2);
+    test(S("abcde"), 2, 3, S(""), 3);
+    test(S("abcde"), 2, 3, S("abcde"), 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 2);
+    test(S("abcde"), 2, 4, S(""), 3);
+    test(S("abcde"), 2, 4, S("abcde"), 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 2);
+    test(S("abcde"), 4, 0, S(""), 0);
+    test(S("abcde"), 4, 0, S("abcde"), -5);
+    test(S("abcde"), 4, 0, S("abcdefghij"), -10);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), 4, 1, S(""), 1);
+    test(S("abcde"), 4, 1, S("abcde"), 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 4);
+    test(S("abcde"), 4, 2, S(""), 1);
+    test(S("abcde"), 4, 2, S("abcde"), 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 4);
+    test(S("abcde"), 5, 0, S(""), 0);
+    test(S("abcde"), 5, 0, S("abcde"), -5);
+    test(S("abcde"), 5, 0, S("abcdefghij"), -10);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), 5, 1, S(""), 0);
+    test(S("abcde"), 5, 1, S("abcde"), -5);
+    test(S("abcde"), 5, 1, S("abcdefghij"), -10);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), -20);
+}
+
+void test1()
+{
+    test(S("abcde"), 6, 0, S(""), 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0);
+    test(S("abcdefghij"), 0, 0, S(""), 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), -5);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 0, 1, S(""), 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), -4);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), -19);
+    test(S("abcdefghij"), 0, 5, S(""), 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), -15);
+    test(S("abcdefghij"), 0, 9, S(""), 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 4);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), -11);
+    test(S("abcdefghij"), 0, 10, S(""), 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), -10);
+    test(S("abcdefghij"), 0, 11, S(""), 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), -10);
+    test(S("abcdefghij"), 1, 0, S(""), 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), -5);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 1, 1, S(""), 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghij"), 1, 4, S(""), 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghij"), 1, 8, S(""), 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghij"), 1, 9, S(""), 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghij"), 1, 10, S(""), 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghij"), 5, 0, S(""), 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), -5);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 5, 1, S(""), 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 5);
+    test(S("abcdefghij"), 5, 2, S(""), 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 5);
+    test(S("abcdefghij"), 5, 4, S(""), 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 5);
+    test(S("abcdefghij"), 5, 5, S(""), 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 5);
+    test(S("abcdefghij"), 5, 6, S(""), 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 5);
+    test(S("abcdefghij"), 9, 0, S(""), 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), -5);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 9, 1, S(""), 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 9);
+    test(S("abcdefghij"), 9, 2, S(""), 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 9);
+    test(S("abcdefghij"), 10, 0, S(""), 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), -5);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 10, 1, S(""), 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), -5);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghij"), 11, 0, S(""), 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0);
+}
+
+void test2()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), -19);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), -20);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string_size_size.pass.cpp
new file mode 100644
index 0000000..8a6be68
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/size_size_string_size_size.pass.cpp
@@ -0,0 +1,5800 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(size_type pos1, size_type n1, const basic_string& str,
+//             size_type pos2, size_type n2) const;
+
+#include <string>
+#include <stdexcept>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, typename S::size_type pos1, typename S::size_type n1,
+     const S& str, typename S::size_type pos2, typename S::size_type n2, int x)
+{
+    try
+    {
+        assert(sign(s.compare(pos1, n1, str, pos2, n2)) == sign(x));
+        assert(pos1 <= s.size());
+        assert(pos2 <= str.size());
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos1 > s.size() || pos2 > str.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), 0, 0, S(""), 0, 0, 0);
+    test(S(""), 0, 0, S(""), 0, 1, 0);
+    test(S(""), 0, 0, S(""), 1, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 0, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 0, 1, -1);
+    test(S(""), 0, 0, S("abcde"), 0, 2, -2);
+    test(S(""), 0, 0, S("abcde"), 0, 4, -4);
+    test(S(""), 0, 0, S("abcde"), 0, 5, -5);
+    test(S(""), 0, 0, S("abcde"), 0, 6, -5);
+    test(S(""), 0, 0, S("abcde"), 1, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 1, 1, -1);
+    test(S(""), 0, 0, S("abcde"), 1, 2, -2);
+    test(S(""), 0, 0, S("abcde"), 1, 3, -3);
+    test(S(""), 0, 0, S("abcde"), 1, 4, -4);
+    test(S(""), 0, 0, S("abcde"), 1, 5, -4);
+    test(S(""), 0, 0, S("abcde"), 2, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 2, 1, -1);
+    test(S(""), 0, 0, S("abcde"), 2, 2, -2);
+    test(S(""), 0, 0, S("abcde"), 2, 3, -3);
+    test(S(""), 0, 0, S("abcde"), 2, 4, -3);
+    test(S(""), 0, 0, S("abcde"), 4, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 4, 1, -1);
+    test(S(""), 0, 0, S("abcde"), 4, 2, -1);
+    test(S(""), 0, 0, S("abcde"), 5, 0, 0);
+    test(S(""), 0, 0, S("abcde"), 5, 1, 0);
+    test(S(""), 0, 0, S("abcde"), 6, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 1, -1);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 5, -5);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 9, -9);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 10, -10);
+    test(S(""), 0, 0, S("abcdefghij"), 0, 11, -10);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 1, -1);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 4, -4);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 8, -8);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 9, -9);
+    test(S(""), 0, 0, S("abcdefghij"), 1, 10, -9);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 1, -1);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 2, -2);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 4, -4);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 5, -5);
+    test(S(""), 0, 0, S("abcdefghij"), 5, 6, -5);
+    test(S(""), 0, 0, S("abcdefghij"), 9, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 9, 1, -1);
+    test(S(""), 0, 0, S("abcdefghij"), 9, 2, -1);
+    test(S(""), 0, 0, S("abcdefghij"), 10, 0, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 10, 1, 0);
+    test(S(""), 0, 0, S("abcdefghij"), 11, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S(""), 0, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S(""), 0, 1, S(""), 0, 0, 0);
+    test(S(""), 0, 1, S(""), 0, 1, 0);
+    test(S(""), 0, 1, S(""), 1, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 0, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 0, 1, -1);
+    test(S(""), 0, 1, S("abcde"), 0, 2, -2);
+    test(S(""), 0, 1, S("abcde"), 0, 4, -4);
+    test(S(""), 0, 1, S("abcde"), 0, 5, -5);
+    test(S(""), 0, 1, S("abcde"), 0, 6, -5);
+    test(S(""), 0, 1, S("abcde"), 1, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 1, 1, -1);
+    test(S(""), 0, 1, S("abcde"), 1, 2, -2);
+    test(S(""), 0, 1, S("abcde"), 1, 3, -3);
+    test(S(""), 0, 1, S("abcde"), 1, 4, -4);
+    test(S(""), 0, 1, S("abcde"), 1, 5, -4);
+    test(S(""), 0, 1, S("abcde"), 2, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 2, 1, -1);
+    test(S(""), 0, 1, S("abcde"), 2, 2, -2);
+    test(S(""), 0, 1, S("abcde"), 2, 3, -3);
+    test(S(""), 0, 1, S("abcde"), 2, 4, -3);
+    test(S(""), 0, 1, S("abcde"), 4, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 4, 1, -1);
+    test(S(""), 0, 1, S("abcde"), 4, 2, -1);
+    test(S(""), 0, 1, S("abcde"), 5, 0, 0);
+    test(S(""), 0, 1, S("abcde"), 5, 1, 0);
+    test(S(""), 0, 1, S("abcde"), 6, 0, 0);
+}
+
+void test1()
+{
+    test(S(""), 0, 1, S("abcdefghij"), 0, 0, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 0, 1, -1);
+    test(S(""), 0, 1, S("abcdefghij"), 0, 5, -5);
+    test(S(""), 0, 1, S("abcdefghij"), 0, 9, -9);
+    test(S(""), 0, 1, S("abcdefghij"), 0, 10, -10);
+    test(S(""), 0, 1, S("abcdefghij"), 0, 11, -10);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 0, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 1, -1);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 4, -4);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 8, -8);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 9, -9);
+    test(S(""), 0, 1, S("abcdefghij"), 1, 10, -9);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 0, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 1, -1);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 2, -2);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 4, -4);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 5, -5);
+    test(S(""), 0, 1, S("abcdefghij"), 5, 6, -5);
+    test(S(""), 0, 1, S("abcdefghij"), 9, 0, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 9, 1, -1);
+    test(S(""), 0, 1, S("abcdefghij"), 9, 2, -1);
+    test(S(""), 0, 1, S("abcdefghij"), 10, 0, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 10, 1, 0);
+    test(S(""), 0, 1, S("abcdefghij"), 11, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S(""), 0, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S(""), 1, 0, S(""), 0, 0, 0);
+    test(S(""), 1, 0, S(""), 0, 1, 0);
+    test(S(""), 1, 0, S(""), 1, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 1, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 2, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 4, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 5, 0);
+    test(S(""), 1, 0, S("abcde"), 0, 6, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 1, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 2, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 3, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 4, 0);
+    test(S(""), 1, 0, S("abcde"), 1, 5, 0);
+    test(S(""), 1, 0, S("abcde"), 2, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 2, 1, 0);
+    test(S(""), 1, 0, S("abcde"), 2, 2, 0);
+    test(S(""), 1, 0, S("abcde"), 2, 3, 0);
+    test(S(""), 1, 0, S("abcde"), 2, 4, 0);
+    test(S(""), 1, 0, S("abcde"), 4, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 4, 1, 0);
+    test(S(""), 1, 0, S("abcde"), 4, 2, 0);
+    test(S(""), 1, 0, S("abcde"), 5, 0, 0);
+    test(S(""), 1, 0, S("abcde"), 5, 1, 0);
+    test(S(""), 1, 0, S("abcde"), 6, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 1, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 5, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 9, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 10, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 0, 11, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 1, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 4, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 8, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 9, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 1, 10, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 1, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 2, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 4, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 5, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 5, 6, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 9, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 9, 1, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 9, 2, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 10, 0, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 10, 1, 0);
+    test(S(""), 1, 0, S("abcdefghij"), 11, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 1, 0);
+}
+
+void test2()
+{
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 19, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 18, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 1, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 5, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 9, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S(""), 1, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 0, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 0, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 0, 0, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 0, 0, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 0, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 0, 0, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 0, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 0, 0, S("abcde"), 2, 4, -3);
+    test(S("abcde"), 0, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 0, 0, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 0, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 0, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 0, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 0, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 1, S(""), 0, 0, 1);
+    test(S("abcde"), 0, 1, S(""), 0, 1, 1);
+    test(S("abcde"), 0, 1, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 1, S("abcde"), 0, 0, 1);
+}
+
+void test3()
+{
+    test(S("abcde"), 0, 1, S("abcde"), 0, 1, 0);
+    test(S("abcde"), 0, 1, S("abcde"), 0, 2, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 0, 4, -3);
+    test(S("abcde"), 0, 1, S("abcde"), 0, 5, -4);
+    test(S("abcde"), 0, 1, S("abcde"), 0, 6, -4);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 0, 1);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 0, 1, S("abcde"), 2, 0, 1);
+    test(S("abcde"), 0, 1, S("abcde"), 2, 1, -2);
+    test(S("abcde"), 0, 1, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 1, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 0, 1, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 0, 1, S("abcde"), 4, 0, 1);
+    test(S("abcde"), 0, 1, S("abcde"), 4, 1, -4);
+    test(S("abcde"), 0, 1, S("abcde"), 4, 2, -4);
+    test(S("abcde"), 0, 1, S("abcde"), 5, 0, 1);
+    test(S("abcde"), 0, 1, S("abcde"), 5, 1, 1);
+    test(S("abcde"), 0, 1, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 1, 0);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 5, -4);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 9, -8);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 10, -9);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 0, 11, -9);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 8, -1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 9, -1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 1, 10, -1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 1, -5);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 2, -5);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 4, -5);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 9, 1, -9);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 9, 2, -9);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcde"), 0, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 10, -9);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 19, -18);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 20, -19);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 0, 21, -19);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcde"), 0, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 2, S(""), 0, 0, 2);
+    test(S("abcde"), 0, 2, S(""), 0, 1, 2);
+    test(S("abcde"), 0, 2, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 0, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 2, 0);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 4, -2);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 5, -3);
+    test(S("abcde"), 0, 2, S("abcde"), 0, 6, -3);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 0, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 0, 2, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 0, 2, S("abcde"), 2, 0, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 2, 1, -2);
+    test(S("abcde"), 0, 2, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 2, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 0, 2, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 0, 2, S("abcde"), 4, 0, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 4, 1, -4);
+    test(S("abcde"), 0, 2, S("abcde"), 4, 2, -4);
+    test(S("abcde"), 0, 2, S("abcde"), 5, 0, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 5, 1, 2);
+    test(S("abcde"), 0, 2, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 5, -3);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 9, -7);
+}
+
+void test4()
+{
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 10, -8);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 0, 11, -8);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 8, -1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 9, -1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 1, 10, -1);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 1, -5);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 2, -5);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 4, -5);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 9, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 9, 1, -9);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 9, 2, -9);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 10, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 10, 1, 2);
+    test(S("abcde"), 0, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 10, -8);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 19, -17);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 20, -18);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 0, 21, -18);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 19, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 20, 0, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 20, 1, 2);
+    test(S("abcde"), 0, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 4, S(""), 0, 0, 4);
+    test(S("abcde"), 0, 4, S(""), 0, 1, 4);
+    test(S("abcde"), 0, 4, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 0, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 1, 3);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 2, 2);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 4, 0);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 5, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 0, 6, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 0, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 0, 4, S("abcde"), 2, 0, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 2, 1, -2);
+    test(S("abcde"), 0, 4, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 4, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 0, 4, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 0, 4, S("abcde"), 4, 0, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 4, 1, -4);
+    test(S("abcde"), 0, 4, S("abcde"), 4, 2, -4);
+    test(S("abcde"), 0, 4, S("abcde"), 5, 0, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 5, 1, 4);
+    test(S("abcde"), 0, 4, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 1, 3);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 5, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 9, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 10, -6);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 0, 11, -6);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 8, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 9, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 1, 10, -1);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 1, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 2, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 4, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 9, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 9, 1, -9);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 9, 2, -9);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 10, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 10, 1, 4);
+    test(S("abcde"), 0, 4, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 1, 3);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 10, -6);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 19, -15);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 20, -16);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 0, 21, -16);
+}
+
+void test5()
+{
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 19, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 20, 0, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 20, 1, 4);
+    test(S("abcde"), 0, 4, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 5, S(""), 0, 0, 5);
+    test(S("abcde"), 0, 5, S(""), 0, 1, 5);
+    test(S("abcde"), 0, 5, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 0, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 1, 4);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 2, 3);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 5, 0);
+    test(S("abcde"), 0, 5, S("abcde"), 0, 6, 0);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 0, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 0, 5, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 0, 5, S("abcde"), 2, 0, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 2, 1, -2);
+    test(S("abcde"), 0, 5, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 5, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 0, 5, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 0, 5, S("abcde"), 4, 0, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 4, 1, -4);
+    test(S("abcde"), 0, 5, S("abcde"), 4, 2, -4);
+    test(S("abcde"), 0, 5, S("abcde"), 5, 0, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 5, 1, 5);
+    test(S("abcde"), 0, 5, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 1, 4);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 5, 0);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 9, -4);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 10, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 0, 11, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 8, -1);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 9, -1);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 1, 10, -1);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 1, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 2, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 4, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 9, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 9, 1, -9);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 9, 2, -9);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 10, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 10, 1, 5);
+    test(S("abcde"), 0, 5, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 1, 4);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 10, -5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 19, -14);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 20, -15);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 0, 21, -15);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcde"), 0, 5, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 0, 6, S(""), 0, 0, 5);
+    test(S("abcde"), 0, 6, S(""), 0, 1, 5);
+    test(S("abcde"), 0, 6, S(""), 1, 0, 0);
+    test(S("abcde"), 0, 6, S("abcde"), 0, 0, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 0, 1, 4);
+    test(S("abcde"), 0, 6, S("abcde"), 0, 2, 3);
+    test(S("abcde"), 0, 6, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 0, 6, S("abcde"), 0, 5, 0);
+}
+
+void test6()
+{
+    test(S("abcde"), 0, 6, S("abcde"), 0, 6, 0);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 0, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 0, 6, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 0, 6, S("abcde"), 2, 0, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 2, 1, -2);
+    test(S("abcde"), 0, 6, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 0, 6, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 0, 6, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 0, 6, S("abcde"), 4, 0, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 4, 1, -4);
+    test(S("abcde"), 0, 6, S("abcde"), 4, 2, -4);
+    test(S("abcde"), 0, 6, S("abcde"), 5, 0, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 5, 1, 5);
+    test(S("abcde"), 0, 6, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 1, 4);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 5, 0);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 9, -4);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 10, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 0, 11, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 8, -1);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 9, -1);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 1, 10, -1);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 1, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 2, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 4, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 9, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 9, 1, -9);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 9, 2, -9);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 10, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 10, 1, 5);
+    test(S("abcde"), 0, 6, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 1, 4);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 10, -5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 19, -14);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 20, -15);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 0, 21, -15);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcde"), 0, 6, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 1, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 1, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 1, 0, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 1, 0, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 1, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 0, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 1, 0, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 1, 0, S("abcde"), 2, 4, -3);
+    test(S("abcde"), 1, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 1, 0, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 1, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 1, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 1, -1);
+}
+
+void test7()
+{
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 1, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 1, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 1, S(""), 0, 0, 1);
+    test(S("abcde"), 1, 1, S(""), 0, 1, 1);
+    test(S("abcde"), 1, 1, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 0, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 2, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 5, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 0, 6, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 0, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 1, 0);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 2, -1);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 3, -2);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 4, -3);
+    test(S("abcde"), 1, 1, S("abcde"), 1, 5, -3);
+    test(S("abcde"), 1, 1, S("abcde"), 2, 0, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 1, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 1, 1, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 1, 1, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 1, 1, S("abcde"), 4, 0, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 4, 1, -3);
+    test(S("abcde"), 1, 1, S("abcde"), 4, 2, -3);
+    test(S("abcde"), 1, 1, S("abcde"), 5, 0, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 5, 1, 1);
+    test(S("abcde"), 1, 1, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 5, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 9, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 10, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 0, 11, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 1, 0);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 4, -3);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 8, -7);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 9, -8);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 1, 10, -8);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 1, -4);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 2, -4);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 5, -4);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 5, 6, -4);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 9, 1, -8);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 9, 2, -8);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcde"), 1, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 9, -8);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 18, -17);
+}
+
+void test8()
+{
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 19, -18);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 1, 20, -18);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcde"), 1, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 2, S(""), 0, 0, 2);
+    test(S("abcde"), 1, 2, S(""), 0, 1, 2);
+    test(S("abcde"), 1, 2, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 0, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 2, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 5, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 0, 6, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 0, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 1, 1);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 2, 0);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 3, -1);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 4, -2);
+    test(S("abcde"), 1, 2, S("abcde"), 1, 5, -2);
+    test(S("abcde"), 1, 2, S("abcde"), 2, 0, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 2, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 1, 2, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 1, 2, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 1, 2, S("abcde"), 4, 0, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 4, 1, -3);
+    test(S("abcde"), 1, 2, S("abcde"), 4, 2, -3);
+    test(S("abcde"), 1, 2, S("abcde"), 5, 0, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 5, 1, 2);
+    test(S("abcde"), 1, 2, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 5, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 9, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 10, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 0, 11, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 1, 1);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 4, -2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 8, -6);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 9, -7);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 1, 10, -7);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 1, -4);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 2, -4);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 5, -4);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 5, 6, -4);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 9, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 9, 1, -8);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 9, 2, -8);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 10, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 10, 1, 2);
+    test(S("abcde"), 1, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 1, 1);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 9, -7);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 18, -16);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 19, -17);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 1, 20, -17);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 19, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 20, 0, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 20, 1, 2);
+    test(S("abcde"), 1, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 3, S(""), 0, 0, 3);
+    test(S("abcde"), 1, 3, S(""), 0, 1, 3);
+    test(S("abcde"), 1, 3, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 0, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 2, 1);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 5, 1);
+    test(S("abcde"), 1, 3, S("abcde"), 0, 6, 1);
+    test(S("abcde"), 1, 3, S("abcde"), 1, 0, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 1, 1, 2);
+    test(S("abcde"), 1, 3, S("abcde"), 1, 2, 1);
+}
+
+void test9()
+{
+    test(S("abcde"), 1, 3, S("abcde"), 1, 3, 0);
+    test(S("abcde"), 1, 3, S("abcde"), 1, 4, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 1, 5, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 2, 0, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 1, 3, S("abcde"), 4, 0, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 4, 1, -3);
+    test(S("abcde"), 1, 3, S("abcde"), 4, 2, -3);
+    test(S("abcde"), 1, 3, S("abcde"), 5, 0, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 5, 1, 3);
+    test(S("abcde"), 1, 3, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 5, 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 9, 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 10, 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 0, 11, 1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 1, 2);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 4, -1);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 8, -5);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 9, -6);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 1, 10, -6);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 1, -4);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 2, -4);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 5, -4);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 5, 6, -4);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 9, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 9, 1, -8);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 9, 2, -8);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 10, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 10, 1, 3);
+    test(S("abcde"), 1, 3, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 1, 2);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 9, -6);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 18, -15);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 19, -16);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 1, 20, -16);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 19, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 20, 0, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 20, 1, 3);
+    test(S("abcde"), 1, 3, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 4, S(""), 0, 0, 4);
+    test(S("abcde"), 1, 4, S(""), 0, 1, 4);
+    test(S("abcde"), 1, 4, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 0, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 2, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 5, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 0, 6, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 0, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 1, 3);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 2, 2);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 4, 0);
+    test(S("abcde"), 1, 4, S("abcde"), 1, 5, 0);
+    test(S("abcde"), 1, 4, S("abcde"), 2, 0, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 4, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 1, 4, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 1, 4, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 1, 4, S("abcde"), 4, 0, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 4, 1, -3);
+    test(S("abcde"), 1, 4, S("abcde"), 4, 2, -3);
+    test(S("abcde"), 1, 4, S("abcde"), 5, 0, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 5, 1, 4);
+    test(S("abcde"), 1, 4, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 5, 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 9, 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 10, 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 0, 11, 1);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 1, 3);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 4, 0);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 8, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 9, -5);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 1, 10, -5);
+}
+
+void test10()
+{
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 1, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 2, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 5, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 5, 6, -4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 9, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 9, 1, -8);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 9, 2, -8);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 10, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 10, 1, 4);
+    test(S("abcde"), 1, 4, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 1, 3);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 9, -5);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 18, -14);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 19, -15);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 1, 20, -15);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 19, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 20, 0, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 20, 1, 4);
+    test(S("abcde"), 1, 4, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 1, 5, S(""), 0, 0, 4);
+    test(S("abcde"), 1, 5, S(""), 0, 1, 4);
+    test(S("abcde"), 1, 5, S(""), 1, 0, 0);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 0, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 1, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 2, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 4, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 5, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 0, 6, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 0, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 1, 3);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 2, 2);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 4, 0);
+    test(S("abcde"), 1, 5, S("abcde"), 1, 5, 0);
+    test(S("abcde"), 1, 5, S("abcde"), 2, 0, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 1, 5, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 1, 5, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 1, 5, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 1, 5, S("abcde"), 4, 0, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 4, 1, -3);
+    test(S("abcde"), 1, 5, S("abcde"), 4, 2, -3);
+    test(S("abcde"), 1, 5, S("abcde"), 5, 0, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 5, 1, 4);
+    test(S("abcde"), 1, 5, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 1, 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 5, 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 9, 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 10, 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 0, 11, 1);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 1, 3);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 4, 0);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 8, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 9, -5);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 1, 10, -5);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 1, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 2, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 5, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 5, 6, -4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 9, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 9, 1, -8);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 9, 2, -8);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 10, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 10, 1, 4);
+    test(S("abcde"), 1, 5, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 1, 3);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 9, -5);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 18, -14);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 19, -15);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 1, 20, -15);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 1, -9);
+}
+
+void test11()
+{
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 19, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 20, 0, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 20, 1, 4);
+    test(S("abcde"), 1, 5, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 2, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 2, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 2, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 2, 0, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 2, 0, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 2, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 2, 0, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 2, 0, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 2, 0, S("abcde"), 2, 4, -3);
+    test(S("abcde"), 2, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 2, 0, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 2, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 2, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 2, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 2, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 2, 1, S(""), 0, 0, 1);
+    test(S("abcde"), 2, 1, S(""), 0, 1, 1);
+    test(S("abcde"), 2, 1, S(""), 1, 0, 0);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 0, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 1, 2);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 2, 2);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 4, 2);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 5, 2);
+    test(S("abcde"), 2, 1, S("abcde"), 0, 6, 2);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 0, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 1, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 2, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 4, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 1, 5, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 2, 0, 1);
+}
+
+void test12()
+{
+    test(S("abcde"), 2, 1, S("abcde"), 2, 1, 0);
+    test(S("abcde"), 2, 1, S("abcde"), 2, 2, -1);
+    test(S("abcde"), 2, 1, S("abcde"), 2, 3, -2);
+    test(S("abcde"), 2, 1, S("abcde"), 2, 4, -2);
+    test(S("abcde"), 2, 1, S("abcde"), 4, 0, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 4, 1, -2);
+    test(S("abcde"), 2, 1, S("abcde"), 4, 2, -2);
+    test(S("abcde"), 2, 1, S("abcde"), 5, 0, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 5, 1, 1);
+    test(S("abcde"), 2, 1, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 1, 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 5, 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 9, 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 10, 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 0, 11, 2);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 1, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 4, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 8, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 9, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 1, 10, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 1, -3);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 2, -3);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 4, -3);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 5, -3);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 5, 6, -3);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 9, 1, -7);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 9, 2, -7);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcde"), 2, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 1, 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 10, 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 19, 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 20, 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 0, 21, 2);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 1, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 9, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 18, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 19, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 1, 20, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 1, -8);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 5, -8);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 9, -8);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 10, -8);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 10, 11, -8);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 19, 1, -17);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 19, 2, -17);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcde"), 2, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 2, 2, S(""), 0, 0, 2);
+    test(S("abcde"), 2, 2, S(""), 0, 1, 2);
+    test(S("abcde"), 2, 2, S(""), 1, 0, 0);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 0, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 1, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 2, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 4, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 5, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 0, 6, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 0, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 1, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 2, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 4, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 1, 5, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 2, 0, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 2, 1, 1);
+    test(S("abcde"), 2, 2, S("abcde"), 2, 2, 0);
+    test(S("abcde"), 2, 2, S("abcde"), 2, 3, -1);
+    test(S("abcde"), 2, 2, S("abcde"), 2, 4, -1);
+    test(S("abcde"), 2, 2, S("abcde"), 4, 0, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 4, 1, -2);
+    test(S("abcde"), 2, 2, S("abcde"), 4, 2, -2);
+    test(S("abcde"), 2, 2, S("abcde"), 5, 0, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 5, 1, 2);
+    test(S("abcde"), 2, 2, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 1, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 5, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 9, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 10, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 0, 11, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 1, 1);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 4, 1);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 8, 1);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 9, 1);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 1, 10, 1);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 1, -3);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 2, -3);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 4, -3);
+}
+
+void test13()
+{
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 5, -3);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 5, 6, -3);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 9, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 9, 1, -7);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 9, 2, -7);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 10, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 10, 1, 2);
+    test(S("abcde"), 2, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 1, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 10, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 19, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 20, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 0, 21, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 1, 1);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 9, 1);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 18, 1);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 19, 1);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 1, 20, 1);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 1, -8);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 5, -8);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 9, -8);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 10, -8);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 10, 11, -8);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 19, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 19, 1, -17);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 19, 2, -17);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 20, 0, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 20, 1, 2);
+    test(S("abcde"), 2, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 2, 3, S(""), 0, 0, 3);
+    test(S("abcde"), 2, 3, S(""), 0, 1, 3);
+    test(S("abcde"), 2, 3, S(""), 1, 0, 0);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 0, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 1, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 2, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 4, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 5, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 0, 6, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 0, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 1, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 2, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 4, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 1, 5, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 2, 0, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 2, 1, 2);
+    test(S("abcde"), 2, 3, S("abcde"), 2, 2, 1);
+    test(S("abcde"), 2, 3, S("abcde"), 2, 3, 0);
+    test(S("abcde"), 2, 3, S("abcde"), 2, 4, 0);
+    test(S("abcde"), 2, 3, S("abcde"), 4, 0, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 4, 1, -2);
+    test(S("abcde"), 2, 3, S("abcde"), 4, 2, -2);
+    test(S("abcde"), 2, 3, S("abcde"), 5, 0, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 5, 1, 3);
+    test(S("abcde"), 2, 3, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 1, 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 5, 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 9, 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 10, 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 0, 11, 2);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 1, 1);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 4, 1);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 8, 1);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 9, 1);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 1, 10, 1);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 1, -3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 2, -3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 4, -3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 5, -3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 5, 6, -3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 9, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 9, 1, -7);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 9, 2, -7);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 10, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 10, 1, 3);
+    test(S("abcde"), 2, 3, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 1, 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 10, 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 19, 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 20, 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 0, 21, 2);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 1, 1);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 9, 1);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 18, 1);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 19, 1);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 1, 20, 1);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 1, -8);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 5, -8);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 9, -8);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 10, -8);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 10, 11, -8);
+}
+
+void test14()
+{
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 19, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 19, 1, -17);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 19, 2, -17);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 20, 0, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 20, 1, 3);
+    test(S("abcde"), 2, 3, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 2, 4, S(""), 0, 0, 3);
+    test(S("abcde"), 2, 4, S(""), 0, 1, 3);
+    test(S("abcde"), 2, 4, S(""), 1, 0, 0);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 0, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 1, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 2, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 4, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 5, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 0, 6, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 0, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 1, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 2, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 3, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 4, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 1, 5, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 2, 0, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 2, 1, 2);
+    test(S("abcde"), 2, 4, S("abcde"), 2, 2, 1);
+    test(S("abcde"), 2, 4, S("abcde"), 2, 3, 0);
+    test(S("abcde"), 2, 4, S("abcde"), 2, 4, 0);
+    test(S("abcde"), 2, 4, S("abcde"), 4, 0, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 4, 1, -2);
+    test(S("abcde"), 2, 4, S("abcde"), 4, 2, -2);
+    test(S("abcde"), 2, 4, S("abcde"), 5, 0, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 5, 1, 3);
+    test(S("abcde"), 2, 4, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 1, 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 5, 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 9, 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 10, 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 0, 11, 2);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 1, 1);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 4, 1);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 8, 1);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 9, 1);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 1, 10, 1);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 1, -3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 2, -3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 4, -3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 5, -3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 5, 6, -3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 9, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 9, 1, -7);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 9, 2, -7);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 10, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 10, 1, 3);
+    test(S("abcde"), 2, 4, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 1, 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 10, 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 19, 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 20, 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 0, 21, 2);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 1, 1);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 9, 1);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 18, 1);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 19, 1);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 1, 20, 1);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 1, -8);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 5, -8);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 9, -8);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 10, -8);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 10, 11, -8);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 19, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 19, 1, -17);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 19, 2, -17);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 20, 0, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 20, 1, 3);
+    test(S("abcde"), 2, 4, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 4, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 4, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 4, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 4, 0, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 4, 0, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 4, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 4, 0, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 4, 0, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 4, 0, S("abcde"), 2, 4, -3);
+}
+
+void test15()
+{
+    test(S("abcde"), 4, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 4, 0, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 4, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 4, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 4, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 4, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 4, 1, S(""), 0, 0, 1);
+    test(S("abcde"), 4, 1, S(""), 0, 1, 1);
+    test(S("abcde"), 4, 1, S(""), 1, 0, 0);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 0, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 1, 4);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 2, 4);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 4, 4);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 5, 4);
+    test(S("abcde"), 4, 1, S("abcde"), 0, 6, 4);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 0, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 1, 3);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 2, 3);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 3, 3);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 4, 3);
+    test(S("abcde"), 4, 1, S("abcde"), 1, 5, 3);
+    test(S("abcde"), 4, 1, S("abcde"), 2, 0, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 2, 1, 2);
+    test(S("abcde"), 4, 1, S("abcde"), 2, 2, 2);
+    test(S("abcde"), 4, 1, S("abcde"), 2, 3, 2);
+    test(S("abcde"), 4, 1, S("abcde"), 2, 4, 2);
+    test(S("abcde"), 4, 1, S("abcde"), 4, 0, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 4, 1, 0);
+    test(S("abcde"), 4, 1, S("abcde"), 4, 2, 0);
+    test(S("abcde"), 4, 1, S("abcde"), 5, 0, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 5, 1, 1);
+    test(S("abcde"), 4, 1, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 1, 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 5, 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 9, 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 10, 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 0, 11, 4);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 1, 3);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 4, 3);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 8, 3);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 9, 3);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 1, 10, 3);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 2, -1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 4, -1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 5, -1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 5, 6, -1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 9, 1, -5);
+}
+
+void test16()
+{
+    test(S("abcde"), 4, 1, S("abcdefghij"), 9, 2, -5);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcde"), 4, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 1, 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 10, 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 19, 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 20, 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 0, 21, 4);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 1, 3);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 9, 3);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 18, 3);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 19, 3);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 1, 20, 3);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 1, -6);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 5, -6);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 9, -6);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 10, -6);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 10, 11, -6);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 19, 1, -15);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 19, 2, -15);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcde"), 4, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 4, 2, S(""), 0, 0, 1);
+    test(S("abcde"), 4, 2, S(""), 0, 1, 1);
+    test(S("abcde"), 4, 2, S(""), 1, 0, 0);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 0, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 1, 4);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 2, 4);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 4, 4);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 5, 4);
+    test(S("abcde"), 4, 2, S("abcde"), 0, 6, 4);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 0, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 1, 3);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 2, 3);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 3, 3);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 4, 3);
+    test(S("abcde"), 4, 2, S("abcde"), 1, 5, 3);
+    test(S("abcde"), 4, 2, S("abcde"), 2, 0, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 2, 1, 2);
+    test(S("abcde"), 4, 2, S("abcde"), 2, 2, 2);
+    test(S("abcde"), 4, 2, S("abcde"), 2, 3, 2);
+    test(S("abcde"), 4, 2, S("abcde"), 2, 4, 2);
+    test(S("abcde"), 4, 2, S("abcde"), 4, 0, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 4, 1, 0);
+    test(S("abcde"), 4, 2, S("abcde"), 4, 2, 0);
+    test(S("abcde"), 4, 2, S("abcde"), 5, 0, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 5, 1, 1);
+    test(S("abcde"), 4, 2, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 1, 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 5, 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 9, 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 10, 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 0, 11, 4);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 1, 3);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 4, 3);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 8, 3);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 9, 3);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 1, 10, 3);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 2, -1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 4, -1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 5, -1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 5, 6, -1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 9, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 9, 1, -5);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 9, 2, -5);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 10, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 10, 1, 1);
+    test(S("abcde"), 4, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 1, 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 10, 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 19, 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 20, 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 0, 21, 4);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 1, 3);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 9, 3);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 18, 3);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 19, 3);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 1, 20, 3);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 1, -6);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 5, -6);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 9, -6);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 10, -6);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 10, 11, -6);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 19, 1, -15);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 19, 2, -15);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 20, 0, 1);
+}
+
+void test17()
+{
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcde"), 4, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 5, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 5, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 5, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 5, 0, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 5, 0, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 5, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 5, 0, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 5, 0, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 5, 0, S("abcde"), 2, 4, -3);
+    test(S("abcde"), 5, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 5, 0, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 5, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 5, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 5, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 5, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 5, 1, S(""), 0, 0, 0);
+    test(S("abcde"), 5, 1, S(""), 0, 1, 0);
+    test(S("abcde"), 5, 1, S(""), 1, 0, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 1, -1);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 2, -2);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 4, -4);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 5, -5);
+    test(S("abcde"), 5, 1, S("abcde"), 0, 6, -5);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 1, -1);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 2, -2);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 3, -3);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 4, -4);
+    test(S("abcde"), 5, 1, S("abcde"), 1, 5, -4);
+    test(S("abcde"), 5, 1, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 2, 1, -1);
+    test(S("abcde"), 5, 1, S("abcde"), 2, 2, -2);
+    test(S("abcde"), 5, 1, S("abcde"), 2, 3, -3);
+    test(S("abcde"), 5, 1, S("abcde"), 2, 4, -3);
+    test(S("abcde"), 5, 1, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 4, 1, -1);
+    test(S("abcde"), 5, 1, S("abcde"), 4, 2, -1);
+    test(S("abcde"), 5, 1, S("abcde"), 5, 0, 0);
+}
+
+void test18()
+{
+    test(S("abcde"), 5, 1, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 5, 1, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 5, -5);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 9, -9);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 10, -10);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 0, 11, -10);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 4, -4);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 8, -8);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 9, -9);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 1, 10, -9);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 2, -2);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 9, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 9, 2, -1);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 5, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 5, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcde"), 6, 0, S(""), 0, 0, 0);
+    test(S("abcde"), 6, 0, S(""), 0, 1, 0);
+    test(S("abcde"), 6, 0, S(""), 1, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 1, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 2, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 4, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 5, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 0, 6, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 1, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 2, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 3, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 4, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 1, 5, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 2, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 2, 1, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 2, 2, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 2, 3, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 2, 4, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 4, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 4, 1, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 4, 2, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 5, 0, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 5, 1, 0);
+    test(S("abcde"), 6, 0, S("abcde"), 6, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 5, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 9, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 10, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 0, 11, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 4, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 8, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 9, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 1, 10, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 2, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 4, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 5, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 5, 6, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 9, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 9, 2, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghij"), 11, 0, 0);
+}
+
+void test19()
+{
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 19, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 18, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 5, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 9, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcde"), 6, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 0, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 0, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 0, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 0, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 1, S(""), 0, 0, 1);
+    test(S("abcdefghij"), 0, 1, S(""), 0, 1, 1);
+}
+
+void test20()
+{
+    test(S("abcdefghij"), 0, 1, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 1, 0);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 2, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 4, -3);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 5, -4);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 0, 6, -4);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 3, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 1, 5, -1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 2, 1, -2);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 2, 3, -2);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 2, 4, -2);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 4, 1, -4);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 4, 2, -4);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghij"), 0, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 1, 0);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 5, -4);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 9, -8);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 10, -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 0, 11, -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 10, -9);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 19, -18);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 20, -19);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 0, 21, -19);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghij"), 0, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 5, S(""), 0, 0, 5);
+    test(S("abcdefghij"), 0, 5, S(""), 0, 1, 5);
+    test(S("abcdefghij"), 0, 5, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 1, 4);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 2, 3);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 5, 0);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 0, 6, 0);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 3, -1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 1, 5, -1);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 2, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 2, 1, -2);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 2, 3, -2);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 2, 4, -2);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 4, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 4, 1, -4);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 4, 2, -4);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 5, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 5, 1, 5);
+    test(S("abcdefghij"), 0, 5, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 1, 4);
+}
+
+void test21()
+{
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 5, 0);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 9, -4);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 10, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 0, 11, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 9, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 10, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 10, 1, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 1, 4);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 10, -5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 19, -14);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 20, -15);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 0, 21, -15);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcdefghij"), 0, 5, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 9, S(""), 0, 0, 9);
+    test(S("abcdefghij"), 0, 9, S(""), 0, 1, 9);
+    test(S("abcdefghij"), 0, 9, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 1, 8);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 2, 7);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 5, 4);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 0, 6, 4);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 3, -1);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 1, 5, -1);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 2, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 2, 1, -2);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 2, 3, -2);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 2, 4, -2);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 4, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 4, 1, -4);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 4, 2, -4);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 5, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 5, 1, 9);
+    test(S("abcdefghij"), 0, 9, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 1, 8);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 5, 4);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 9, 0);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 10, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 0, 11, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 9, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 10, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 10, 1, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 1, 8);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 10, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 19, -10);
+}
+
+void test22()
+{
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 20, -11);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 0, 21, -11);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 19, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 20, 0, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 20, 1, 9);
+    test(S("abcdefghij"), 0, 9, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 10, S(""), 0, 0, 10);
+    test(S("abcdefghij"), 0, 10, S(""), 0, 1, 10);
+    test(S("abcdefghij"), 0, 10, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 2, 8);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 4, 6);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 3, -1);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 1, 5, -1);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 2, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 2, 1, -2);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 2, 3, -2);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 2, 4, -2);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 4, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 4, 1, -4);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 4, 2, -4);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 5, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 5, 1, 10);
+    test(S("abcdefghij"), 0, 10, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 10, 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 0, 11, 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 9, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 10, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 10, 1, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 19, -9);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 20, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 0, 21, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 19, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 20, 0, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 20, 1, 10);
+    test(S("abcdefghij"), 0, 10, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 0, 11, S(""), 0, 0, 10);
+    test(S("abcdefghij"), 0, 11, S(""), 0, 1, 10);
+    test(S("abcdefghij"), 0, 11, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 2, 8);
+}
+
+void test23()
+{
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 4, 6);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 3, -1);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 1, 5, -1);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 2, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 2, 1, -2);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 2, 3, -2);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 2, 4, -2);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 4, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 4, 1, -4);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 4, 2, -4);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 5, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 5, 1, 10);
+    test(S("abcdefghij"), 0, 11, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 10, 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 0, 11, 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 9, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 10, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 10, 1, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 1, 9);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 19, -9);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 20, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 0, 21, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 19, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 20, 0, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 20, 1, 10);
+    test(S("abcdefghij"), 0, 11, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 1, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 1, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 1, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 0, 11, -10);
+}
+
+void test24()
+{
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 1, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 1, S(""), 0, 0, 1);
+    test(S("abcdefghij"), 1, 1, S(""), 0, 1, 1);
+    test(S("abcdefghij"), 1, 1, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 2, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 0, 6, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 1, 0);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 2, -1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 3, -2);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 4, -3);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 1, 5, -3);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 2, 2, -1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 2, 3, -1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 2, 4, -1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 4, 1, -3);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 4, 2, -3);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 1, 0);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 4, -3);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 8, -7);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 9, -8);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 1, 10, -8);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 1, 0);
+}
+
+void test25()
+{
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 9, -8);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 18, -17);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 19, -18);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 1, 20, -18);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghij"), 1, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 4, S(""), 0, 0, 4);
+    test(S("abcdefghij"), 1, 4, S(""), 0, 1, 4);
+    test(S("abcdefghij"), 1, 4, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 2, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 0, 6, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 1, 3);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 2, 2);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 3, 1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 4, 0);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 1, 5, 0);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 2, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 2, 2, -1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 2, 3, -1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 2, 4, -1);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 4, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 4, 1, -3);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 4, 2, -3);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 5, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 5, 1, 4);
+    test(S("abcdefghij"), 1, 4, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 1, 3);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 4, 0);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 8, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 9, -5);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 1, 10, -5);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 9, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 10, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 10, 1, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 1, 3);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 9, -5);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 18, -14);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 19, -15);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 1, 20, -15);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 19, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 20, 0, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 20, 1, 4);
+    test(S("abcdefghij"), 1, 4, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 8, S(""), 0, 0, 8);
+    test(S("abcdefghij"), 1, 8, S(""), 0, 1, 8);
+    test(S("abcdefghij"), 1, 8, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 2, 1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 0, 6, 1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 0, 8);
+}
+
+void test26()
+{
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 1, 7);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 2, 6);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 3, 5);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 4, 4);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 2, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 2, 2, -1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 2, 3, -1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 2, 4, -1);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 4, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 4, 1, -3);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 4, 2, -3);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 5, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 5, 1, 8);
+    test(S("abcdefghij"), 1, 8, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 1, 7);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 8, 0);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 9, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 10, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 10, 1, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 1, 7);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 18, -10);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 19, -11);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 1, 20, -11);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 19, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 20, 0, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 20, 1, 8);
+    test(S("abcdefghij"), 1, 8, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 9, S(""), 0, 0, 9);
+    test(S("abcdefghij"), 1, 9, S(""), 0, 1, 9);
+    test(S("abcdefghij"), 1, 9, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 2, 1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 0, 6, 1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 2, 7);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 3, 6);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 4, 5);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 1, 5, 5);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 2, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 2, 2, -1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 2, 3, -1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 2, 4, -1);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 4, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 4, 1, -3);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 4, 2, -3);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 5, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 5, 1, 9);
+    test(S("abcdefghij"), 1, 9, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 4, 5);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 8, 1);
+}
+
+void test27()
+{
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 9, 0);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 1, 10, 0);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 9, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 10, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 10, 1, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 18, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 19, -10);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 1, 20, -10);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 19, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 20, 0, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 20, 1, 9);
+    test(S("abcdefghij"), 1, 9, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 1, 10, S(""), 0, 0, 9);
+    test(S("abcdefghij"), 1, 10, S(""), 0, 1, 9);
+    test(S("abcdefghij"), 1, 10, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 2, 1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 4, 1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 0, 6, 1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 2, 7);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 3, 6);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 4, 5);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 1, 5, 5);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 2, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 2, 2, -1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 2, 3, -1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 2, 4, -1);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 4, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 4, 1, -3);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 4, 2, -3);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 5, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 5, 1, 9);
+    test(S("abcdefghij"), 1, 10, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 4, 5);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 8, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 9, 0);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 1, 10, 0);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 9, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 10, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 10, 1, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 1, 8);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 18, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 19, -10);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 1, 20, -10);
+}
+
+void test28()
+{
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 19, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 20, 0, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 20, 1, 9);
+    test(S("abcdefghij"), 1, 10, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 5, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 5, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 5, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 5, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 1, S(""), 0, 0, 1);
+    test(S("abcdefghij"), 5, 1, S(""), 0, 1, 1);
+    test(S("abcdefghij"), 5, 1, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 2, 5);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 2, 4);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 3, 4);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 4, 4);
+}
+
+void test29()
+{
+    test(S("abcdefghij"), 5, 1, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 2, 1, 3);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 2, 2, 3);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 2, 3, 3);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 2, 4, 3);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 4, 1, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 4, 2, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghij"), 5, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 9, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 0, 11, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 8, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 1, 10, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 1, 0);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 2, -1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 4, -3);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 9, 1, -4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 9, 2, -4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 19, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 20, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 0, 21, 5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 18, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 19, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 1, 20, 4);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 1, -5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 9, -5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 19, 1, -14);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 19, 2, -14);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghij"), 5, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 2, S(""), 0, 0, 2);
+    test(S("abcdefghij"), 5, 2, S(""), 0, 1, 2);
+    test(S("abcdefghij"), 5, 2, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 2, 5);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 2, 4);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 3, 4);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 2, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 2, 1, 3);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 2, 2, 3);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 2, 3, 3);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 2, 4, 3);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 4, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 4, 1, 1);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 4, 2, 1);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 5, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 5, 1, 2);
+    test(S("abcdefghij"), 5, 2, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 9, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 0, 11, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 8, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 1, 10, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 1, 1);
+}
+
+void test30()
+{
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 2, 0);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 4, -2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 5, -3);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 5, 6, -3);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 9, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 9, 1, -4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 9, 2, -4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 10, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 10, 1, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 19, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 20, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 0, 21, 5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 18, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 19, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 1, 20, 4);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 1, -5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 9, -5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 19, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 19, 1, -14);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 19, 2, -14);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 20, 0, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 20, 1, 2);
+    test(S("abcdefghij"), 5, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 4, S(""), 0, 0, 4);
+    test(S("abcdefghij"), 5, 4, S(""), 0, 1, 4);
+    test(S("abcdefghij"), 5, 4, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 2, 5);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 2, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 3, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 2, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 2, 1, 3);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 2, 2, 3);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 2, 3, 3);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 2, 4, 3);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 4, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 4, 1, 1);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 4, 2, 1);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 5, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 5, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 9, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 0, 11, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 8, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 1, 10, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 1, 3);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 2, 2);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 4, 0);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 5, -1);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 5, 6, -1);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 9, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 9, 1, -4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 9, 2, -4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 10, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 10, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 19, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 20, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 0, 21, 5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 18, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 19, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 1, 20, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 1, -5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 9, -5);
+}
+
+void test31()
+{
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 19, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 19, 1, -14);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 19, 2, -14);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 20, 0, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 20, 1, 4);
+    test(S("abcdefghij"), 5, 4, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 5, S(""), 0, 0, 5);
+    test(S("abcdefghij"), 5, 5, S(""), 0, 1, 5);
+    test(S("abcdefghij"), 5, 5, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 2, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 2, 4);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 3, 4);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 2, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 2, 1, 3);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 2, 2, 3);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 2, 3, 3);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 2, 4, 3);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 4, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 4, 1, 1);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 4, 2, 1);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 5, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 5, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 9, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 0, 11, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 8, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 1, 10, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 1, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 2, 3);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 4, 1);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 5, 0);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 5, 6, 0);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 9, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 9, 1, -4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 9, 2, -4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 10, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 10, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 19, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 20, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 0, 21, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 18, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 19, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 1, 20, 4);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 1, -5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 9, -5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 19, 1, -14);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 19, 2, -14);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcdefghij"), 5, 5, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 5, 6, S(""), 0, 0, 5);
+    test(S("abcdefghij"), 5, 6, S(""), 0, 1, 5);
+    test(S("abcdefghij"), 5, 6, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 2, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 4, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 0, 6, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 2, 4);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 3, 4);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 1, 5, 4);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 2, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 2, 1, 3);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 2, 2, 3);
+}
+
+void test32()
+{
+    test(S("abcdefghij"), 5, 6, S("abcde"), 2, 3, 3);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 2, 4, 3);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 4, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 4, 1, 1);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 4, 2, 1);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 5, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 5, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 9, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 0, 11, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 4, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 8, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 1, 10, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 1, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 2, 3);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 4, 1);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 5, 0);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 5, 6, 0);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 9, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 9, 1, -4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 9, 2, -4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 10, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 10, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 10, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 19, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 20, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 0, 21, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 1, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 9, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 18, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 19, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 1, 20, 4);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 1, -5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 9, -5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 19, 1, -14);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 19, 2, -14);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcdefghij"), 5, 6, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 9, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 9, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 9, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 9, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 5, 6, -5);
+}
+
+void test33()
+{
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 9, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 9, 1, S(""), 0, 0, 1);
+    test(S("abcdefghij"), 9, 1, S(""), 0, 1, 1);
+    test(S("abcdefghij"), 9, 1, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 2, 9);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 4, 9);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 5, 9);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 0, 6, 9);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 2, 8);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 3, 8);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 4, 8);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 1, 5, 8);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 2, 1, 7);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 2, 2, 7);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 2, 3, 7);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 2, 4, 7);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 4, 1, 5);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 4, 2, 5);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghij"), 9, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 5, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 9, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 10, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 0, 11, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 4, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 8, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 9, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 1, 10, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 1, 4);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 2, 4);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 4, 4);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 5, 4);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 5, 6, 4);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 9, 1, 0);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 9, 2, 0);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 10, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 19, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 20, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 0, 21, 9);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 9, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 18, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 19, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 1, 20, 8);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 5, -1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 9, -1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 10, -1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 10, 11, -1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 19, 1, -10);
+}
+
+void test34()
+{
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 19, 2, -10);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghij"), 9, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 9, 2, S(""), 0, 0, 1);
+    test(S("abcdefghij"), 9, 2, S(""), 0, 1, 1);
+    test(S("abcdefghij"), 9, 2, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 2, 9);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 4, 9);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 5, 9);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 0, 6, 9);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 2, 8);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 3, 8);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 4, 8);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 1, 5, 8);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 2, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 2, 1, 7);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 2, 2, 7);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 2, 3, 7);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 2, 4, 7);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 4, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 4, 1, 5);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 4, 2, 5);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 5, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 5, 1, 1);
+    test(S("abcdefghij"), 9, 2, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 5, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 9, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 10, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 0, 11, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 4, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 8, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 9, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 1, 10, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 1, 4);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 2, 4);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 4, 4);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 5, 4);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 5, 6, 4);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 9, 1, 0);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 9, 2, 0);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 1, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 10, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 19, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 20, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 0, 21, 9);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 1, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 9, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 18, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 19, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 1, 20, 8);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 5, -1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 9, -1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 10, -1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 10, 11, -1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 19, 1, -10);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 19, 2, -10);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghij"), 9, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 10, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 10, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 10, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 4, 1, -1);
+}
+
+void test35()
+{
+    test(S("abcdefghij"), 10, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 10, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 10, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 10, 1, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 10, 1, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 10, 1, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 2, -2);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 4, -4);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 5, -5);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 0, 6, -5);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 2, -2);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 3, -3);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 4, -4);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 1, 5, -4);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 2, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 2, 2, -2);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 2, 3, -3);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 2, 4, -3);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 4, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 4, 2, -1);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 10, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 10, 0, 0);
+}
+
+void test36()
+{
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 10, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghij"), 11, 0, S(""), 0, 0, 0);
+    test(S("abcdefghij"), 11, 0, S(""), 0, 1, 0);
+    test(S("abcdefghij"), 11, 0, S(""), 1, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 4, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 5, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 0, 6, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 3, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 4, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 1, 5, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 2, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 2, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 2, 3, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 2, 4, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 4, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 4, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 5, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 9, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 10, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 0, 11, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 4, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 8, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 9, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 1, 10, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 4, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 5, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 5, 6, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 9, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 9, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 19, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 18, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 5, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 9, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghij"), 11, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+}
+
+void test37()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 0, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 1, 5, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 2, 1, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 2, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 2, 4, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 4, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 4, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcde"), 6, 0, 0);
+}
+
+void test38()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 9, -8);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 0, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 19, -18);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 0, 21, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 4, 6);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 0, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 1, 5, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 2, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 2, 1, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 2, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 2, 4, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 4, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 4, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 4, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 5, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 0, 11, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 9, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 10, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 1, 9);
+}
+
+void test39()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 19, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 20, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 0, 21, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 19, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 20, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 20, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 10, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 2, 17);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 4, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 5, 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 0, 6, 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 1, 5, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 2, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 2, 1, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 2, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 2, 4, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 4, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 4, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 4, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 5, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 5, 14);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 0, 11, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 9, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 10, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 19, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 0, 21, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 19, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 20, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 20, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 19, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 0, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 0, 20);
+}
+
+void test40()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 2, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 4, 16);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 0, 6, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 1, 5, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 2, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 2, 1, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 2, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 2, 4, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 4, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 4, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 4, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 5, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 5, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 9, 11);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 9, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 10, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 10, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 19, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 20, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 20, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 20, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 0, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 2, 18);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 4, 16);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 0, 6, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 1, 5, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 2, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 2, 1, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 2, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 2, 4, -2);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 4, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 4, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 4, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 5, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 5, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 9, 11);
+}
+
+void test41()
+{
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 8, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 1, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 1, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 2, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 4, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 9, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 9, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 9, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 10, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 10, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 9, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 18, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 1, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 5, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 9, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 19, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 19, 1, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 19, 2, -19);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 20, 0, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 20, 1, 20);
+    test(S("abcdefghijklmnopqrst"), 0, 21, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+}
+
+void test42()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 0, 6, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 3, -2);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 1, 5, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 2, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 2, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 2, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 4, 1, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 4, 2, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 8, -7);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 9, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 1, 10, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 9, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 18, -17);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 19, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 1, 20, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 0, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 5, 1);
+}
+
+void test43()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 0, 6, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 2, 7);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 3, 6);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 1, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 2, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 2, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 2, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 2, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 4, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 4, 1, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 4, 2, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 5, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 5, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 8, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 1, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 9, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 10, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 18, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 19, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 1, 20, -10);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 19, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 20, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 20, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 9, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 0, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 0, 6, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 1, 17);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 2, 16);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 3, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 4, 14);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 1, 5, 14);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 2, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 2, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 2, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 2, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 4, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 4, 1, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 4, 2, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 5, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 5, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 1, 17);
+}
+
+void test44()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 4, 14);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 8, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 1, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 9, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 10, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 10, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 1, 17);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 18, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 19, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 1, 20, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 19, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 20, 0, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 20, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 18, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 0, 6, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 2, 17);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 3, 16);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 4, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 1, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 2, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 2, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 2, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 2, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 4, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 4, 1, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 4, 2, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 5, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 4, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 8, 11);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 1, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 9, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 10, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 18, 1);
+}
+
+void test45()
+{
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 19, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 20, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 20, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 19, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 4, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 0, 6, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 2, 17);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 3, 16);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 4, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 1, 5, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 2, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 2, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 2, 3, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 2, 4, -1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 4, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 4, 1, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 4, 2, -3);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 5, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 5, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 0, 11, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 4, 15);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 8, 11);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 1, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 1, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 2, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 5, 6, -4);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 9, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 9, 1, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 9, 2, -8);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 10, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 10, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 19, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 20, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 0, 21, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 18, 1);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 5, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 19, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 19, 1, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 19, 2, -18);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 20, 0, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 20, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 1, 20, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 2, -2);
+}
+
+void test46()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 0, 6, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 2, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 3, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 1, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 2, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 2, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 2, 3, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 2, 4, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 4, 1, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 4, 2, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 8, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 1, 10, 9);
+}
+
+void test47()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 2, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 5, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 9, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 9, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 0, 21, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 18, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 19, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 1, 20, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 9, -8);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 10, 11, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 19, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 19, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 0, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 0, 6, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 2, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 3, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 1, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 2, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 2, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 2, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 2, 3, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 2, 4, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 4, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 4, 1, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 4, 2, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 5, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 8, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 1, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 2, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 5, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 9, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 9, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 9, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 10, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 10, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 0, 21, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 18, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 19, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 1, 20, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 1, 4);
+}
+
+void test48()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 9, -4);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 10, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 10, 11, -5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 19, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 19, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 19, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 20, 0, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 20, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 0, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 0, 6, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 2, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 3, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 1, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 2, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 2, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 2, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 2, 3, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 2, 4, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 4, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 4, 1, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 4, 2, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 5, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 5, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 8, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 1, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 2, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 5, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 9, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 9, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 9, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 10, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 0, 21, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 18, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 19, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 1, 20, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 5, 4);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 10, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 10, 11, -1);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 19, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 19, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 19, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 20, 0, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 20, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 0, 6, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 2, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 3, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 1, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 2, 0, 10);
+}
+
+void test49()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 2, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 2, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 2, 3, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 2, 4, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 4, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 4, 1, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 4, 2, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 5, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 8, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 1, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 2, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 4, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 5, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 9, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 9, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 9, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 10, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 0, 21, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 18, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 19, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 1, 20, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 19, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 19, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 19, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 20, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 20, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 4, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 0, 6, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 2, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 3, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 1, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 2, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 2, 1, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 2, 2, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 2, 3, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 2, 4, 8);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 4, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 4, 1, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 4, 2, 6);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 5, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 5, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 9, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 0, 11, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 4, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 8, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 1, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 1, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 2, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 4, 5);
+}
+
+void test50()
+{
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 5, 6, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 9, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 9, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 9, 2, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 10, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 10, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 19, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 20, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 0, 21, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 18, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 19, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 1, 20, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 5, 5);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 9, 1);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 19, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 19, 1, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 19, 2, -9);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 20, 0, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 20, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 10, 11, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+}
+
+void test51()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 2, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 4, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 0, 6, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 2, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 3, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 4, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 1, 5, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 2, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 2, 1, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 2, 2, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 2, 3, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 2, 4, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 4, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 4, 1, 15);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 4, 2, 15);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 5, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 9, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 0, 11, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 4, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 8, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 9, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 1, 10, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 1, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 2, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 4, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 5, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 5, 6, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 9, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 9, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 19, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 20, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 0, 21, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 9, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 18, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 19, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 1, 20, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 10, 11, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 0, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 2, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 4, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 0, 6, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 2, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 3, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 4, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 1, 5, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 2, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 2, 1, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 2, 2, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 2, 3, 17);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 2, 4, 17);
+}
+
+void test52()
+{
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 4, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 4, 1, 15);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 4, 2, 15);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 5, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 5, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 9, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 0, 11, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 4, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 8, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 9, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 1, 10, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 1, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 2, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 4, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 5, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 5, 6, 14);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 9, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 9, 1, 10);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 9, 2, 10);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 10, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 1, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 10, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 19, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 20, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 0, 21, 19);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 1, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 9, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 18, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 19, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 1, 20, 18);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 1, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 5, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 9, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 10, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 10, 11, 9);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 19, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 20, 0, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 20, 1, 1);
+    test(S("abcdefghijklmnopqrst"), 19, 2, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 9, 1, -1);
+}
+
+void test53()
+{
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 0, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 1, 5, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 2, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 2, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 2, 3, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 2, 4, -3);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 4, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 4, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 0, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 8, -8);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 1, 10, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 2, -2);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 4, -4);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 5, 6, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 9, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 9, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 20, -20);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 0, 21, -20);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 18, -18);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 19, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 1, 20, -19);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 5, -5);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 9, -9);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 10, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 10, 11, -10);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 19, 1, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 19, 2, -1);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 20, 0, 0);
+}
+
+void test54()
+{
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 20, 1, S("abcdefghijklmnopqrst"), 21, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S(""), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 0, 6, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 3, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 1, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 2, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 2, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 2, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 2, 3, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 2, 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 4, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 4, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 4, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcde"), 6, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 0, 11, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 8, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 1, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 4, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 5, 6, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 9, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 9, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 9, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghij"), 11, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 19, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 0, 21, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 18, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 19, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 1, 20, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 5, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 9, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 10, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 10, 11, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 19, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 19, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 19, 2, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 20, 0, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 20, 1, 0);
+    test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+    test4();
+    test5();
+    test6();
+    test7();
+    test8();
+    test9();
+    test10();
+    test11();
+    test12();
+    test13();
+    test14();
+    test15();
+    test16();
+    test17();
+    test18();
+    test19();
+    test20();
+    test21();
+    test22();
+    test23();
+    test24();
+    test25();
+    test26();
+    test27();
+    test28();
+    test29();
+    test30();
+    test31();
+    test32();
+    test33();
+    test34();
+    test35();
+    test36();
+    test37();
+    test38();
+    test39();
+    test40();
+    test41();
+    test42();
+    test43();
+    test44();
+    test45();
+    test46();
+    test47();
+    test48();
+    test49();
+    test50();
+    test51();
+    test52();
+    test53();
+    test54();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::compare/string.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::compare/string.pass.cpp
new file mode 100644
index 0000000..de7b106
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::compare/string.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// int compare(const basic_string& str) const
+
+#include <string>
+#include <cassert>
+
+int sign(int x)
+{
+    if (x == 0)
+        return 0;
+    if (x < 0)
+        return -1;
+    return 1;
+}
+
+template <class S>
+void
+test(const S& s, const S& str, int x)
+{
+    assert(sign(s.compare(str)) == sign(x));
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), S(""), 0);
+    test(S(""), S("abcde"), -5);
+    test(S(""), S("abcdefghij"), -10);
+    test(S(""), S("abcdefghijklmnopqrst"), -20);
+    test(S("abcde"), S(""), 5);
+    test(S("abcde"), S("abcde"), 0);
+    test(S("abcde"), S("abcdefghij"), -5);
+    test(S("abcde"), S("abcdefghijklmnopqrst"), -15);
+    test(S("abcdefghij"), S(""), 10);
+    test(S("abcdefghij"), S("abcde"), 5);
+    test(S("abcdefghij"), S("abcdefghij"), 0);
+    test(S("abcdefghij"), S("abcdefghijklmnopqrst"), -10);
+    test(S("abcdefghijklmnopqrst"), S(""), 20);
+    test(S("abcdefghijklmnopqrst"), S("abcde"), 15);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghij"), 10);
+    test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), 0);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/char_size.pass.cpp
new file mode 100644
index 0000000..bc82706
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_not_of(charT c, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_first_not_of(c, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.find_first_not_of(c) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'q', 0, S::npos);
+    test(S(""), 'q', 1, S::npos);
+    test(S("kitcj"), 'q', 0, 0);
+    test(S("qkamf"), 'q', 1, 1);
+    test(S("nhmko"), 'q', 2, 2);
+    test(S("tpsaf"), 'q', 4, 4);
+    test(S("lahfb"), 'q', 5, S::npos);
+    test(S("irkhs"), 'q', 6, S::npos);
+    test(S("gmfhdaipsr"), 'q', 0, 0);
+    test(S("kantesmpgj"), 'q', 1, 1);
+    test(S("odaftiegpm"), 'q', 5, 5);
+    test(S("oknlrstdpi"), 'q', 9, 9);
+    test(S("eolhfgpjqk"), 'q', 10, S::npos);
+    test(S("pcdrofikas"), 'q', 11, S::npos);
+    test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
+    test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
+    test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
+    test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
+    test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
+    test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
+
+    test(S(""), 'q', S::npos);
+    test(S("csope"), 'q', 0);
+    test(S("gfsmthlkon"), 'q', 0);
+    test(S("laenfsbridchgotmkqpj"), 'q', 0);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size.pass.cpp
new file mode 100644
index 0000000..3549ea3
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size.pass.cpp
@@ -0,0 +1,146 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_not_of(const charT* s, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_first_not_of(str, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.find_first_not_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, S::npos);
+    test(S(""), "laenf", 0, S::npos);
+    test(S(""), "pqlnkmbdjo", 0, S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", 0, S::npos);
+    test(S(""), "", 1, S::npos);
+    test(S(""), "bjaht", 1, S::npos);
+    test(S(""), "hjlcmgpket", 1, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 1, S::npos);
+    test(S("fodgq"), "", 0, 0);
+    test(S("qanej"), "dfkap", 0, 0);
+    test(S("clbao"), "ihqrfebgad", 0, 0);
+    test(S("mekdn"), "ngtjfcalbseiqrphmkdo", 0, S::npos);
+    test(S("srdfq"), "", 1, 1);
+    test(S("oemth"), "ikcrq", 1, 1);
+    test(S("cdaih"), "dmajblfhsg", 1, 3);
+    test(S("qohtk"), "oqftjhdmkgsblacenirp", 1, S::npos);
+    test(S("cshmd"), "", 2, 2);
+    test(S("lhcdo"), "oebqi", 2, 2);
+    test(S("qnsoh"), "kojhpmbsfe", 2, S::npos);
+    test(S("pkrof"), "acbsjqogpltdkhinfrem", 2, S::npos);
+    test(S("fmtsp"), "", 4, 4);
+    test(S("khbpm"), "aobjd", 4, 4);
+    test(S("pbsji"), "pcbahntsje", 4, 4);
+    test(S("mprdj"), "fhepcrntkoagbmldqijs", 4, S::npos);
+    test(S("eqmpa"), "", 5, S::npos);
+    test(S("omigs"), "kocgb", 5, S::npos);
+    test(S("onmje"), "fbslrjiqkm", 5, S::npos);
+    test(S("oqmrj"), "jeidpcmalhfnqbgtrsko", 5, S::npos);
+    test(S("schfa"), "", 6, S::npos);
+    test(S("igdsc"), "qngpd", 6, S::npos);
+    test(S("brqgo"), "rodhqklgmb", 6, S::npos);
+    test(S("tnrph"), "thdjgafrlbkoiqcspmne", 6, S::npos);
+    test(S("hcjitbfapl"), "", 0, 0);
+    test(S("daiprenocl"), "ashjd", 0, 2);
+    test(S("litpcfdghe"), "mgojkldsqh", 0, 1);
+    test(S("aidjksrolc"), "imqnaghkfrdtlopbjesc", 0, S::npos);
+    test(S("qpghtfbaji"), "", 1, 1);
+    test(S("gfshlcmdjr"), "nadkh", 1, 1);
+    test(S("nkodajteqp"), "ofdrqmkebl", 1, 4);
+    test(S("gbmetiprqd"), "bdfjqgatlksriohemnpc", 1, S::npos);
+    test(S("crnklpmegd"), "", 5, 5);
+    test(S("jsbtafedoc"), "prqgn", 5, 5);
+    test(S("qnmodrtkeb"), "pejafmnokr", 5, 6);
+    test(S("cpebqsfmnj"), "odnqkgijrhabfmcestlp", 5, S::npos);
+    test(S("lmofqdhpki"), "", 9, 9);
+    test(S("hnefkqimca"), "rtjpa", 9, S::npos);
+    test(S("drtasbgmfp"), "ktsrmnqagd", 9, 9);
+    test(S("lsaijeqhtr"), "rtdhgcisbnmoaqkfpjle", 9, S::npos);
+    test(S("elgofjmbrq"), "", 10, S::npos);
+    test(S("mjqdgalkpc"), "dplqa", 10, S::npos);
+    test(S("kthqnfcerm"), "dkacjoptns", 10, S::npos);
+    test(S("dfsjhanorc"), "hqfimtrgnbekpdcsjalo", 10, S::npos);
+    test(S("eqsgalomhb"), "", 11, S::npos);
+    test(S("akiteljmoh"), "lofbc", 11, S::npos);
+    test(S("hlbdfreqjo"), "astoegbfpn", 11, S::npos);
+    test(S("taqobhlerg"), "pdgreqomsncafklhtibj", 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), "", 0, 0);
+    test(S("aemtbrgcklhndjisfpoq"), "lbtqd", 0, 0);
+    test(S("pnracgfkjdiholtbqsem"), "tboimldpjh", 0, 1);
+    test(S("dicfltehbsgrmojnpkaq"), "slcerthdaiqjfnobgkpm", 0, S::npos);
+    test(S("jlnkraeodhcspfgbqitm"), "", 1, 1);
+    test(S("lhosrngtmfjikbqpcade"), "aqibs", 1, 1);
+    test(S("rbtaqjhgkneisldpmfoc"), "gtfblmqinc", 1, 3);
+    test(S("gpifsqlrdkbonjtmheca"), "mkqpbtdalgniorhfescj", 1, S::npos);
+    test(S("hdpkobnsalmcfijregtq"), "", 10, 10);
+    test(S("jtlshdgqaiprkbcoenfm"), "pblas", 10, 11);
+    test(S("fkdrbqltsgmcoiphneaj"), "arosdhcfme", 10, 13);
+    test(S("crsplifgtqedjohnabmk"), "blkhjeogicatqfnpdmsr", 10, S::npos);
+    test(S("niptglfbosehkamrdqcj"), "", 19, 19);
+    test(S("copqdhstbingamjfkler"), "djkqc", 19, 19);
+    test(S("mrtaefilpdsgocnhqbjk"), "lgokshjtpb", 19, S::npos);
+    test(S("kojatdhlcmigpbfrqnes"), "bqjhtkfepimcnsgrlado", 19, S::npos);
+    test(S("eaintpchlqsbdgrkjofm"), "", 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), "nocfa", 20, S::npos);
+    test(S("spocfaktqdbiejlhngmr"), "bgtajmiedc", 20, S::npos);
+    test(S("rphmlekgfscndtaobiqj"), "lsckfnqgdahejiopbtmr", 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), "", 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), "gfsrt", 21, S::npos);
+    test(S("latkmisecnorjbfhqpdg"), "pfsocbhjtm", 21, S::npos);
+    test(S("lecfratdjkhnsmqpoigb"), "tpflmdnoicjgkberhqsa", 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), "", S::npos);
+    test(S(""), "laenf", S::npos);
+    test(S(""), "pqlnkmbdjo", S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", S::npos);
+    test(S("nhmko"), "", 0);
+    test(S("lahfb"), "irkhs", 0);
+    test(S("gmfhd"), "kantesmpgj", 2);
+    test(S("odaft"), "oknlrstdpiqmjbaghcfe", S::npos);
+    test(S("eolhfgpjqk"), "", 0);
+    test(S("nbatdlmekr"), "bnrpe", 2);
+    test(S("jdmciepkaq"), "jtdaefblso", 2);
+    test(S("hkbgspoflt"), "oselktgbcapndfjihrmq", S::npos);
+    test(S("gprdcokbnjhlsfmtieqa"), "", 0);
+    test(S("qjghlnftcaismkropdeb"), "bjaht", 0);
+    test(S("pnalfrdtkqcmojiesbhg"), "hjlcmgpket", 1);
+    test(S("pniotcfrhqsmgdkjbael"), "htaobedqikfplcgjsmrn", S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..edbe611
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type n, typename S::size_type x)
+{
+    assert(s.find_first_not_of(str, pos, n) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, S::npos);
+    test(S(""), "irkhs", 0, 0, S::npos);
+    test(S(""), "kante", 0, 1, S::npos);
+    test(S(""), "oknlr", 0, 2, S::npos);
+    test(S(""), "pcdro", 0, 4, S::npos);
+    test(S(""), "bnrpe", 0, 5, S::npos);
+    test(S(""), "jtdaefblso", 0, 0, S::npos);
+    test(S(""), "oselktgbca", 0, 1, S::npos);
+    test(S(""), "eqgaplhckj", 0, 5, S::npos);
+    test(S(""), "bjahtcmnlp", 0, 9, S::npos);
+    test(S(""), "hjlcmgpket", 0, 10, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 0, 0, S::npos);
+    test(S(""), "hpqiarojkcdlsgnmfetb", 0, 1, S::npos);
+    test(S(""), "dfkaprhjloqetcsimnbg", 0, 10, S::npos);
+    test(S(""), "ihqrfebgadntlpmjksoc", 0, 19, S::npos);
+    test(S(""), "ngtjfcalbseiqrphmkdo", 0, 20, S::npos);
+    test(S(""), "", 1, 0, S::npos);
+    test(S(""), "lbtqd", 1, 0, S::npos);
+    test(S(""), "tboim", 1, 1, S::npos);
+    test(S(""), "slcer", 1, 2, S::npos);
+    test(S(""), "cbjfs", 1, 4, S::npos);
+    test(S(""), "aqibs", 1, 5, S::npos);
+    test(S(""), "gtfblmqinc", 1, 0, S::npos);
+    test(S(""), "mkqpbtdalg", 1, 1, S::npos);
+    test(S(""), "kphatlimcd", 1, 5, S::npos);
+    test(S(""), "pblasqogic", 1, 9, S::npos);
+    test(S(""), "arosdhcfme", 1, 10, S::npos);
+    test(S(""), "blkhjeogicatqfnpdmsr", 1, 0, S::npos);
+    test(S(""), "bmhineprjcoadgstflqk", 1, 1, S::npos);
+    test(S(""), "djkqcmetslnghpbarfoi", 1, 10, S::npos);
+    test(S(""), "lgokshjtpbemarcdqnfi", 1, 19, S::npos);
+    test(S(""), "bqjhtkfepimcnsgrlado", 1, 20, S::npos);
+    test(S("eaint"), "", 0, 0, 0);
+    test(S("binja"), "gfsrt", 0, 0, 0);
+    test(S("latkm"), "pfsoc", 0, 1, 0);
+    test(S("lecfr"), "tpflm", 0, 2, 0);
+    test(S("eqkst"), "sgkec", 0, 4, 1);
+    test(S("cdafr"), "romds", 0, 5, 0);
+    test(S("prbhe"), "qhjistlgmr", 0, 0, 0);
+    test(S("lbisk"), "pedfirsglo", 0, 1, 0);
+    test(S("hrlpd"), "aqcoslgrmk", 0, 5, 0);
+    test(S("ehmja"), "dabckmepqj", 0, 9, 1);
+    test(S("mhqgd"), "pqscrjthli", 0, 10, 0);
+    test(S("tgklq"), "kfphdcsjqmobliagtren", 0, 0, 0);
+    test(S("bocjs"), "rokpefncljibsdhqtagm", 0, 1, 0);
+    test(S("grbsd"), "afionmkphlebtcjqsgrd", 0, 10, 0);
+    test(S("ofjqr"), "aenmqplidhkofrjbctsg", 0, 19, S::npos);
+    test(S("btlfi"), "osjmbtcadhiklegrpqnf", 0, 20, S::npos);
+    test(S("clrgb"), "", 1, 0, 1);
+    test(S("tjmek"), "osmia", 1, 0, 1);
+    test(S("bgstp"), "ckonl", 1, 1, 1);
+    test(S("hstrk"), "ilcaj", 1, 2, 1);
+    test(S("kmspj"), "lasiq", 1, 4, 1);
+    test(S("tjboh"), "kfqmr", 1, 5, 1);
+    test(S("ilbcj"), "klnitfaobg", 1, 0, 1);
+    test(S("jkngf"), "gjhmdlqikp", 1, 1, 1);
+    test(S("gfcql"), "skbgtahqej", 1, 5, 1);
+    test(S("dqtlg"), "bjsdgtlpkf", 1, 9, 1);
+    test(S("bthpg"), "bjgfmnlkio", 1, 10, 1);
+    test(S("dgsnq"), "lbhepotfsjdqigcnamkr", 1, 0, 1);
+    test(S("rmfhp"), "tebangckmpsrqdlfojhi", 1, 1, 1);
+    test(S("jfdam"), "joflqbdkhtegimscpanr", 1, 10, 3);
+    test(S("edapb"), "adpmcohetfbsrjinlqkg", 1, 19, S::npos);
+    test(S("brfsm"), "iacldqjpfnogbsrhmetk", 1, 20, S::npos);
+    test(S("ndrhl"), "", 2, 0, 2);
+    test(S("mrecp"), "otkgb", 2, 0, 2);
+    test(S("qlasf"), "cqsjl", 2, 1, 2);
+    test(S("smaqd"), "dpifl", 2, 2, 2);
+    test(S("hjeni"), "oapht", 2, 4, 2);
+    test(S("ocmfj"), "cifts", 2, 5, 2);
+    test(S("hmftq"), "nmsckbgalo", 2, 0, 2);
+    test(S("fklad"), "tpksqhamle", 2, 1, 2);
+    test(S("dirnm"), "tpdrchmkji", 2, 5, 3);
+    test(S("hrgdc"), "ijagfkblst", 2, 9, 3);
+    test(S("ifakg"), "kpocsignjb", 2, 10, 2);
+    test(S("ebrgd"), "pecqtkjsnbdrialgmohf", 2, 0, 2);
+    test(S("rcjml"), "aiortphfcmkjebgsndql", 2, 1, 2);
+    test(S("peqmt"), "sdbkeamglhipojqftrcn", 2, 10, 2);
+    test(S("frehn"), "ljqncehgmfktroapidbs", 2, 19, S::npos);
+    test(S("tqolf"), "rtcfodilamkbenjghqps", 2, 20, S::npos);
+    test(S("cjgao"), "", 4, 0, 4);
+    test(S("kjplq"), "mabns", 4, 0, 4);
+    test(S("herni"), "bdnrp", 4, 1, 4);
+    test(S("tadrb"), "scidp", 4, 2, 4);
+    test(S("pkfeo"), "agbjl", 4, 4, 4);
+    test(S("hoser"), "jfmpr", 4, 5, S::npos);
+    test(S("kgrsp"), "rbpefghsmj", 4, 0, 4);
+    test(S("pgejb"), "apsfntdoqc", 4, 1, 4);
+    test(S("thlnq"), "ndkjeisgcl", 4, 5, 4);
+    test(S("nbmit"), "rnfpqatdeo", 4, 9, S::npos);
+    test(S("jgmib"), "bntjlqrfik", 4, 10, S::npos);
+    test(S("ncrfj"), "kcrtmpolnaqejghsfdbi", 4, 0, 4);
+    test(S("ncsik"), "lobheanpkmqidsrtcfgj", 4, 1, 4);
+    test(S("sgbfh"), "athdkljcnreqbgpmisof", 4, 10, S::npos);
+    test(S("dktbn"), "qkdmjialrscpbhefgont", 4, 19, S::npos);
+    test(S("fthqm"), "dmasojntqleribkgfchp", 4, 20, S::npos);
+    test(S("klopi"), "", 5, 0, S::npos);
+    test(S("dajhn"), "psthd", 5, 0, S::npos);
+    test(S("jbgno"), "rpmjd", 5, 1, S::npos);
+    test(S("hkjae"), "dfsmk", 5, 2, S::npos);
+}
+
+void test1()
+{
+    test(S("gbhqo"), "skqne", 5, 4, S::npos);
+    test(S("ktdor"), "kipnf", 5, 5, S::npos);
+    test(S("ldprn"), "hmrnqdgifl", 5, 0, S::npos);
+    test(S("egmjk"), "fsmjcdairn", 5, 1, S::npos);
+    test(S("armql"), "pcdgltbrfj", 5, 5, S::npos);
+    test(S("cdhjo"), "aekfctpirg", 5, 9, S::npos);
+    test(S("jcons"), "ledihrsgpf", 5, 10, S::npos);
+    test(S("cbrkp"), "mqcklahsbtirgopefndj", 5, 0, S::npos);
+    test(S("fhgna"), "kmlthaoqgecrnpdbjfis", 5, 1, S::npos);
+    test(S("ejfcd"), "sfhbamcdptojlkrenqgi", 5, 10, S::npos);
+    test(S("kqjhe"), "pbniofmcedrkhlstgaqj", 5, 19, S::npos);
+    test(S("pbdjl"), "mongjratcskbhqiepfdl", 5, 20, S::npos);
+    test(S("gajqn"), "", 6, 0, S::npos);
+    test(S("stedk"), "hrnat", 6, 0, S::npos);
+    test(S("tjkaf"), "gsqdt", 6, 1, S::npos);
+    test(S("dthpe"), "bspkd", 6, 2, S::npos);
+    test(S("klhde"), "ohcmb", 6, 4, S::npos);
+    test(S("bhlki"), "heatr", 6, 5, S::npos);
+    test(S("lqmoh"), "pmblckedfn", 6, 0, S::npos);
+    test(S("mtqin"), "aceqmsrbik", 6, 1, S::npos);
+    test(S("dpqbr"), "lmbtdehjrn", 6, 5, S::npos);
+    test(S("kdhmo"), "teqmcrlgib", 6, 9, S::npos);
+    test(S("jblqp"), "njolbmspac", 6, 10, S::npos);
+    test(S("qmjgl"), "pofnhidklamecrbqjgst", 6, 0, S::npos);
+    test(S("rothp"), "jbhckmtgrqnosafedpli", 6, 1, S::npos);
+    test(S("ghknq"), "dobntpmqklicsahgjerf", 6, 10, S::npos);
+    test(S("eopfi"), "tpdshainjkbfoemlrgcq", 6, 19, S::npos);
+    test(S("dsnmg"), "oldpfgeakrnitscbjmqh", 6, 20, S::npos);
+    test(S("jnkrfhotgl"), "", 0, 0, 0);
+    test(S("dltjfngbko"), "rqegt", 0, 0, 0);
+    test(S("bmjlpkiqde"), "dashm", 0, 1, 0);
+    test(S("skrflobnqm"), "jqirk", 0, 2, 0);
+    test(S("jkpldtshrm"), "rckeg", 0, 4, 0);
+    test(S("ghasdbnjqo"), "jscie", 0, 5, 0);
+    test(S("igrkhpbqjt"), "efsphndliq", 0, 0, 0);
+    test(S("ikthdgcamf"), "gdicosleja", 0, 1, 0);
+    test(S("pcofgeniam"), "qcpjibosfl", 0, 5, 2);
+    test(S("rlfjgesqhc"), "lrhmefnjcq", 0, 9, 4);
+    test(S("itphbqsker"), "dtablcrseo", 0, 10, 0);
+    test(S("skjafcirqm"), "apckjsftedbhgomrnilq", 0, 0, 0);
+    test(S("tcqomarsfd"), "pcbrgflehjtiadnsokqm", 0, 1, 0);
+    test(S("rocfeldqpk"), "nsiadegjklhobrmtqcpf", 0, 10, 0);
+    test(S("cfpegndlkt"), "cpmajdqnolikhgsbretf", 0, 19, 1);
+    test(S("fqbtnkeasj"), "jcflkntmgiqrphdosaeb", 0, 20, S::npos);
+    test(S("shbcqnmoar"), "", 1, 0, 1);
+    test(S("bdoshlmfin"), "ontrs", 1, 0, 1);
+    test(S("khfrebnsgq"), "pfkna", 1, 1, 1);
+    test(S("getcrsaoji"), "ekosa", 1, 2, 2);
+    test(S("fjiknedcpq"), "anqhk", 1, 4, 1);
+    test(S("tkejgnafrm"), "jekca", 1, 5, 4);
+    test(S("jnakolqrde"), "ikemsjgacf", 1, 0, 1);
+    test(S("lcjptsmgbe"), "arolgsjkhm", 1, 1, 1);
+    test(S("itfsmcjorl"), "oftkbldhre", 1, 5, 3);
+    test(S("omchkfrjea"), "gbkqdoeftl", 1, 9, 1);
+    test(S("cigfqkated"), "sqcflrgtim", 1, 10, 5);
+    test(S("tscenjikml"), "fmhbkislrjdpanogqcet", 1, 0, 1);
+    test(S("qcpaemsinf"), "rnioadktqlgpbcjsmhef", 1, 1, 1);
+    test(S("gltkojeipd"), "oakgtnldpsefihqmjcbr", 1, 10, 5);
+    test(S("qistfrgnmp"), "gbnaelosidmcjqktfhpr", 1, 19, 5);
+    test(S("bdnpfcqaem"), "akbripjhlosndcmqgfet", 1, 20, S::npos);
+    test(S("ectnhskflp"), "", 5, 0, 5);
+    test(S("fgtianblpq"), "pijag", 5, 0, 5);
+    test(S("mfeqklirnh"), "jrckd", 5, 1, 5);
+    test(S("astedncjhk"), "qcloh", 5, 2, 5);
+    test(S("fhlqgcajbr"), "thlmp", 5, 4, 5);
+    test(S("epfhocmdng"), "qidmo", 5, 5, 5);
+    test(S("apcnsibger"), "lnegpsjqrd", 5, 0, 5);
+    test(S("aqkocrbign"), "rjqdablmfs", 5, 1, 6);
+    test(S("ijsmdtqgce"), "enkgpbsjaq", 5, 5, 5);
+    test(S("clobgsrken"), "kdsgoaijfh", 5, 9, 6);
+    test(S("jbhcfposld"), "trfqgmckbe", 5, 10, 5);
+    test(S("oqnpblhide"), "igetsracjfkdnpoblhqm", 5, 0, 5);
+    test(S("lroeasctif"), "nqctfaogirshlekbdjpm", 5, 1, 5);
+    test(S("bpjlgmiedh"), "csehfgomljdqinbartkp", 5, 10, 6);
+    test(S("pamkeoidrj"), "qahoegcmplkfsjbdnitr", 5, 19, 8);
+    test(S("espogqbthk"), "dpteiajrqmsognhlfbkc", 5, 20, S::npos);
+    test(S("shoiedtcjb"), "", 9, 0, 9);
+    test(S("ebcinjgads"), "tqbnh", 9, 0, 9);
+    test(S("dqmregkcfl"), "akmle", 9, 1, 9);
+    test(S("ngcrieqajf"), "iqfkm", 9, 2, 9);
+    test(S("qosmilgnjb"), "tqjsr", 9, 4, 9);
+    test(S("ikabsjtdfl"), "jplqg", 9, 5, S::npos);
+    test(S("ersmicafdh"), "oilnrbcgtj", 9, 0, 9);
+    test(S("fdnplotmgh"), "morkglpesn", 9, 1, 9);
+    test(S("fdbicojerm"), "dmicerngat", 9, 5, S::npos);
+    test(S("mbtafndjcq"), "radgeskbtc", 9, 9, 9);
+    test(S("mlenkpfdtc"), "ljikprsmqo", 9, 10, 9);
+    test(S("ahlcifdqgs"), "trqihkcgsjamfdbolnpe", 9, 0, 9);
+    test(S("bgjemaltks"), "lqmthbsrekajgnofcipd", 9, 1, 9);
+    test(S("pdhslbqrfc"), "jtalmedribkgqsopcnfh", 9, 10, 9);
+    test(S("dirhtsnjkc"), "spqfoiclmtagejbndkrh", 9, 19, S::npos);
+    test(S("dlroktbcja"), "nmotklspigjrdhcfaebq", 9, 20, S::npos);
+    test(S("ncjpmaekbs"), "", 10, 0, S::npos);
+    test(S("hlbosgmrak"), "hpmsd", 10, 0, S::npos);
+    test(S("pqfhsgilen"), "qnpor", 10, 1, S::npos);
+    test(S("gqtjsbdckh"), "otdma", 10, 2, S::npos);
+    test(S("cfkqpjlegi"), "efhjg", 10, 4, S::npos);
+    test(S("beanrfodgj"), "odpte", 10, 5, S::npos);
+    test(S("adtkqpbjfi"), "bctdgfmolr", 10, 0, S::npos);
+    test(S("iomkfthagj"), "oaklidrbqg", 10, 1, S::npos);
+}
+
+void test2()
+{
+    test(S("sdpcilonqj"), "dnjfsagktr", 10, 5, S::npos);
+    test(S("gtfbdkqeml"), "nejaktmiqg", 10, 9, S::npos);
+    test(S("bmeqgcdorj"), "pjqonlebsf", 10, 10, S::npos);
+    test(S("etqlcanmob"), "dshmnbtolcjepgaikfqr", 10, 0, S::npos);
+    test(S("roqmkbdtia"), "iogfhpabtjkqlrnemcds", 10, 1, S::npos);
+    test(S("kadsithljf"), "ngridfabjsecpqltkmoh", 10, 10, S::npos);
+    test(S("sgtkpbfdmh"), "athmknplcgofrqejsdib", 10, 19, S::npos);
+    test(S("qgmetnabkl"), "ldobhmqcafnjtkeisgrp", 10, 20, S::npos);
+    test(S("cqjohampgd"), "", 11, 0, S::npos);
+    test(S("hobitmpsan"), "aocjb", 11, 0, S::npos);
+    test(S("tjehkpsalm"), "jbrnk", 11, 1, S::npos);
+    test(S("ngfbojitcl"), "tqedg", 11, 2, S::npos);
+    test(S("rcfkdbhgjo"), "nqskp", 11, 4, S::npos);
+    test(S("qghptonrea"), "eaqkl", 11, 5, S::npos);
+    test(S("hnprfgqjdl"), "reaoicljqm", 11, 0, S::npos);
+    test(S("hlmgabenti"), "lsftgajqpm", 11, 1, S::npos);
+    test(S("ofcjanmrbs"), "rlpfogmits", 11, 5, S::npos);
+    test(S("jqedtkornm"), "shkncmiaqj", 11, 9, S::npos);
+    test(S("rfedlasjmg"), "fpnatrhqgs", 11, 10, S::npos);
+    test(S("talpqjsgkm"), "sjclemqhnpdbgikarfot", 11, 0, S::npos);
+    test(S("lrkcbtqpie"), "otcmedjikgsfnqbrhpla", 11, 1, S::npos);
+    test(S("cipogdskjf"), "bonsaefdqiprkhlgtjcm", 11, 10, S::npos);
+    test(S("nqedcojahi"), "egpscmahijlfnkrodqtb", 11, 19, S::npos);
+    test(S("hefnrkmctj"), "kmqbfepjthgilscrndoa", 11, 20, S::npos);
+    test(S("atqirnmekfjolhpdsgcb"), "", 0, 0, 0);
+    test(S("echfkmlpribjnqsaogtd"), "prboq", 0, 0, 0);
+    test(S("qnhiftdgcleajbpkrosm"), "fjcqh", 0, 1, 0);
+    test(S("chamfknorbedjitgslpq"), "fmosa", 0, 2, 0);
+    test(S("njhqpibfmtlkaecdrgso"), "qdbok", 0, 4, 0);
+    test(S("ebnghfsqkprmdcljoiat"), "amslg", 0, 5, 0);
+    test(S("letjomsgihfrpqbkancd"), "smpltjneqb", 0, 0, 0);
+    test(S("nblgoipcrqeaktshjdmf"), "flitskrnge", 0, 1, 0);
+    test(S("cehkbngtjoiflqapsmrd"), "pgqihmlbef", 0, 5, 0);
+    test(S("mignapfoklbhcqjetdrs"), "cfpdqjtgsb", 0, 9, 0);
+    test(S("ceatbhlsqjgpnokfrmdi"), "htpsiaflom", 0, 10, 0);
+    test(S("ocihkjgrdelpfnmastqb"), "kpjfiaceghsrdtlbnomq", 0, 0, 0);
+    test(S("noelgschdtbrjfmiqkap"), "qhtbomidljgafneksprc", 0, 1, 0);
+    test(S("dkclqfombepritjnghas"), "nhtjobkcefldimpsaqgr", 0, 10, 0);
+    test(S("miklnresdgbhqcojftap"), "prabcjfqnoeskilmtgdh", 0, 19, 11);
+    test(S("htbcigojaqmdkfrnlsep"), "dtrgmchilkasqoebfpjn", 0, 20, S::npos);
+    test(S("febhmqtjanokscdirpgl"), "", 1, 0, 1);
+    test(S("loakbsqjpcrdhftniegm"), "sqome", 1, 0, 1);
+    test(S("reagphsqflbitdcjmkno"), "smfte", 1, 1, 1);
+    test(S("jitlfrqemsdhkopncabg"), "ciboh", 1, 2, 2);
+    test(S("mhtaepscdnrjqgbkifol"), "haois", 1, 4, 2);
+    test(S("tocesrfmnglpbjihqadk"), "abfki", 1, 5, 1);
+    test(S("lpfmctjrhdagneskbqoi"), "frdkocntmq", 1, 0, 1);
+    test(S("lsmqaepkdhncirbtjfgo"), "oasbpedlnr", 1, 1, 1);
+    test(S("epoiqmtldrabnkjhcfsg"), "kltqmhgand", 1, 5, 1);
+    test(S("emgasrilpknqojhtbdcf"), "gdtfjchpmr", 1, 9, 3);
+    test(S("hnfiagdpcklrjetqbsom"), "ponmcqblet", 1, 10, 2);
+    test(S("nsdfebgajhmtricpoklq"), "sgphqdnofeiklatbcmjr", 1, 0, 1);
+    test(S("atjgfsdlpobmeiqhncrk"), "ljqprsmigtfoneadckbh", 1, 1, 1);
+    test(S("sitodfgnrejlahcbmqkp"), "ligeojhafnkmrcsqtbdp", 1, 10, 2);
+    test(S("fraghmbiceknltjpqosd"), "lsimqfnjarbopedkhcgt", 1, 19, 13);
+    test(S("pmafenlhqtdbkirjsogc"), "abedmfjlghniorcqptks", 1, 20, S::npos);
+    test(S("pihgmoeqtnakrjslcbfd"), "", 10, 0, 10);
+    test(S("gjdkeprctqblnhiafsom"), "hqtoa", 10, 0, 10);
+    test(S("mkpnblfdsahrcqijteog"), "cahif", 10, 1, 10);
+    test(S("gckarqnelodfjhmbptis"), "kehis", 10, 2, 10);
+    test(S("gqpskidtbclomahnrjfe"), "kdlmh", 10, 4, 11);
+    test(S("pkldjsqrfgitbhmaecno"), "paeql", 10, 5, 10);
+    test(S("aftsijrbeklnmcdqhgop"), "aghoqiefnb", 10, 0, 10);
+    test(S("mtlgdrhafjkbiepqnsoc"), "jrbqaikpdo", 10, 1, 10);
+    test(S("pqgirnaefthokdmbsclj"), "smjonaeqcl", 10, 5, 10);
+    test(S("kpdbgjmtherlsfcqoina"), "eqbdrkcfah", 10, 9, 11);
+    test(S("jrlbothiknqmdgcfasep"), "kapmsienhf", 10, 10, 10);
+    test(S("mjogldqferckabinptsh"), "jpqotrlenfcsbhkaimdg", 10, 0, 10);
+    test(S("apoklnefbhmgqcdrisjt"), "jlbmhnfgtcqprikeados", 10, 1, 10);
+    test(S("ifeopcnrjbhkdgatmqls"), "stgbhfmdaljnpqoicker", 10, 10, 11);
+    test(S("ckqhaiesmjdnrgolbtpf"), "oihcetflbjagdsrkmqpn", 10, 19, 11);
+    test(S("bnlgapfimcoterskqdjh"), "adtclebmnpjsrqfkigoh", 10, 20, S::npos);
+    test(S("kgdlrobpmjcthqsafeni"), "", 19, 0, 19);
+    test(S("dfkechomjapgnslbtqir"), "beafg", 19, 0, 19);
+    test(S("rloadknfbqtgmhcsipje"), "iclat", 19, 1, 19);
+    test(S("mgjhkolrnadqbpetcifs"), "rkhnf", 19, 2, 19);
+    test(S("cmlfakiojdrgtbsphqen"), "clshq", 19, 4, 19);
+    test(S("kghbfipeomsntdalrqjc"), "dtcoj", 19, 5, S::npos);
+    test(S("eldiqckrnmtasbghjfpo"), "rqosnjmfth", 19, 0, 19);
+    test(S("abqjcfedgotihlnspkrm"), "siatdfqglh", 19, 1, 19);
+    test(S("qfbadrtjsimkolcenhpg"), "mrlshtpgjq", 19, 5, 19);
+    test(S("abseghclkjqifmtodrnp"), "adlcskgqjt", 19, 9, 19);
+    test(S("ibmsnlrjefhtdokacqpg"), "drshcjknaf", 19, 10, 19);
+    test(S("mrkfciqjebaponsthldg"), "etsaqroinghpkjdlfcbm", 19, 0, 19);
+    test(S("mjkticdeoqshpalrfbgn"), "sgepdnkqliambtrocfhj", 19, 1, 19);
+    test(S("rqnoclbdejgiphtfsakm"), "nlmcjaqgbsortfdihkpe", 19, 10, S::npos);
+    test(S("plkqbhmtfaeodjcrsing"), "racfnpmosldibqkghjet", 19, 19, S::npos);
+    test(S("oegalhmstjrfickpbndq"), "fjhdsctkqeiolagrnmbp", 19, 20, S::npos);
+    test(S("rdtgjcaohpblniekmsfq"), "", 20, 0, S::npos);
+    test(S("ofkqbnjetrmsaidphglc"), "ejanp", 20, 0, S::npos);
+    test(S("grkpahljcftesdmonqib"), "odife", 20, 1, S::npos);
+    test(S("jimlgbhfqkteospardcn"), "okaqd", 20, 2, S::npos);
+    test(S("gftenihpmslrjkqadcob"), "lcdbi", 20, 4, S::npos);
+    test(S("bmhldogtckrfsanijepq"), "fsqbj", 20, 5, S::npos);
+    test(S("nfqkrpjdesabgtlcmoih"), "bigdomnplq", 20, 0, S::npos);
+    test(S("focalnrpiqmdkstehbjg"), "apiblotgcd", 20, 1, S::npos);
+    test(S("rhqdspkmebiflcotnjga"), "acfhdenops", 20, 5, S::npos);
+    test(S("rahdtmsckfboqlpniegj"), "jopdeamcrk", 20, 9, S::npos);
+    test(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, S::npos);
+    test(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos);
+}
+
+void test3()
+{
+    test(S("pboqganrhedjmltsicfk"), "gbkhdnpoietfcmrslajq", 20, 1, S::npos);
+    test(S("klchabsimetjnqgorfpd"), "rtfnmbsglkjaichoqedp", 20, 10, S::npos);
+    test(S("sirfgmjqhctndbklaepo"), "ohkmdpfqbsacrtjnlgei", 20, 19, S::npos);
+    test(S("rlbdsiceaonqjtfpghkm"), "dlbrteoisgphmkncajfq", 20, 20, S::npos);
+    test(S("ecgdanriptblhjfqskom"), "", 21, 0, S::npos);
+    test(S("fdmiarlpgcskbhoteqjn"), "sjrlo", 21, 0, S::npos);
+    test(S("rlbstjqopignecmfadkh"), "qjpor", 21, 1, S::npos);
+    test(S("grjpqmbshektdolcafni"), "odhfn", 21, 2, S::npos);
+    test(S("sakfcohtqnibprjmlged"), "qtfin", 21, 4, S::npos);
+    test(S("mjtdglasihqpocebrfkn"), "hpqfo", 21, 5, S::npos);
+    test(S("okaplfrntghqbmeicsdj"), "fabmertkos", 21, 0, S::npos);
+    test(S("sahngemrtcjidqbklfpo"), "brqtgkmaej", 21, 1, S::npos);
+    test(S("dlmsipcnekhbgoaftqjr"), "nfrdeihsgl", 21, 5, S::npos);
+    test(S("ahegrmqnoiklpfsdbcjt"), "hlfrosekpi", 21, 9, S::npos);
+    test(S("hdsjbnmlegtkqripacof"), "atgbkrjdsm", 21, 10, S::npos);
+    test(S("pcnedrfjihqbalkgtoms"), "blnrptjgqmaifsdkhoec", 21, 0, S::npos);
+    test(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, S::npos);
+    test(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, S::npos);
+    test(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, S::npos);
+    test(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/string_size.pass.cpp
new file mode 100644
index 0000000..4802073
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.not.of/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_not_of(const basic_string& str, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.find_first_not_of(str, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.find_first_not_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, S::npos);
+    test(S(""), S("laenf"), 0, S::npos);
+    test(S(""), S("pqlnkmbdjo"), 0, S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), 0, S::npos);
+    test(S(""), S(""), 1, S::npos);
+    test(S(""), S("bjaht"), 1, S::npos);
+    test(S(""), S("hjlcmgpket"), 1, S::npos);
+    test(S(""), S("htaobedqikfplcgjsmrn"), 1, S::npos);
+    test(S("fodgq"), S(""), 0, 0);
+    test(S("qanej"), S("dfkap"), 0, 0);
+    test(S("clbao"), S("ihqrfebgad"), 0, 0);
+    test(S("mekdn"), S("ngtjfcalbseiqrphmkdo"), 0, S::npos);
+    test(S("srdfq"), S(""), 1, 1);
+    test(S("oemth"), S("ikcrq"), 1, 1);
+    test(S("cdaih"), S("dmajblfhsg"), 1, 3);
+    test(S("qohtk"), S("oqftjhdmkgsblacenirp"), 1, S::npos);
+    test(S("cshmd"), S(""), 2, 2);
+    test(S("lhcdo"), S("oebqi"), 2, 2);
+    test(S("qnsoh"), S("kojhpmbsfe"), 2, S::npos);
+    test(S("pkrof"), S("acbsjqogpltdkhinfrem"), 2, S::npos);
+    test(S("fmtsp"), S(""), 4, 4);
+    test(S("khbpm"), S("aobjd"), 4, 4);
+    test(S("pbsji"), S("pcbahntsje"), 4, 4);
+    test(S("mprdj"), S("fhepcrntkoagbmldqijs"), 4, S::npos);
+    test(S("eqmpa"), S(""), 5, S::npos);
+    test(S("omigs"), S("kocgb"), 5, S::npos);
+    test(S("onmje"), S("fbslrjiqkm"), 5, S::npos);
+    test(S("oqmrj"), S("jeidpcmalhfnqbgtrsko"), 5, S::npos);
+    test(S("schfa"), S(""), 6, S::npos);
+    test(S("igdsc"), S("qngpd"), 6, S::npos);
+    test(S("brqgo"), S("rodhqklgmb"), 6, S::npos);
+    test(S("tnrph"), S("thdjgafrlbkoiqcspmne"), 6, S::npos);
+    test(S("hcjitbfapl"), S(""), 0, 0);
+    test(S("daiprenocl"), S("ashjd"), 0, 2);
+    test(S("litpcfdghe"), S("mgojkldsqh"), 0, 1);
+    test(S("aidjksrolc"), S("imqnaghkfrdtlopbjesc"), 0, S::npos);
+    test(S("qpghtfbaji"), S(""), 1, 1);
+    test(S("gfshlcmdjr"), S("nadkh"), 1, 1);
+    test(S("nkodajteqp"), S("ofdrqmkebl"), 1, 4);
+    test(S("gbmetiprqd"), S("bdfjqgatlksriohemnpc"), 1, S::npos);
+    test(S("crnklpmegd"), S(""), 5, 5);
+    test(S("jsbtafedoc"), S("prqgn"), 5, 5);
+    test(S("qnmodrtkeb"), S("pejafmnokr"), 5, 6);
+    test(S("cpebqsfmnj"), S("odnqkgijrhabfmcestlp"), 5, S::npos);
+    test(S("lmofqdhpki"), S(""), 9, 9);
+    test(S("hnefkqimca"), S("rtjpa"), 9, S::npos);
+    test(S("drtasbgmfp"), S("ktsrmnqagd"), 9, 9);
+    test(S("lsaijeqhtr"), S("rtdhgcisbnmoaqkfpjle"), 9, S::npos);
+    test(S("elgofjmbrq"), S(""), 10, S::npos);
+    test(S("mjqdgalkpc"), S("dplqa"), 10, S::npos);
+    test(S("kthqnfcerm"), S("dkacjoptns"), 10, S::npos);
+    test(S("dfsjhanorc"), S("hqfimtrgnbekpdcsjalo"), 10, S::npos);
+    test(S("eqsgalomhb"), S(""), 11, S::npos);
+    test(S("akiteljmoh"), S("lofbc"), 11, S::npos);
+    test(S("hlbdfreqjo"), S("astoegbfpn"), 11, S::npos);
+    test(S("taqobhlerg"), S("pdgreqomsncafklhtibj"), 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), S(""), 0, 0);
+    test(S("aemtbrgcklhndjisfpoq"), S("lbtqd"), 0, 0);
+    test(S("pnracgfkjdiholtbqsem"), S("tboimldpjh"), 0, 1);
+    test(S("dicfltehbsgrmojnpkaq"), S("slcerthdaiqjfnobgkpm"), 0, S::npos);
+    test(S("jlnkraeodhcspfgbqitm"), S(""), 1, 1);
+    test(S("lhosrngtmfjikbqpcade"), S("aqibs"), 1, 1);
+    test(S("rbtaqjhgkneisldpmfoc"), S("gtfblmqinc"), 1, 3);
+    test(S("gpifsqlrdkbonjtmheca"), S("mkqpbtdalgniorhfescj"), 1, S::npos);
+    test(S("hdpkobnsalmcfijregtq"), S(""), 10, 10);
+    test(S("jtlshdgqaiprkbcoenfm"), S("pblas"), 10, 11);
+    test(S("fkdrbqltsgmcoiphneaj"), S("arosdhcfme"), 10, 13);
+    test(S("crsplifgtqedjohnabmk"), S("blkhjeogicatqfnpdmsr"), 10, S::npos);
+    test(S("niptglfbosehkamrdqcj"), S(""), 19, 19);
+    test(S("copqdhstbingamjfkler"), S("djkqc"), 19, 19);
+    test(S("mrtaefilpdsgocnhqbjk"), S("lgokshjtpb"), 19, S::npos);
+    test(S("kojatdhlcmigpbfrqnes"), S("bqjhtkfepimcnsgrlado"), 19, S::npos);
+    test(S("eaintpchlqsbdgrkjofm"), S(""), 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), S("nocfa"), 20, S::npos);
+    test(S("spocfaktqdbiejlhngmr"), S("bgtajmiedc"), 20, S::npos);
+    test(S("rphmlekgfscndtaobiqj"), S("lsckfnqgdahejiopbtmr"), 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), S(""), 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), S("gfsrt"), 21, S::npos);
+    test(S("latkmisecnorjbfhqpdg"), S("pfsocbhjtm"), 21, S::npos);
+    test(S("lecfratdjkhnsmqpoigb"), S("tpflmdnoicjgkberhqsa"), 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), S(""), S::npos);
+    test(S(""), S("laenf"), S::npos);
+    test(S(""), S("pqlnkmbdjo"), S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), S::npos);
+    test(S("nhmko"), S(""), 0);
+    test(S("lahfb"), S("irkhs"), 0);
+    test(S("gmfhd"), S("kantesmpgj"), 2);
+    test(S("odaft"), S("oknlrstdpiqmjbaghcfe"), S::npos);
+    test(S("eolhfgpjqk"), S(""), 0);
+    test(S("nbatdlmekr"), S("bnrpe"), 2);
+    test(S("jdmciepkaq"), S("jtdaefblso"), 2);
+    test(S("hkbgspoflt"), S("oselktgbcapndfjihrmq"), S::npos);
+    test(S("gprdcokbnjhlsfmtieqa"), S(""), 0);
+    test(S("qjghlnftcaismkropdeb"), S("bjaht"), 0);
+    test(S("pnalfrdtkqcmojiesbhg"), S("hjlcmgpket"), 1);
+    test(S("pniotcfrhqsmgdkjbael"), S("htaobedqikfplcgjsmrn"), S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.of/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/char_size.pass.cpp
new file mode 100644
index 0000000..d178a03
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_of(charT c, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_first_of(c, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.find_first_of(c) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'e', 0, S::npos);
+    test(S(""), 'e', 1, S::npos);
+    test(S("kitcj"), 'e', 0, S::npos);
+    test(S("qkamf"), 'e', 1, S::npos);
+    test(S("nhmko"), 'e', 2, S::npos);
+    test(S("tpsaf"), 'e', 4, S::npos);
+    test(S("lahfb"), 'e', 5, S::npos);
+    test(S("irkhs"), 'e', 6, S::npos);
+    test(S("gmfhdaipsr"), 'e', 0, S::npos);
+    test(S("kantesmpgj"), 'e', 1, 4);
+    test(S("odaftiegpm"), 'e', 5, 6);
+    test(S("oknlrstdpi"), 'e', 9, S::npos);
+    test(S("eolhfgpjqk"), 'e', 10, S::npos);
+    test(S("pcdrofikas"), 'e', 11, S::npos);
+    test(S("nbatdlmekrgcfqsophij"), 'e', 0, 7);
+    test(S("bnrpehidofmqtcksjgla"), 'e', 1, 4);
+    test(S("jdmciepkaqgotsrfnhlb"), 'e', 10, S::npos);
+    test(S("jtdaefblsokrmhpgcnqi"), 'e', 19, S::npos);
+    test(S("hkbgspofltajcnedqmri"), 'e', 20, S::npos);
+    test(S("oselktgbcapndfjihrmq"), 'e', 21, S::npos);
+
+    test(S(""), 'e', S::npos);
+    test(S("csope"), 'e', 4);
+    test(S("gfsmthlkon"), 'e', S::npos);
+    test(S("laenfsbridchgotmkqpj"), 'e', 2);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size.pass.cpp
new file mode 100644
index 0000000..6803024
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size.pass.cpp
@@ -0,0 +1,146 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_of(const charT* s, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_first_of(str, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.find_first_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, S::npos);
+    test(S(""), "laenf", 0, S::npos);
+    test(S(""), "pqlnkmbdjo", 0, S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", 0, S::npos);
+    test(S(""), "", 1, S::npos);
+    test(S(""), "bjaht", 1, S::npos);
+    test(S(""), "hjlcmgpket", 1, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 1, S::npos);
+    test(S("fodgq"), "", 0, S::npos);
+    test(S("qanej"), "dfkap", 0, 1);
+    test(S("clbao"), "ihqrfebgad", 0, 2);
+    test(S("mekdn"), "ngtjfcalbseiqrphmkdo", 0, 0);
+    test(S("srdfq"), "", 1, S::npos);
+    test(S("oemth"), "ikcrq", 1, S::npos);
+    test(S("cdaih"), "dmajblfhsg", 1, 1);
+    test(S("qohtk"), "oqftjhdmkgsblacenirp", 1, 1);
+    test(S("cshmd"), "", 2, S::npos);
+    test(S("lhcdo"), "oebqi", 2, 4);
+    test(S("qnsoh"), "kojhpmbsfe", 2, 2);
+    test(S("pkrof"), "acbsjqogpltdkhinfrem", 2, 2);
+    test(S("fmtsp"), "", 4, S::npos);
+    test(S("khbpm"), "aobjd", 4, S::npos);
+    test(S("pbsji"), "pcbahntsje", 4, S::npos);
+    test(S("mprdj"), "fhepcrntkoagbmldqijs", 4, 4);
+    test(S("eqmpa"), "", 5, S::npos);
+    test(S("omigs"), "kocgb", 5, S::npos);
+    test(S("onmje"), "fbslrjiqkm", 5, S::npos);
+    test(S("oqmrj"), "jeidpcmalhfnqbgtrsko", 5, S::npos);
+    test(S("schfa"), "", 6, S::npos);
+    test(S("igdsc"), "qngpd", 6, S::npos);
+    test(S("brqgo"), "rodhqklgmb", 6, S::npos);
+    test(S("tnrph"), "thdjgafrlbkoiqcspmne", 6, S::npos);
+    test(S("hcjitbfapl"), "", 0, S::npos);
+    test(S("daiprenocl"), "ashjd", 0, 0);
+    test(S("litpcfdghe"), "mgojkldsqh", 0, 0);
+    test(S("aidjksrolc"), "imqnaghkfrdtlopbjesc", 0, 0);
+    test(S("qpghtfbaji"), "", 1, S::npos);
+    test(S("gfshlcmdjr"), "nadkh", 1, 3);
+    test(S("nkodajteqp"), "ofdrqmkebl", 1, 1);
+    test(S("gbmetiprqd"), "bdfjqgatlksriohemnpc", 1, 1);
+    test(S("crnklpmegd"), "", 5, S::npos);
+    test(S("jsbtafedoc"), "prqgn", 5, S::npos);
+    test(S("qnmodrtkeb"), "pejafmnokr", 5, 5);
+    test(S("cpebqsfmnj"), "odnqkgijrhabfmcestlp", 5, 5);
+    test(S("lmofqdhpki"), "", 9, S::npos);
+    test(S("hnefkqimca"), "rtjpa", 9, 9);
+    test(S("drtasbgmfp"), "ktsrmnqagd", 9, S::npos);
+    test(S("lsaijeqhtr"), "rtdhgcisbnmoaqkfpjle", 9, 9);
+    test(S("elgofjmbrq"), "", 10, S::npos);
+    test(S("mjqdgalkpc"), "dplqa", 10, S::npos);
+    test(S("kthqnfcerm"), "dkacjoptns", 10, S::npos);
+    test(S("dfsjhanorc"), "hqfimtrgnbekpdcsjalo", 10, S::npos);
+    test(S("eqsgalomhb"), "", 11, S::npos);
+    test(S("akiteljmoh"), "lofbc", 11, S::npos);
+    test(S("hlbdfreqjo"), "astoegbfpn", 11, S::npos);
+    test(S("taqobhlerg"), "pdgreqomsncafklhtibj", 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), "", 0, S::npos);
+    test(S("aemtbrgcklhndjisfpoq"), "lbtqd", 0, 3);
+    test(S("pnracgfkjdiholtbqsem"), "tboimldpjh", 0, 0);
+    test(S("dicfltehbsgrmojnpkaq"), "slcerthdaiqjfnobgkpm", 0, 0);
+    test(S("jlnkraeodhcspfgbqitm"), "", 1, S::npos);
+    test(S("lhosrngtmfjikbqpcade"), "aqibs", 1, 3);
+    test(S("rbtaqjhgkneisldpmfoc"), "gtfblmqinc", 1, 1);
+    test(S("gpifsqlrdkbonjtmheca"), "mkqpbtdalgniorhfescj", 1, 1);
+    test(S("hdpkobnsalmcfijregtq"), "", 10, S::npos);
+    test(S("jtlshdgqaiprkbcoenfm"), "pblas", 10, 10);
+    test(S("fkdrbqltsgmcoiphneaj"), "arosdhcfme", 10, 10);
+    test(S("crsplifgtqedjohnabmk"), "blkhjeogicatqfnpdmsr", 10, 10);
+    test(S("niptglfbosehkamrdqcj"), "", 19, S::npos);
+    test(S("copqdhstbingamjfkler"), "djkqc", 19, S::npos);
+    test(S("mrtaefilpdsgocnhqbjk"), "lgokshjtpb", 19, 19);
+    test(S("kojatdhlcmigpbfrqnes"), "bqjhtkfepimcnsgrlado", 19, 19);
+    test(S("eaintpchlqsbdgrkjofm"), "", 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), "nocfa", 20, S::npos);
+    test(S("spocfaktqdbiejlhngmr"), "bgtajmiedc", 20, S::npos);
+    test(S("rphmlekgfscndtaobiqj"), "lsckfnqgdahejiopbtmr", 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), "", 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), "gfsrt", 21, S::npos);
+    test(S("latkmisecnorjbfhqpdg"), "pfsocbhjtm", 21, S::npos);
+    test(S("lecfratdjkhnsmqpoigb"), "tpflmdnoicjgkberhqsa", 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), "", S::npos);
+    test(S(""), "laenf", S::npos);
+    test(S(""), "pqlnkmbdjo", S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", S::npos);
+    test(S("nhmko"), "", S::npos);
+    test(S("lahfb"), "irkhs", 2);
+    test(S("gmfhd"), "kantesmpgj", 0);
+    test(S("odaft"), "oknlrstdpiqmjbaghcfe", 0);
+    test(S("eolhfgpjqk"), "", S::npos);
+    test(S("nbatdlmekr"), "bnrpe", 0);
+    test(S("jdmciepkaq"), "jtdaefblso", 0);
+    test(S("hkbgspoflt"), "oselktgbcapndfjihrmq", 0);
+    test(S("gprdcokbnjhlsfmtieqa"), "", S::npos);
+    test(S("qjghlnftcaismkropdeb"), "bjaht", 1);
+    test(S("pnalfrdtkqcmojiesbhg"), "hjlcmgpket", 0);
+    test(S("pniotcfrhqsmgdkjbael"), "htaobedqikfplcgjsmrn", 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..9423a1d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_of(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type n, typename S::size_type x)
+{
+    assert(s.find_first_of(str, pos, n) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, S::npos);
+    test(S(""), "irkhs", 0, 0, S::npos);
+    test(S(""), "kante", 0, 1, S::npos);
+    test(S(""), "oknlr", 0, 2, S::npos);
+    test(S(""), "pcdro", 0, 4, S::npos);
+    test(S(""), "bnrpe", 0, 5, S::npos);
+    test(S(""), "jtdaefblso", 0, 0, S::npos);
+    test(S(""), "oselktgbca", 0, 1, S::npos);
+    test(S(""), "eqgaplhckj", 0, 5, S::npos);
+    test(S(""), "bjahtcmnlp", 0, 9, S::npos);
+    test(S(""), "hjlcmgpket", 0, 10, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 0, 0, S::npos);
+    test(S(""), "hpqiarojkcdlsgnmfetb", 0, 1, S::npos);
+    test(S(""), "dfkaprhjloqetcsimnbg", 0, 10, S::npos);
+    test(S(""), "ihqrfebgadntlpmjksoc", 0, 19, S::npos);
+    test(S(""), "ngtjfcalbseiqrphmkdo", 0, 20, S::npos);
+    test(S(""), "", 1, 0, S::npos);
+    test(S(""), "lbtqd", 1, 0, S::npos);
+    test(S(""), "tboim", 1, 1, S::npos);
+    test(S(""), "slcer", 1, 2, S::npos);
+    test(S(""), "cbjfs", 1, 4, S::npos);
+    test(S(""), "aqibs", 1, 5, S::npos);
+    test(S(""), "gtfblmqinc", 1, 0, S::npos);
+    test(S(""), "mkqpbtdalg", 1, 1, S::npos);
+    test(S(""), "kphatlimcd", 1, 5, S::npos);
+    test(S(""), "pblasqogic", 1, 9, S::npos);
+    test(S(""), "arosdhcfme", 1, 10, S::npos);
+    test(S(""), "blkhjeogicatqfnpdmsr", 1, 0, S::npos);
+    test(S(""), "bmhineprjcoadgstflqk", 1, 1, S::npos);
+    test(S(""), "djkqcmetslnghpbarfoi", 1, 10, S::npos);
+    test(S(""), "lgokshjtpbemarcdqnfi", 1, 19, S::npos);
+    test(S(""), "bqjhtkfepimcnsgrlado", 1, 20, S::npos);
+    test(S("eaint"), "", 0, 0, S::npos);
+    test(S("binja"), "gfsrt", 0, 0, S::npos);
+    test(S("latkm"), "pfsoc", 0, 1, S::npos);
+    test(S("lecfr"), "tpflm", 0, 2, S::npos);
+    test(S("eqkst"), "sgkec", 0, 4, 0);
+    test(S("cdafr"), "romds", 0, 5, 1);
+    test(S("prbhe"), "qhjistlgmr", 0, 0, S::npos);
+    test(S("lbisk"), "pedfirsglo", 0, 1, S::npos);
+    test(S("hrlpd"), "aqcoslgrmk", 0, 5, S::npos);
+    test(S("ehmja"), "dabckmepqj", 0, 9, 0);
+    test(S("mhqgd"), "pqscrjthli", 0, 10, 1);
+    test(S("tgklq"), "kfphdcsjqmobliagtren", 0, 0, S::npos);
+    test(S("bocjs"), "rokpefncljibsdhqtagm", 0, 1, S::npos);
+    test(S("grbsd"), "afionmkphlebtcjqsgrd", 0, 10, S::npos);
+    test(S("ofjqr"), "aenmqplidhkofrjbctsg", 0, 19, 0);
+    test(S("btlfi"), "osjmbtcadhiklegrpqnf", 0, 20, 0);
+    test(S("clrgb"), "", 1, 0, S::npos);
+    test(S("tjmek"), "osmia", 1, 0, S::npos);
+    test(S("bgstp"), "ckonl", 1, 1, S::npos);
+    test(S("hstrk"), "ilcaj", 1, 2, S::npos);
+    test(S("kmspj"), "lasiq", 1, 4, 2);
+    test(S("tjboh"), "kfqmr", 1, 5, S::npos);
+    test(S("ilbcj"), "klnitfaobg", 1, 0, S::npos);
+    test(S("jkngf"), "gjhmdlqikp", 1, 1, 3);
+    test(S("gfcql"), "skbgtahqej", 1, 5, S::npos);
+    test(S("dqtlg"), "bjsdgtlpkf", 1, 9, 2);
+    test(S("bthpg"), "bjgfmnlkio", 1, 10, 4);
+    test(S("dgsnq"), "lbhepotfsjdqigcnamkr", 1, 0, S::npos);
+    test(S("rmfhp"), "tebangckmpsrqdlfojhi", 1, 1, S::npos);
+    test(S("jfdam"), "joflqbdkhtegimscpanr", 1, 10, 1);
+    test(S("edapb"), "adpmcohetfbsrjinlqkg", 1, 19, 1);
+    test(S("brfsm"), "iacldqjpfnogbsrhmetk", 1, 20, 1);
+    test(S("ndrhl"), "", 2, 0, S::npos);
+    test(S("mrecp"), "otkgb", 2, 0, S::npos);
+    test(S("qlasf"), "cqsjl", 2, 1, S::npos);
+    test(S("smaqd"), "dpifl", 2, 2, 4);
+    test(S("hjeni"), "oapht", 2, 4, S::npos);
+    test(S("ocmfj"), "cifts", 2, 5, 3);
+    test(S("hmftq"), "nmsckbgalo", 2, 0, S::npos);
+    test(S("fklad"), "tpksqhamle", 2, 1, S::npos);
+    test(S("dirnm"), "tpdrchmkji", 2, 5, 2);
+    test(S("hrgdc"), "ijagfkblst", 2, 9, 2);
+    test(S("ifakg"), "kpocsignjb", 2, 10, 3);
+    test(S("ebrgd"), "pecqtkjsnbdrialgmohf", 2, 0, S::npos);
+    test(S("rcjml"), "aiortphfcmkjebgsndql", 2, 1, S::npos);
+    test(S("peqmt"), "sdbkeamglhipojqftrcn", 2, 10, 3);
+    test(S("frehn"), "ljqncehgmfktroapidbs", 2, 19, 2);
+    test(S("tqolf"), "rtcfodilamkbenjghqps", 2, 20, 2);
+    test(S("cjgao"), "", 4, 0, S::npos);
+    test(S("kjplq"), "mabns", 4, 0, S::npos);
+    test(S("herni"), "bdnrp", 4, 1, S::npos);
+    test(S("tadrb"), "scidp", 4, 2, S::npos);
+    test(S("pkfeo"), "agbjl", 4, 4, S::npos);
+    test(S("hoser"), "jfmpr", 4, 5, 4);
+    test(S("kgrsp"), "rbpefghsmj", 4, 0, S::npos);
+    test(S("pgejb"), "apsfntdoqc", 4, 1, S::npos);
+    test(S("thlnq"), "ndkjeisgcl", 4, 5, S::npos);
+    test(S("nbmit"), "rnfpqatdeo", 4, 9, 4);
+    test(S("jgmib"), "bntjlqrfik", 4, 10, 4);
+    test(S("ncrfj"), "kcrtmpolnaqejghsfdbi", 4, 0, S::npos);
+    test(S("ncsik"), "lobheanpkmqidsrtcfgj", 4, 1, S::npos);
+    test(S("sgbfh"), "athdkljcnreqbgpmisof", 4, 10, 4);
+    test(S("dktbn"), "qkdmjialrscpbhefgont", 4, 19, 4);
+    test(S("fthqm"), "dmasojntqleribkgfchp", 4, 20, 4);
+    test(S("klopi"), "", 5, 0, S::npos);
+    test(S("dajhn"), "psthd", 5, 0, S::npos);
+    test(S("jbgno"), "rpmjd", 5, 1, S::npos);
+    test(S("hkjae"), "dfsmk", 5, 2, S::npos);
+}
+
+void test1()
+{
+    test(S("gbhqo"), "skqne", 5, 4, S::npos);
+    test(S("ktdor"), "kipnf", 5, 5, S::npos);
+    test(S("ldprn"), "hmrnqdgifl", 5, 0, S::npos);
+    test(S("egmjk"), "fsmjcdairn", 5, 1, S::npos);
+    test(S("armql"), "pcdgltbrfj", 5, 5, S::npos);
+    test(S("cdhjo"), "aekfctpirg", 5, 9, S::npos);
+    test(S("jcons"), "ledihrsgpf", 5, 10, S::npos);
+    test(S("cbrkp"), "mqcklahsbtirgopefndj", 5, 0, S::npos);
+    test(S("fhgna"), "kmlthaoqgecrnpdbjfis", 5, 1, S::npos);
+    test(S("ejfcd"), "sfhbamcdptojlkrenqgi", 5, 10, S::npos);
+    test(S("kqjhe"), "pbniofmcedrkhlstgaqj", 5, 19, S::npos);
+    test(S("pbdjl"), "mongjratcskbhqiepfdl", 5, 20, S::npos);
+    test(S("gajqn"), "", 6, 0, S::npos);
+    test(S("stedk"), "hrnat", 6, 0, S::npos);
+    test(S("tjkaf"), "gsqdt", 6, 1, S::npos);
+    test(S("dthpe"), "bspkd", 6, 2, S::npos);
+    test(S("klhde"), "ohcmb", 6, 4, S::npos);
+    test(S("bhlki"), "heatr", 6, 5, S::npos);
+    test(S("lqmoh"), "pmblckedfn", 6, 0, S::npos);
+    test(S("mtqin"), "aceqmsrbik", 6, 1, S::npos);
+    test(S("dpqbr"), "lmbtdehjrn", 6, 5, S::npos);
+    test(S("kdhmo"), "teqmcrlgib", 6, 9, S::npos);
+    test(S("jblqp"), "njolbmspac", 6, 10, S::npos);
+    test(S("qmjgl"), "pofnhidklamecrbqjgst", 6, 0, S::npos);
+    test(S("rothp"), "jbhckmtgrqnosafedpli", 6, 1, S::npos);
+    test(S("ghknq"), "dobntpmqklicsahgjerf", 6, 10, S::npos);
+    test(S("eopfi"), "tpdshainjkbfoemlrgcq", 6, 19, S::npos);
+    test(S("dsnmg"), "oldpfgeakrnitscbjmqh", 6, 20, S::npos);
+    test(S("jnkrfhotgl"), "", 0, 0, S::npos);
+    test(S("dltjfngbko"), "rqegt", 0, 0, S::npos);
+    test(S("bmjlpkiqde"), "dashm", 0, 1, 8);
+    test(S("skrflobnqm"), "jqirk", 0, 2, 8);
+    test(S("jkpldtshrm"), "rckeg", 0, 4, 1);
+    test(S("ghasdbnjqo"), "jscie", 0, 5, 3);
+    test(S("igrkhpbqjt"), "efsphndliq", 0, 0, S::npos);
+    test(S("ikthdgcamf"), "gdicosleja", 0, 1, 5);
+    test(S("pcofgeniam"), "qcpjibosfl", 0, 5, 0);
+    test(S("rlfjgesqhc"), "lrhmefnjcq", 0, 9, 0);
+    test(S("itphbqsker"), "dtablcrseo", 0, 10, 1);
+    test(S("skjafcirqm"), "apckjsftedbhgomrnilq", 0, 0, S::npos);
+    test(S("tcqomarsfd"), "pcbrgflehjtiadnsokqm", 0, 1, S::npos);
+    test(S("rocfeldqpk"), "nsiadegjklhobrmtqcpf", 0, 10, 4);
+    test(S("cfpegndlkt"), "cpmajdqnolikhgsbretf", 0, 19, 0);
+    test(S("fqbtnkeasj"), "jcflkntmgiqrphdosaeb", 0, 20, 0);
+    test(S("shbcqnmoar"), "", 1, 0, S::npos);
+    test(S("bdoshlmfin"), "ontrs", 1, 0, S::npos);
+    test(S("khfrebnsgq"), "pfkna", 1, 1, S::npos);
+    test(S("getcrsaoji"), "ekosa", 1, 2, 1);
+    test(S("fjiknedcpq"), "anqhk", 1, 4, 4);
+    test(S("tkejgnafrm"), "jekca", 1, 5, 1);
+    test(S("jnakolqrde"), "ikemsjgacf", 1, 0, S::npos);
+    test(S("lcjptsmgbe"), "arolgsjkhm", 1, 1, S::npos);
+    test(S("itfsmcjorl"), "oftkbldhre", 1, 5, 1);
+    test(S("omchkfrjea"), "gbkqdoeftl", 1, 9, 4);
+    test(S("cigfqkated"), "sqcflrgtim", 1, 10, 1);
+    test(S("tscenjikml"), "fmhbkislrjdpanogqcet", 1, 0, S::npos);
+    test(S("qcpaemsinf"), "rnioadktqlgpbcjsmhef", 1, 1, S::npos);
+    test(S("gltkojeipd"), "oakgtnldpsefihqmjcbr", 1, 10, 1);
+    test(S("qistfrgnmp"), "gbnaelosidmcjqktfhpr", 1, 19, 1);
+    test(S("bdnpfcqaem"), "akbripjhlosndcmqgfet", 1, 20, 1);
+    test(S("ectnhskflp"), "", 5, 0, S::npos);
+    test(S("fgtianblpq"), "pijag", 5, 0, S::npos);
+    test(S("mfeqklirnh"), "jrckd", 5, 1, S::npos);
+    test(S("astedncjhk"), "qcloh", 5, 2, 6);
+    test(S("fhlqgcajbr"), "thlmp", 5, 4, S::npos);
+    test(S("epfhocmdng"), "qidmo", 5, 5, 6);
+    test(S("apcnsibger"), "lnegpsjqrd", 5, 0, S::npos);
+    test(S("aqkocrbign"), "rjqdablmfs", 5, 1, 5);
+    test(S("ijsmdtqgce"), "enkgpbsjaq", 5, 5, 7);
+    test(S("clobgsrken"), "kdsgoaijfh", 5, 9, 5);
+    test(S("jbhcfposld"), "trfqgmckbe", 5, 10, S::npos);
+    test(S("oqnpblhide"), "igetsracjfkdnpoblhqm", 5, 0, S::npos);
+    test(S("lroeasctif"), "nqctfaogirshlekbdjpm", 5, 1, S::npos);
+    test(S("bpjlgmiedh"), "csehfgomljdqinbartkp", 5, 10, 5);
+    test(S("pamkeoidrj"), "qahoegcmplkfsjbdnitr", 5, 19, 5);
+    test(S("espogqbthk"), "dpteiajrqmsognhlfbkc", 5, 20, 5);
+    test(S("shoiedtcjb"), "", 9, 0, S::npos);
+    test(S("ebcinjgads"), "tqbnh", 9, 0, S::npos);
+    test(S("dqmregkcfl"), "akmle", 9, 1, S::npos);
+    test(S("ngcrieqajf"), "iqfkm", 9, 2, S::npos);
+    test(S("qosmilgnjb"), "tqjsr", 9, 4, S::npos);
+    test(S("ikabsjtdfl"), "jplqg", 9, 5, 9);
+    test(S("ersmicafdh"), "oilnrbcgtj", 9, 0, S::npos);
+    test(S("fdnplotmgh"), "morkglpesn", 9, 1, S::npos);
+    test(S("fdbicojerm"), "dmicerngat", 9, 5, 9);
+    test(S("mbtafndjcq"), "radgeskbtc", 9, 9, S::npos);
+    test(S("mlenkpfdtc"), "ljikprsmqo", 9, 10, S::npos);
+    test(S("ahlcifdqgs"), "trqihkcgsjamfdbolnpe", 9, 0, S::npos);
+    test(S("bgjemaltks"), "lqmthbsrekajgnofcipd", 9, 1, S::npos);
+    test(S("pdhslbqrfc"), "jtalmedribkgqsopcnfh", 9, 10, S::npos);
+    test(S("dirhtsnjkc"), "spqfoiclmtagejbndkrh", 9, 19, 9);
+    test(S("dlroktbcja"), "nmotklspigjrdhcfaebq", 9, 20, 9);
+    test(S("ncjpmaekbs"), "", 10, 0, S::npos);
+    test(S("hlbosgmrak"), "hpmsd", 10, 0, S::npos);
+    test(S("pqfhsgilen"), "qnpor", 10, 1, S::npos);
+    test(S("gqtjsbdckh"), "otdma", 10, 2, S::npos);
+    test(S("cfkqpjlegi"), "efhjg", 10, 4, S::npos);
+    test(S("beanrfodgj"), "odpte", 10, 5, S::npos);
+    test(S("adtkqpbjfi"), "bctdgfmolr", 10, 0, S::npos);
+    test(S("iomkfthagj"), "oaklidrbqg", 10, 1, S::npos);
+}
+
+void test2()
+{
+    test(S("sdpcilonqj"), "dnjfsagktr", 10, 5, S::npos);
+    test(S("gtfbdkqeml"), "nejaktmiqg", 10, 9, S::npos);
+    test(S("bmeqgcdorj"), "pjqonlebsf", 10, 10, S::npos);
+    test(S("etqlcanmob"), "dshmnbtolcjepgaikfqr", 10, 0, S::npos);
+    test(S("roqmkbdtia"), "iogfhpabtjkqlrnemcds", 10, 1, S::npos);
+    test(S("kadsithljf"), "ngridfabjsecpqltkmoh", 10, 10, S::npos);
+    test(S("sgtkpbfdmh"), "athmknplcgofrqejsdib", 10, 19, S::npos);
+    test(S("qgmetnabkl"), "ldobhmqcafnjtkeisgrp", 10, 20, S::npos);
+    test(S("cqjohampgd"), "", 11, 0, S::npos);
+    test(S("hobitmpsan"), "aocjb", 11, 0, S::npos);
+    test(S("tjehkpsalm"), "jbrnk", 11, 1, S::npos);
+    test(S("ngfbojitcl"), "tqedg", 11, 2, S::npos);
+    test(S("rcfkdbhgjo"), "nqskp", 11, 4, S::npos);
+    test(S("qghptonrea"), "eaqkl", 11, 5, S::npos);
+    test(S("hnprfgqjdl"), "reaoicljqm", 11, 0, S::npos);
+    test(S("hlmgabenti"), "lsftgajqpm", 11, 1, S::npos);
+    test(S("ofcjanmrbs"), "rlpfogmits", 11, 5, S::npos);
+    test(S("jqedtkornm"), "shkncmiaqj", 11, 9, S::npos);
+    test(S("rfedlasjmg"), "fpnatrhqgs", 11, 10, S::npos);
+    test(S("talpqjsgkm"), "sjclemqhnpdbgikarfot", 11, 0, S::npos);
+    test(S("lrkcbtqpie"), "otcmedjikgsfnqbrhpla", 11, 1, S::npos);
+    test(S("cipogdskjf"), "bonsaefdqiprkhlgtjcm", 11, 10, S::npos);
+    test(S("nqedcojahi"), "egpscmahijlfnkrodqtb", 11, 19, S::npos);
+    test(S("hefnrkmctj"), "kmqbfepjthgilscrndoa", 11, 20, S::npos);
+    test(S("atqirnmekfjolhpdsgcb"), "", 0, 0, S::npos);
+    test(S("echfkmlpribjnqsaogtd"), "prboq", 0, 0, S::npos);
+    test(S("qnhiftdgcleajbpkrosm"), "fjcqh", 0, 1, 4);
+    test(S("chamfknorbedjitgslpq"), "fmosa", 0, 2, 3);
+    test(S("njhqpibfmtlkaecdrgso"), "qdbok", 0, 4, 3);
+    test(S("ebnghfsqkprmdcljoiat"), "amslg", 0, 5, 3);
+    test(S("letjomsgihfrpqbkancd"), "smpltjneqb", 0, 0, S::npos);
+    test(S("nblgoipcrqeaktshjdmf"), "flitskrnge", 0, 1, 19);
+    test(S("cehkbngtjoiflqapsmrd"), "pgqihmlbef", 0, 5, 2);
+    test(S("mignapfoklbhcqjetdrs"), "cfpdqjtgsb", 0, 9, 2);
+    test(S("ceatbhlsqjgpnokfrmdi"), "htpsiaflom", 0, 10, 2);
+    test(S("ocihkjgrdelpfnmastqb"), "kpjfiaceghsrdtlbnomq", 0, 0, S::npos);
+    test(S("noelgschdtbrjfmiqkap"), "qhtbomidljgafneksprc", 0, 1, 16);
+    test(S("dkclqfombepritjnghas"), "nhtjobkcefldimpsaqgr", 0, 10, 1);
+    test(S("miklnresdgbhqcojftap"), "prabcjfqnoeskilmtgdh", 0, 19, 0);
+    test(S("htbcigojaqmdkfrnlsep"), "dtrgmchilkasqoebfpjn", 0, 20, 0);
+    test(S("febhmqtjanokscdirpgl"), "", 1, 0, S::npos);
+    test(S("loakbsqjpcrdhftniegm"), "sqome", 1, 0, S::npos);
+    test(S("reagphsqflbitdcjmkno"), "smfte", 1, 1, 6);
+    test(S("jitlfrqemsdhkopncabg"), "ciboh", 1, 2, 1);
+    test(S("mhtaepscdnrjqgbkifol"), "haois", 1, 4, 1);
+    test(S("tocesrfmnglpbjihqadk"), "abfki", 1, 5, 6);
+    test(S("lpfmctjrhdagneskbqoi"), "frdkocntmq", 1, 0, S::npos);
+    test(S("lsmqaepkdhncirbtjfgo"), "oasbpedlnr", 1, 1, 19);
+    test(S("epoiqmtldrabnkjhcfsg"), "kltqmhgand", 1, 5, 4);
+    test(S("emgasrilpknqojhtbdcf"), "gdtfjchpmr", 1, 9, 1);
+    test(S("hnfiagdpcklrjetqbsom"), "ponmcqblet", 1, 10, 1);
+    test(S("nsdfebgajhmtricpoklq"), "sgphqdnofeiklatbcmjr", 1, 0, S::npos);
+    test(S("atjgfsdlpobmeiqhncrk"), "ljqprsmigtfoneadckbh", 1, 1, 7);
+    test(S("sitodfgnrejlahcbmqkp"), "ligeojhafnkmrcsqtbdp", 1, 10, 1);
+    test(S("fraghmbiceknltjpqosd"), "lsimqfnjarbopedkhcgt", 1, 19, 1);
+    test(S("pmafenlhqtdbkirjsogc"), "abedmfjlghniorcqptks", 1, 20, 1);
+    test(S("pihgmoeqtnakrjslcbfd"), "", 10, 0, S::npos);
+    test(S("gjdkeprctqblnhiafsom"), "hqtoa", 10, 0, S::npos);
+    test(S("mkpnblfdsahrcqijteog"), "cahif", 10, 1, 12);
+    test(S("gckarqnelodfjhmbptis"), "kehis", 10, 2, S::npos);
+    test(S("gqpskidtbclomahnrjfe"), "kdlmh", 10, 4, 10);
+    test(S("pkldjsqrfgitbhmaecno"), "paeql", 10, 5, 15);
+    test(S("aftsijrbeklnmcdqhgop"), "aghoqiefnb", 10, 0, S::npos);
+    test(S("mtlgdrhafjkbiepqnsoc"), "jrbqaikpdo", 10, 1, S::npos);
+    test(S("pqgirnaefthokdmbsclj"), "smjonaeqcl", 10, 5, 11);
+    test(S("kpdbgjmtherlsfcqoina"), "eqbdrkcfah", 10, 9, 10);
+    test(S("jrlbothiknqmdgcfasep"), "kapmsienhf", 10, 10, 11);
+    test(S("mjogldqferckabinptsh"), "jpqotrlenfcsbhkaimdg", 10, 0, S::npos);
+    test(S("apoklnefbhmgqcdrisjt"), "jlbmhnfgtcqprikeados", 10, 1, 18);
+    test(S("ifeopcnrjbhkdgatmqls"), "stgbhfmdaljnpqoicker", 10, 10, 10);
+    test(S("ckqhaiesmjdnrgolbtpf"), "oihcetflbjagdsrkmqpn", 10, 19, 10);
+    test(S("bnlgapfimcoterskqdjh"), "adtclebmnpjsrqfkigoh", 10, 20, 10);
+    test(S("kgdlrobpmjcthqsafeni"), "", 19, 0, S::npos);
+    test(S("dfkechomjapgnslbtqir"), "beafg", 19, 0, S::npos);
+    test(S("rloadknfbqtgmhcsipje"), "iclat", 19, 1, S::npos);
+    test(S("mgjhkolrnadqbpetcifs"), "rkhnf", 19, 2, S::npos);
+    test(S("cmlfakiojdrgtbsphqen"), "clshq", 19, 4, S::npos);
+    test(S("kghbfipeomsntdalrqjc"), "dtcoj", 19, 5, 19);
+    test(S("eldiqckrnmtasbghjfpo"), "rqosnjmfth", 19, 0, S::npos);
+    test(S("abqjcfedgotihlnspkrm"), "siatdfqglh", 19, 1, S::npos);
+    test(S("qfbadrtjsimkolcenhpg"), "mrlshtpgjq", 19, 5, S::npos);
+    test(S("abseghclkjqifmtodrnp"), "adlcskgqjt", 19, 9, S::npos);
+    test(S("ibmsnlrjefhtdokacqpg"), "drshcjknaf", 19, 10, S::npos);
+    test(S("mrkfciqjebaponsthldg"), "etsaqroinghpkjdlfcbm", 19, 0, S::npos);
+    test(S("mjkticdeoqshpalrfbgn"), "sgepdnkqliambtrocfhj", 19, 1, S::npos);
+    test(S("rqnoclbdejgiphtfsakm"), "nlmcjaqgbsortfdihkpe", 19, 10, 19);
+    test(S("plkqbhmtfaeodjcrsing"), "racfnpmosldibqkghjet", 19, 19, 19);
+    test(S("oegalhmstjrfickpbndq"), "fjhdsctkqeiolagrnmbp", 19, 20, 19);
+    test(S("rdtgjcaohpblniekmsfq"), "", 20, 0, S::npos);
+    test(S("ofkqbnjetrmsaidphglc"), "ejanp", 20, 0, S::npos);
+    test(S("grkpahljcftesdmonqib"), "odife", 20, 1, S::npos);
+    test(S("jimlgbhfqkteospardcn"), "okaqd", 20, 2, S::npos);
+    test(S("gftenihpmslrjkqadcob"), "lcdbi", 20, 4, S::npos);
+    test(S("bmhldogtckrfsanijepq"), "fsqbj", 20, 5, S::npos);
+    test(S("nfqkrpjdesabgtlcmoih"), "bigdomnplq", 20, 0, S::npos);
+    test(S("focalnrpiqmdkstehbjg"), "apiblotgcd", 20, 1, S::npos);
+    test(S("rhqdspkmebiflcotnjga"), "acfhdenops", 20, 5, S::npos);
+    test(S("rahdtmsckfboqlpniegj"), "jopdeamcrk", 20, 9, S::npos);
+    test(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, S::npos);
+    test(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos);
+}
+
+void test3()
+{
+    test(S("pboqganrhedjmltsicfk"), "gbkhdnpoietfcmrslajq", 20, 1, S::npos);
+    test(S("klchabsimetjnqgorfpd"), "rtfnmbsglkjaichoqedp", 20, 10, S::npos);
+    test(S("sirfgmjqhctndbklaepo"), "ohkmdpfqbsacrtjnlgei", 20, 19, S::npos);
+    test(S("rlbdsiceaonqjtfpghkm"), "dlbrteoisgphmkncajfq", 20, 20, S::npos);
+    test(S("ecgdanriptblhjfqskom"), "", 21, 0, S::npos);
+    test(S("fdmiarlpgcskbhoteqjn"), "sjrlo", 21, 0, S::npos);
+    test(S("rlbstjqopignecmfadkh"), "qjpor", 21, 1, S::npos);
+    test(S("grjpqmbshektdolcafni"), "odhfn", 21, 2, S::npos);
+    test(S("sakfcohtqnibprjmlged"), "qtfin", 21, 4, S::npos);
+    test(S("mjtdglasihqpocebrfkn"), "hpqfo", 21, 5, S::npos);
+    test(S("okaplfrntghqbmeicsdj"), "fabmertkos", 21, 0, S::npos);
+    test(S("sahngemrtcjidqbklfpo"), "brqtgkmaej", 21, 1, S::npos);
+    test(S("dlmsipcnekhbgoaftqjr"), "nfrdeihsgl", 21, 5, S::npos);
+    test(S("ahegrmqnoiklpfsdbcjt"), "hlfrosekpi", 21, 9, S::npos);
+    test(S("hdsjbnmlegtkqripacof"), "atgbkrjdsm", 21, 10, S::npos);
+    test(S("pcnedrfjihqbalkgtoms"), "blnrptjgqmaifsdkhoec", 21, 0, S::npos);
+    test(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, S::npos);
+    test(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, S::npos);
+    test(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, S::npos);
+    test(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.first.of/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/string_size.pass.cpp
new file mode 100644
index 0000000..84ba3cd
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.first.of/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_first_of(const basic_string& str, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.find_first_of(str, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.find_first_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, S::npos);
+    test(S(""), S("laenf"), 0, S::npos);
+    test(S(""), S("pqlnkmbdjo"), 0, S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), 0, S::npos);
+    test(S(""), S(""), 1, S::npos);
+    test(S(""), S("bjaht"), 1, S::npos);
+    test(S(""), S("hjlcmgpket"), 1, S::npos);
+    test(S(""), S("htaobedqikfplcgjsmrn"), 1, S::npos);
+    test(S("fodgq"), S(""), 0, S::npos);
+    test(S("qanej"), S("dfkap"), 0, 1);
+    test(S("clbao"), S("ihqrfebgad"), 0, 2);
+    test(S("mekdn"), S("ngtjfcalbseiqrphmkdo"), 0, 0);
+    test(S("srdfq"), S(""), 1, S::npos);
+    test(S("oemth"), S("ikcrq"), 1, S::npos);
+    test(S("cdaih"), S("dmajblfhsg"), 1, 1);
+    test(S("qohtk"), S("oqftjhdmkgsblacenirp"), 1, 1);
+    test(S("cshmd"), S(""), 2, S::npos);
+    test(S("lhcdo"), S("oebqi"), 2, 4);
+    test(S("qnsoh"), S("kojhpmbsfe"), 2, 2);
+    test(S("pkrof"), S("acbsjqogpltdkhinfrem"), 2, 2);
+    test(S("fmtsp"), S(""), 4, S::npos);
+    test(S("khbpm"), S("aobjd"), 4, S::npos);
+    test(S("pbsji"), S("pcbahntsje"), 4, S::npos);
+    test(S("mprdj"), S("fhepcrntkoagbmldqijs"), 4, 4);
+    test(S("eqmpa"), S(""), 5, S::npos);
+    test(S("omigs"), S("kocgb"), 5, S::npos);
+    test(S("onmje"), S("fbslrjiqkm"), 5, S::npos);
+    test(S("oqmrj"), S("jeidpcmalhfnqbgtrsko"), 5, S::npos);
+    test(S("schfa"), S(""), 6, S::npos);
+    test(S("igdsc"), S("qngpd"), 6, S::npos);
+    test(S("brqgo"), S("rodhqklgmb"), 6, S::npos);
+    test(S("tnrph"), S("thdjgafrlbkoiqcspmne"), 6, S::npos);
+    test(S("hcjitbfapl"), S(""), 0, S::npos);
+    test(S("daiprenocl"), S("ashjd"), 0, 0);
+    test(S("litpcfdghe"), S("mgojkldsqh"), 0, 0);
+    test(S("aidjksrolc"), S("imqnaghkfrdtlopbjesc"), 0, 0);
+    test(S("qpghtfbaji"), S(""), 1, S::npos);
+    test(S("gfshlcmdjr"), S("nadkh"), 1, 3);
+    test(S("nkodajteqp"), S("ofdrqmkebl"), 1, 1);
+    test(S("gbmetiprqd"), S("bdfjqgatlksriohemnpc"), 1, 1);
+    test(S("crnklpmegd"), S(""), 5, S::npos);
+    test(S("jsbtafedoc"), S("prqgn"), 5, S::npos);
+    test(S("qnmodrtkeb"), S("pejafmnokr"), 5, 5);
+    test(S("cpebqsfmnj"), S("odnqkgijrhabfmcestlp"), 5, 5);
+    test(S("lmofqdhpki"), S(""), 9, S::npos);
+    test(S("hnefkqimca"), S("rtjpa"), 9, 9);
+    test(S("drtasbgmfp"), S("ktsrmnqagd"), 9, S::npos);
+    test(S("lsaijeqhtr"), S("rtdhgcisbnmoaqkfpjle"), 9, 9);
+    test(S("elgofjmbrq"), S(""), 10, S::npos);
+    test(S("mjqdgalkpc"), S("dplqa"), 10, S::npos);
+    test(S("kthqnfcerm"), S("dkacjoptns"), 10, S::npos);
+    test(S("dfsjhanorc"), S("hqfimtrgnbekpdcsjalo"), 10, S::npos);
+    test(S("eqsgalomhb"), S(""), 11, S::npos);
+    test(S("akiteljmoh"), S("lofbc"), 11, S::npos);
+    test(S("hlbdfreqjo"), S("astoegbfpn"), 11, S::npos);
+    test(S("taqobhlerg"), S("pdgreqomsncafklhtibj"), 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), S(""), 0, S::npos);
+    test(S("aemtbrgcklhndjisfpoq"), S("lbtqd"), 0, 3);
+    test(S("pnracgfkjdiholtbqsem"), S("tboimldpjh"), 0, 0);
+    test(S("dicfltehbsgrmojnpkaq"), S("slcerthdaiqjfnobgkpm"), 0, 0);
+    test(S("jlnkraeodhcspfgbqitm"), S(""), 1, S::npos);
+    test(S("lhosrngtmfjikbqpcade"), S("aqibs"), 1, 3);
+    test(S("rbtaqjhgkneisldpmfoc"), S("gtfblmqinc"), 1, 1);
+    test(S("gpifsqlrdkbonjtmheca"), S("mkqpbtdalgniorhfescj"), 1, 1);
+    test(S("hdpkobnsalmcfijregtq"), S(""), 10, S::npos);
+    test(S("jtlshdgqaiprkbcoenfm"), S("pblas"), 10, 10);
+    test(S("fkdrbqltsgmcoiphneaj"), S("arosdhcfme"), 10, 10);
+    test(S("crsplifgtqedjohnabmk"), S("blkhjeogicatqfnpdmsr"), 10, 10);
+    test(S("niptglfbosehkamrdqcj"), S(""), 19, S::npos);
+    test(S("copqdhstbingamjfkler"), S("djkqc"), 19, S::npos);
+    test(S("mrtaefilpdsgocnhqbjk"), S("lgokshjtpb"), 19, 19);
+    test(S("kojatdhlcmigpbfrqnes"), S("bqjhtkfepimcnsgrlado"), 19, 19);
+    test(S("eaintpchlqsbdgrkjofm"), S(""), 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), S("nocfa"), 20, S::npos);
+    test(S("spocfaktqdbiejlhngmr"), S("bgtajmiedc"), 20, S::npos);
+    test(S("rphmlekgfscndtaobiqj"), S("lsckfnqgdahejiopbtmr"), 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), S(""), 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), S("gfsrt"), 21, S::npos);
+    test(S("latkmisecnorjbfhqpdg"), S("pfsocbhjtm"), 21, S::npos);
+    test(S("lecfratdjkhnsmqpoigb"), S("tpflmdnoicjgkberhqsa"), 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), S(""), S::npos);
+    test(S(""), S("laenf"), S::npos);
+    test(S(""), S("pqlnkmbdjo"), S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), S::npos);
+    test(S("nhmko"), S(""), S::npos);
+    test(S("lahfb"), S("irkhs"), 2);
+    test(S("gmfhd"), S("kantesmpgj"), 0);
+    test(S("odaft"), S("oknlrstdpiqmjbaghcfe"), 0);
+    test(S("eolhfgpjqk"), S(""), S::npos);
+    test(S("nbatdlmekr"), S("bnrpe"), 0);
+    test(S("jdmciepkaq"), S("jtdaefblso"), 0);
+    test(S("hkbgspoflt"), S("oselktgbcapndfjihrmq"), 0);
+    test(S("gprdcokbnjhlsfmtieqa"), S(""), S::npos);
+    test(S("qjghlnftcaismkropdeb"), S("bjaht"), 1);
+    test(S("pnalfrdtkqcmojiesbhg"), S("hjlcmgpket"), 0);
+    test(S("pniotcfrhqsmgdkjbael"), S("htaobedqikfplcgjsmrn"), 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/char_size.pass.cpp
new file mode 100644
index 0000000..5c6275f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_not_of(charT c, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_last_not_of(c, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.find_last_not_of(c) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'i', 0, S::npos);
+    test(S(""), 'i', 1, S::npos);
+    test(S("kitcj"), 'i', 0, 0);
+    test(S("qkamf"), 'i', 1, 1);
+    test(S("nhmko"), 'i', 2, 2);
+    test(S("tpsaf"), 'i', 4, 4);
+    test(S("lahfb"), 'i', 5, 4);
+    test(S("irkhs"), 'i', 6, 4);
+    test(S("gmfhdaipsr"), 'i', 0, 0);
+    test(S("kantesmpgj"), 'i', 1, 1);
+    test(S("odaftiegpm"), 'i', 5, 4);
+    test(S("oknlrstdpi"), 'i', 9, 8);
+    test(S("eolhfgpjqk"), 'i', 10, 9);
+    test(S("pcdrofikas"), 'i', 11, 9);
+    test(S("nbatdlmekrgcfqsophij"), 'i', 0, 0);
+    test(S("bnrpehidofmqtcksjgla"), 'i', 1, 1);
+    test(S("jdmciepkaqgotsrfnhlb"), 'i', 10, 10);
+    test(S("jtdaefblsokrmhpgcnqi"), 'i', 19, 18);
+    test(S("hkbgspofltajcnedqmri"), 'i', 20, 18);
+    test(S("oselktgbcapndfjihrmq"), 'i', 21, 19);
+
+    test(S(""), 'i', S::npos);
+    test(S("csope"), 'i', 4);
+    test(S("gfsmthlkon"), 'i', 9);
+    test(S("laenfsbridchgotmkqpj"), 'i', 19);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size.pass.cpp
new file mode 100644
index 0000000..5ea8eec
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size.pass.cpp
@@ -0,0 +1,146 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_not_of(const charT* s, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_last_not_of(str, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.find_last_not_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, S::npos);
+    test(S(""), "laenf", 0, S::npos);
+    test(S(""), "pqlnkmbdjo", 0, S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", 0, S::npos);
+    test(S(""), "", 1, S::npos);
+    test(S(""), "bjaht", 1, S::npos);
+    test(S(""), "hjlcmgpket", 1, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 1, S::npos);
+    test(S("fodgq"), "", 0, 0);
+    test(S("qanej"), "dfkap", 0, 0);
+    test(S("clbao"), "ihqrfebgad", 0, 0);
+    test(S("mekdn"), "ngtjfcalbseiqrphmkdo", 0, S::npos);
+    test(S("srdfq"), "", 1, 1);
+    test(S("oemth"), "ikcrq", 1, 1);
+    test(S("cdaih"), "dmajblfhsg", 1, 0);
+    test(S("qohtk"), "oqftjhdmkgsblacenirp", 1, S::npos);
+    test(S("cshmd"), "", 2, 2);
+    test(S("lhcdo"), "oebqi", 2, 2);
+    test(S("qnsoh"), "kojhpmbsfe", 2, 1);
+    test(S("pkrof"), "acbsjqogpltdkhinfrem", 2, S::npos);
+    test(S("fmtsp"), "", 4, 4);
+    test(S("khbpm"), "aobjd", 4, 4);
+    test(S("pbsji"), "pcbahntsje", 4, 4);
+    test(S("mprdj"), "fhepcrntkoagbmldqijs", 4, S::npos);
+    test(S("eqmpa"), "", 5, 4);
+    test(S("omigs"), "kocgb", 5, 4);
+    test(S("onmje"), "fbslrjiqkm", 5, 4);
+    test(S("oqmrj"), "jeidpcmalhfnqbgtrsko", 5, S::npos);
+    test(S("schfa"), "", 6, 4);
+    test(S("igdsc"), "qngpd", 6, 4);
+    test(S("brqgo"), "rodhqklgmb", 6, S::npos);
+    test(S("tnrph"), "thdjgafrlbkoiqcspmne", 6, S::npos);
+    test(S("hcjitbfapl"), "", 0, 0);
+    test(S("daiprenocl"), "ashjd", 0, S::npos);
+    test(S("litpcfdghe"), "mgojkldsqh", 0, S::npos);
+    test(S("aidjksrolc"), "imqnaghkfrdtlopbjesc", 0, S::npos);
+    test(S("qpghtfbaji"), "", 1, 1);
+    test(S("gfshlcmdjr"), "nadkh", 1, 1);
+    test(S("nkodajteqp"), "ofdrqmkebl", 1, 0);
+    test(S("gbmetiprqd"), "bdfjqgatlksriohemnpc", 1, S::npos);
+    test(S("crnklpmegd"), "", 5, 5);
+    test(S("jsbtafedoc"), "prqgn", 5, 5);
+    test(S("qnmodrtkeb"), "pejafmnokr", 5, 4);
+    test(S("cpebqsfmnj"), "odnqkgijrhabfmcestlp", 5, S::npos);
+    test(S("lmofqdhpki"), "", 9, 9);
+    test(S("hnefkqimca"), "rtjpa", 9, 8);
+    test(S("drtasbgmfp"), "ktsrmnqagd", 9, 9);
+    test(S("lsaijeqhtr"), "rtdhgcisbnmoaqkfpjle", 9, S::npos);
+    test(S("elgofjmbrq"), "", 10, 9);
+    test(S("mjqdgalkpc"), "dplqa", 10, 9);
+    test(S("kthqnfcerm"), "dkacjoptns", 10, 9);
+    test(S("dfsjhanorc"), "hqfimtrgnbekpdcsjalo", 10, S::npos);
+    test(S("eqsgalomhb"), "", 11, 9);
+    test(S("akiteljmoh"), "lofbc", 11, 9);
+    test(S("hlbdfreqjo"), "astoegbfpn", 11, 8);
+    test(S("taqobhlerg"), "pdgreqomsncafklhtibj", 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), "", 0, 0);
+    test(S("aemtbrgcklhndjisfpoq"), "lbtqd", 0, 0);
+    test(S("pnracgfkjdiholtbqsem"), "tboimldpjh", 0, S::npos);
+    test(S("dicfltehbsgrmojnpkaq"), "slcerthdaiqjfnobgkpm", 0, S::npos);
+    test(S("jlnkraeodhcspfgbqitm"), "", 1, 1);
+    test(S("lhosrngtmfjikbqpcade"), "aqibs", 1, 1);
+    test(S("rbtaqjhgkneisldpmfoc"), "gtfblmqinc", 1, 0);
+    test(S("gpifsqlrdkbonjtmheca"), "mkqpbtdalgniorhfescj", 1, S::npos);
+    test(S("hdpkobnsalmcfijregtq"), "", 10, 10);
+    test(S("jtlshdgqaiprkbcoenfm"), "pblas", 10, 9);
+    test(S("fkdrbqltsgmcoiphneaj"), "arosdhcfme", 10, 9);
+    test(S("crsplifgtqedjohnabmk"), "blkhjeogicatqfnpdmsr", 10, S::npos);
+    test(S("niptglfbosehkamrdqcj"), "", 19, 19);
+    test(S("copqdhstbingamjfkler"), "djkqc", 19, 19);
+    test(S("mrtaefilpdsgocnhqbjk"), "lgokshjtpb", 19, 16);
+    test(S("kojatdhlcmigpbfrqnes"), "bqjhtkfepimcnsgrlado", 19, S::npos);
+    test(S("eaintpchlqsbdgrkjofm"), "", 20, 19);
+    test(S("gjnhidfsepkrtaqbmclo"), "nocfa", 20, 18);
+    test(S("spocfaktqdbiejlhngmr"), "bgtajmiedc", 20, 19);
+    test(S("rphmlekgfscndtaobiqj"), "lsckfnqgdahejiopbtmr", 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), "", 21, 19);
+    test(S("binjagtfldkrspcomqeh"), "gfsrt", 21, 19);
+    test(S("latkmisecnorjbfhqpdg"), "pfsocbhjtm", 21, 19);
+    test(S("lecfratdjkhnsmqpoigb"), "tpflmdnoicjgkberhqsa", 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), "", S::npos);
+    test(S(""), "laenf", S::npos);
+    test(S(""), "pqlnkmbdjo", S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", S::npos);
+    test(S("nhmko"), "", 4);
+    test(S("lahfb"), "irkhs", 4);
+    test(S("gmfhd"), "kantesmpgj", 4);
+    test(S("odaft"), "oknlrstdpiqmjbaghcfe", S::npos);
+    test(S("eolhfgpjqk"), "", 9);
+    test(S("nbatdlmekr"), "bnrpe", 8);
+    test(S("jdmciepkaq"), "jtdaefblso", 9);
+    test(S("hkbgspoflt"), "oselktgbcapndfjihrmq", S::npos);
+    test(S("gprdcokbnjhlsfmtieqa"), "", 19);
+    test(S("qjghlnftcaismkropdeb"), "bjaht", 18);
+    test(S("pnalfrdtkqcmojiesbhg"), "hjlcmgpket", 17);
+    test(S("pniotcfrhqsmgdkjbael"), "htaobedqikfplcgjsmrn", S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..0f3ca5c
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type n, typename S::size_type x)
+{
+    assert(s.find_last_not_of(str, pos, n) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, S::npos);
+    test(S(""), "irkhs", 0, 0, S::npos);
+    test(S(""), "kante", 0, 1, S::npos);
+    test(S(""), "oknlr", 0, 2, S::npos);
+    test(S(""), "pcdro", 0, 4, S::npos);
+    test(S(""), "bnrpe", 0, 5, S::npos);
+    test(S(""), "jtdaefblso", 0, 0, S::npos);
+    test(S(""), "oselktgbca", 0, 1, S::npos);
+    test(S(""), "eqgaplhckj", 0, 5, S::npos);
+    test(S(""), "bjahtcmnlp", 0, 9, S::npos);
+    test(S(""), "hjlcmgpket", 0, 10, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 0, 0, S::npos);
+    test(S(""), "hpqiarojkcdlsgnmfetb", 0, 1, S::npos);
+    test(S(""), "dfkaprhjloqetcsimnbg", 0, 10, S::npos);
+    test(S(""), "ihqrfebgadntlpmjksoc", 0, 19, S::npos);
+    test(S(""), "ngtjfcalbseiqrphmkdo", 0, 20, S::npos);
+    test(S(""), "", 1, 0, S::npos);
+    test(S(""), "lbtqd", 1, 0, S::npos);
+    test(S(""), "tboim", 1, 1, S::npos);
+    test(S(""), "slcer", 1, 2, S::npos);
+    test(S(""), "cbjfs", 1, 4, S::npos);
+    test(S(""), "aqibs", 1, 5, S::npos);
+    test(S(""), "gtfblmqinc", 1, 0, S::npos);
+    test(S(""), "mkqpbtdalg", 1, 1, S::npos);
+    test(S(""), "kphatlimcd", 1, 5, S::npos);
+    test(S(""), "pblasqogic", 1, 9, S::npos);
+    test(S(""), "arosdhcfme", 1, 10, S::npos);
+    test(S(""), "blkhjeogicatqfnpdmsr", 1, 0, S::npos);
+    test(S(""), "bmhineprjcoadgstflqk", 1, 1, S::npos);
+    test(S(""), "djkqcmetslnghpbarfoi", 1, 10, S::npos);
+    test(S(""), "lgokshjtpbemarcdqnfi", 1, 19, S::npos);
+    test(S(""), "bqjhtkfepimcnsgrlado", 1, 20, S::npos);
+    test(S("eaint"), "", 0, 0, 0);
+    test(S("binja"), "gfsrt", 0, 0, 0);
+    test(S("latkm"), "pfsoc", 0, 1, 0);
+    test(S("lecfr"), "tpflm", 0, 2, 0);
+    test(S("eqkst"), "sgkec", 0, 4, S::npos);
+    test(S("cdafr"), "romds", 0, 5, 0);
+    test(S("prbhe"), "qhjistlgmr", 0, 0, 0);
+    test(S("lbisk"), "pedfirsglo", 0, 1, 0);
+    test(S("hrlpd"), "aqcoslgrmk", 0, 5, 0);
+    test(S("ehmja"), "dabckmepqj", 0, 9, S::npos);
+    test(S("mhqgd"), "pqscrjthli", 0, 10, 0);
+    test(S("tgklq"), "kfphdcsjqmobliagtren", 0, 0, 0);
+    test(S("bocjs"), "rokpefncljibsdhqtagm", 0, 1, 0);
+    test(S("grbsd"), "afionmkphlebtcjqsgrd", 0, 10, 0);
+    test(S("ofjqr"), "aenmqplidhkofrjbctsg", 0, 19, S::npos);
+    test(S("btlfi"), "osjmbtcadhiklegrpqnf", 0, 20, S::npos);
+    test(S("clrgb"), "", 1, 0, 1);
+    test(S("tjmek"), "osmia", 1, 0, 1);
+    test(S("bgstp"), "ckonl", 1, 1, 1);
+    test(S("hstrk"), "ilcaj", 1, 2, 1);
+    test(S("kmspj"), "lasiq", 1, 4, 1);
+    test(S("tjboh"), "kfqmr", 1, 5, 1);
+    test(S("ilbcj"), "klnitfaobg", 1, 0, 1);
+    test(S("jkngf"), "gjhmdlqikp", 1, 1, 1);
+    test(S("gfcql"), "skbgtahqej", 1, 5, 1);
+    test(S("dqtlg"), "bjsdgtlpkf", 1, 9, 1);
+    test(S("bthpg"), "bjgfmnlkio", 1, 10, 1);
+    test(S("dgsnq"), "lbhepotfsjdqigcnamkr", 1, 0, 1);
+    test(S("rmfhp"), "tebangckmpsrqdlfojhi", 1, 1, 1);
+    test(S("jfdam"), "joflqbdkhtegimscpanr", 1, 10, S::npos);
+    test(S("edapb"), "adpmcohetfbsrjinlqkg", 1, 19, S::npos);
+    test(S("brfsm"), "iacldqjpfnogbsrhmetk", 1, 20, S::npos);
+    test(S("ndrhl"), "", 2, 0, 2);
+    test(S("mrecp"), "otkgb", 2, 0, 2);
+    test(S("qlasf"), "cqsjl", 2, 1, 2);
+    test(S("smaqd"), "dpifl", 2, 2, 2);
+    test(S("hjeni"), "oapht", 2, 4, 2);
+    test(S("ocmfj"), "cifts", 2, 5, 2);
+    test(S("hmftq"), "nmsckbgalo", 2, 0, 2);
+    test(S("fklad"), "tpksqhamle", 2, 1, 2);
+    test(S("dirnm"), "tpdrchmkji", 2, 5, 1);
+    test(S("hrgdc"), "ijagfkblst", 2, 9, 1);
+    test(S("ifakg"), "kpocsignjb", 2, 10, 2);
+    test(S("ebrgd"), "pecqtkjsnbdrialgmohf", 2, 0, 2);
+    test(S("rcjml"), "aiortphfcmkjebgsndql", 2, 1, 2);
+    test(S("peqmt"), "sdbkeamglhipojqftrcn", 2, 10, 2);
+    test(S("frehn"), "ljqncehgmfktroapidbs", 2, 19, S::npos);
+    test(S("tqolf"), "rtcfodilamkbenjghqps", 2, 20, S::npos);
+    test(S("cjgao"), "", 4, 0, 4);
+    test(S("kjplq"), "mabns", 4, 0, 4);
+    test(S("herni"), "bdnrp", 4, 1, 4);
+    test(S("tadrb"), "scidp", 4, 2, 4);
+    test(S("pkfeo"), "agbjl", 4, 4, 4);
+    test(S("hoser"), "jfmpr", 4, 5, 3);
+    test(S("kgrsp"), "rbpefghsmj", 4, 0, 4);
+    test(S("pgejb"), "apsfntdoqc", 4, 1, 4);
+    test(S("thlnq"), "ndkjeisgcl", 4, 5, 4);
+    test(S("nbmit"), "rnfpqatdeo", 4, 9, 3);
+    test(S("jgmib"), "bntjlqrfik", 4, 10, 2);
+    test(S("ncrfj"), "kcrtmpolnaqejghsfdbi", 4, 0, 4);
+    test(S("ncsik"), "lobheanpkmqidsrtcfgj", 4, 1, 4);
+    test(S("sgbfh"), "athdkljcnreqbgpmisof", 4, 10, 3);
+    test(S("dktbn"), "qkdmjialrscpbhefgont", 4, 19, 2);
+    test(S("fthqm"), "dmasojntqleribkgfchp", 4, 20, S::npos);
+    test(S("klopi"), "", 5, 0, 4);
+    test(S("dajhn"), "psthd", 5, 0, 4);
+    test(S("jbgno"), "rpmjd", 5, 1, 4);
+    test(S("hkjae"), "dfsmk", 5, 2, 4);
+}
+
+void test1()
+{
+    test(S("gbhqo"), "skqne", 5, 4, 4);
+    test(S("ktdor"), "kipnf", 5, 5, 4);
+    test(S("ldprn"), "hmrnqdgifl", 5, 0, 4);
+    test(S("egmjk"), "fsmjcdairn", 5, 1, 4);
+    test(S("armql"), "pcdgltbrfj", 5, 5, 3);
+    test(S("cdhjo"), "aekfctpirg", 5, 9, 4);
+    test(S("jcons"), "ledihrsgpf", 5, 10, 3);
+    test(S("cbrkp"), "mqcklahsbtirgopefndj", 5, 0, 4);
+    test(S("fhgna"), "kmlthaoqgecrnpdbjfis", 5, 1, 4);
+    test(S("ejfcd"), "sfhbamcdptojlkrenqgi", 5, 10, 1);
+    test(S("kqjhe"), "pbniofmcedrkhlstgaqj", 5, 19, 2);
+    test(S("pbdjl"), "mongjratcskbhqiepfdl", 5, 20, S::npos);
+    test(S("gajqn"), "", 6, 0, 4);
+    test(S("stedk"), "hrnat", 6, 0, 4);
+    test(S("tjkaf"), "gsqdt", 6, 1, 4);
+    test(S("dthpe"), "bspkd", 6, 2, 4);
+    test(S("klhde"), "ohcmb", 6, 4, 4);
+    test(S("bhlki"), "heatr", 6, 5, 4);
+    test(S("lqmoh"), "pmblckedfn", 6, 0, 4);
+    test(S("mtqin"), "aceqmsrbik", 6, 1, 4);
+    test(S("dpqbr"), "lmbtdehjrn", 6, 5, 4);
+    test(S("kdhmo"), "teqmcrlgib", 6, 9, 4);
+    test(S("jblqp"), "njolbmspac", 6, 10, 3);
+    test(S("qmjgl"), "pofnhidklamecrbqjgst", 6, 0, 4);
+    test(S("rothp"), "jbhckmtgrqnosafedpli", 6, 1, 4);
+    test(S("ghknq"), "dobntpmqklicsahgjerf", 6, 10, 1);
+    test(S("eopfi"), "tpdshainjkbfoemlrgcq", 6, 19, S::npos);
+    test(S("dsnmg"), "oldpfgeakrnitscbjmqh", 6, 20, S::npos);
+    test(S("jnkrfhotgl"), "", 0, 0, 0);
+    test(S("dltjfngbko"), "rqegt", 0, 0, 0);
+    test(S("bmjlpkiqde"), "dashm", 0, 1, 0);
+    test(S("skrflobnqm"), "jqirk", 0, 2, 0);
+    test(S("jkpldtshrm"), "rckeg", 0, 4, 0);
+    test(S("ghasdbnjqo"), "jscie", 0, 5, 0);
+    test(S("igrkhpbqjt"), "efsphndliq", 0, 0, 0);
+    test(S("ikthdgcamf"), "gdicosleja", 0, 1, 0);
+    test(S("pcofgeniam"), "qcpjibosfl", 0, 5, S::npos);
+    test(S("rlfjgesqhc"), "lrhmefnjcq", 0, 9, S::npos);
+    test(S("itphbqsker"), "dtablcrseo", 0, 10, 0);
+    test(S("skjafcirqm"), "apckjsftedbhgomrnilq", 0, 0, 0);
+    test(S("tcqomarsfd"), "pcbrgflehjtiadnsokqm", 0, 1, 0);
+    test(S("rocfeldqpk"), "nsiadegjklhobrmtqcpf", 0, 10, 0);
+    test(S("cfpegndlkt"), "cpmajdqnolikhgsbretf", 0, 19, S::npos);
+    test(S("fqbtnkeasj"), "jcflkntmgiqrphdosaeb", 0, 20, S::npos);
+    test(S("shbcqnmoar"), "", 1, 0, 1);
+    test(S("bdoshlmfin"), "ontrs", 1, 0, 1);
+    test(S("khfrebnsgq"), "pfkna", 1, 1, 1);
+    test(S("getcrsaoji"), "ekosa", 1, 2, 0);
+    test(S("fjiknedcpq"), "anqhk", 1, 4, 1);
+    test(S("tkejgnafrm"), "jekca", 1, 5, 0);
+    test(S("jnakolqrde"), "ikemsjgacf", 1, 0, 1);
+    test(S("lcjptsmgbe"), "arolgsjkhm", 1, 1, 1);
+    test(S("itfsmcjorl"), "oftkbldhre", 1, 5, 0);
+    test(S("omchkfrjea"), "gbkqdoeftl", 1, 9, 1);
+    test(S("cigfqkated"), "sqcflrgtim", 1, 10, S::npos);
+    test(S("tscenjikml"), "fmhbkislrjdpanogqcet", 1, 0, 1);
+    test(S("qcpaemsinf"), "rnioadktqlgpbcjsmhef", 1, 1, 1);
+    test(S("gltkojeipd"), "oakgtnldpsefihqmjcbr", 1, 10, S::npos);
+    test(S("qistfrgnmp"), "gbnaelosidmcjqktfhpr", 1, 19, S::npos);
+    test(S("bdnpfcqaem"), "akbripjhlosndcmqgfet", 1, 20, S::npos);
+    test(S("ectnhskflp"), "", 5, 0, 5);
+    test(S("fgtianblpq"), "pijag", 5, 0, 5);
+    test(S("mfeqklirnh"), "jrckd", 5, 1, 5);
+    test(S("astedncjhk"), "qcloh", 5, 2, 5);
+    test(S("fhlqgcajbr"), "thlmp", 5, 4, 5);
+    test(S("epfhocmdng"), "qidmo", 5, 5, 5);
+    test(S("apcnsibger"), "lnegpsjqrd", 5, 0, 5);
+    test(S("aqkocrbign"), "rjqdablmfs", 5, 1, 4);
+    test(S("ijsmdtqgce"), "enkgpbsjaq", 5, 5, 5);
+    test(S("clobgsrken"), "kdsgoaijfh", 5, 9, 3);
+    test(S("jbhcfposld"), "trfqgmckbe", 5, 10, 5);
+    test(S("oqnpblhide"), "igetsracjfkdnpoblhqm", 5, 0, 5);
+    test(S("lroeasctif"), "nqctfaogirshlekbdjpm", 5, 1, 5);
+    test(S("bpjlgmiedh"), "csehfgomljdqinbartkp", 5, 10, 1);
+    test(S("pamkeoidrj"), "qahoegcmplkfsjbdnitr", 5, 19, S::npos);
+    test(S("espogqbthk"), "dpteiajrqmsognhlfbkc", 5, 20, S::npos);
+    test(S("shoiedtcjb"), "", 9, 0, 9);
+    test(S("ebcinjgads"), "tqbnh", 9, 0, 9);
+    test(S("dqmregkcfl"), "akmle", 9, 1, 9);
+    test(S("ngcrieqajf"), "iqfkm", 9, 2, 9);
+    test(S("qosmilgnjb"), "tqjsr", 9, 4, 9);
+    test(S("ikabsjtdfl"), "jplqg", 9, 5, 8);
+    test(S("ersmicafdh"), "oilnrbcgtj", 9, 0, 9);
+    test(S("fdnplotmgh"), "morkglpesn", 9, 1, 9);
+    test(S("fdbicojerm"), "dmicerngat", 9, 5, 8);
+    test(S("mbtafndjcq"), "radgeskbtc", 9, 9, 9);
+    test(S("mlenkpfdtc"), "ljikprsmqo", 9, 10, 9);
+    test(S("ahlcifdqgs"), "trqihkcgsjamfdbolnpe", 9, 0, 9);
+    test(S("bgjemaltks"), "lqmthbsrekajgnofcipd", 9, 1, 9);
+    test(S("pdhslbqrfc"), "jtalmedribkgqsopcnfh", 9, 10, 9);
+    test(S("dirhtsnjkc"), "spqfoiclmtagejbndkrh", 9, 19, 3);
+    test(S("dlroktbcja"), "nmotklspigjrdhcfaebq", 9, 20, S::npos);
+    test(S("ncjpmaekbs"), "", 10, 0, 9);
+    test(S("hlbosgmrak"), "hpmsd", 10, 0, 9);
+    test(S("pqfhsgilen"), "qnpor", 10, 1, 9);
+    test(S("gqtjsbdckh"), "otdma", 10, 2, 9);
+    test(S("cfkqpjlegi"), "efhjg", 10, 4, 9);
+    test(S("beanrfodgj"), "odpte", 10, 5, 9);
+    test(S("adtkqpbjfi"), "bctdgfmolr", 10, 0, 9);
+    test(S("iomkfthagj"), "oaklidrbqg", 10, 1, 9);
+}
+
+void test2()
+{
+    test(S("sdpcilonqj"), "dnjfsagktr", 10, 5, 8);
+    test(S("gtfbdkqeml"), "nejaktmiqg", 10, 9, 9);
+    test(S("bmeqgcdorj"), "pjqonlebsf", 10, 10, 8);
+    test(S("etqlcanmob"), "dshmnbtolcjepgaikfqr", 10, 0, 9);
+    test(S("roqmkbdtia"), "iogfhpabtjkqlrnemcds", 10, 1, 9);
+    test(S("kadsithljf"), "ngridfabjsecpqltkmoh", 10, 10, 7);
+    test(S("sgtkpbfdmh"), "athmknplcgofrqejsdib", 10, 19, 5);
+    test(S("qgmetnabkl"), "ldobhmqcafnjtkeisgrp", 10, 20, S::npos);
+    test(S("cqjohampgd"), "", 11, 0, 9);
+    test(S("hobitmpsan"), "aocjb", 11, 0, 9);
+    test(S("tjehkpsalm"), "jbrnk", 11, 1, 9);
+    test(S("ngfbojitcl"), "tqedg", 11, 2, 9);
+    test(S("rcfkdbhgjo"), "nqskp", 11, 4, 9);
+    test(S("qghptonrea"), "eaqkl", 11, 5, 7);
+    test(S("hnprfgqjdl"), "reaoicljqm", 11, 0, 9);
+    test(S("hlmgabenti"), "lsftgajqpm", 11, 1, 9);
+    test(S("ofcjanmrbs"), "rlpfogmits", 11, 5, 9);
+    test(S("jqedtkornm"), "shkncmiaqj", 11, 9, 7);
+    test(S("rfedlasjmg"), "fpnatrhqgs", 11, 10, 8);
+    test(S("talpqjsgkm"), "sjclemqhnpdbgikarfot", 11, 0, 9);
+    test(S("lrkcbtqpie"), "otcmedjikgsfnqbrhpla", 11, 1, 9);
+    test(S("cipogdskjf"), "bonsaefdqiprkhlgtjcm", 11, 10, 8);
+    test(S("nqedcojahi"), "egpscmahijlfnkrodqtb", 11, 19, S::npos);
+    test(S("hefnrkmctj"), "kmqbfepjthgilscrndoa", 11, 20, S::npos);
+    test(S("atqirnmekfjolhpdsgcb"), "", 0, 0, 0);
+    test(S("echfkmlpribjnqsaogtd"), "prboq", 0, 0, 0);
+    test(S("qnhiftdgcleajbpkrosm"), "fjcqh", 0, 1, 0);
+    test(S("chamfknorbedjitgslpq"), "fmosa", 0, 2, 0);
+    test(S("njhqpibfmtlkaecdrgso"), "qdbok", 0, 4, 0);
+    test(S("ebnghfsqkprmdcljoiat"), "amslg", 0, 5, 0);
+    test(S("letjomsgihfrpqbkancd"), "smpltjneqb", 0, 0, 0);
+    test(S("nblgoipcrqeaktshjdmf"), "flitskrnge", 0, 1, 0);
+    test(S("cehkbngtjoiflqapsmrd"), "pgqihmlbef", 0, 5, 0);
+    test(S("mignapfoklbhcqjetdrs"), "cfpdqjtgsb", 0, 9, 0);
+    test(S("ceatbhlsqjgpnokfrmdi"), "htpsiaflom", 0, 10, 0);
+    test(S("ocihkjgrdelpfnmastqb"), "kpjfiaceghsrdtlbnomq", 0, 0, 0);
+    test(S("noelgschdtbrjfmiqkap"), "qhtbomidljgafneksprc", 0, 1, 0);
+    test(S("dkclqfombepritjnghas"), "nhtjobkcefldimpsaqgr", 0, 10, 0);
+    test(S("miklnresdgbhqcojftap"), "prabcjfqnoeskilmtgdh", 0, 19, S::npos);
+    test(S("htbcigojaqmdkfrnlsep"), "dtrgmchilkasqoebfpjn", 0, 20, S::npos);
+    test(S("febhmqtjanokscdirpgl"), "", 1, 0, 1);
+    test(S("loakbsqjpcrdhftniegm"), "sqome", 1, 0, 1);
+    test(S("reagphsqflbitdcjmkno"), "smfte", 1, 1, 1);
+    test(S("jitlfrqemsdhkopncabg"), "ciboh", 1, 2, 0);
+    test(S("mhtaepscdnrjqgbkifol"), "haois", 1, 4, 0);
+    test(S("tocesrfmnglpbjihqadk"), "abfki", 1, 5, 1);
+    test(S("lpfmctjrhdagneskbqoi"), "frdkocntmq", 1, 0, 1);
+    test(S("lsmqaepkdhncirbtjfgo"), "oasbpedlnr", 1, 1, 1);
+    test(S("epoiqmtldrabnkjhcfsg"), "kltqmhgand", 1, 5, 1);
+    test(S("emgasrilpknqojhtbdcf"), "gdtfjchpmr", 1, 9, 0);
+    test(S("hnfiagdpcklrjetqbsom"), "ponmcqblet", 1, 10, 0);
+    test(S("nsdfebgajhmtricpoklq"), "sgphqdnofeiklatbcmjr", 1, 0, 1);
+    test(S("atjgfsdlpobmeiqhncrk"), "ljqprsmigtfoneadckbh", 1, 1, 1);
+    test(S("sitodfgnrejlahcbmqkp"), "ligeojhafnkmrcsqtbdp", 1, 10, 0);
+    test(S("fraghmbiceknltjpqosd"), "lsimqfnjarbopedkhcgt", 1, 19, S::npos);
+    test(S("pmafenlhqtdbkirjsogc"), "abedmfjlghniorcqptks", 1, 20, S::npos);
+    test(S("pihgmoeqtnakrjslcbfd"), "", 10, 0, 10);
+    test(S("gjdkeprctqblnhiafsom"), "hqtoa", 10, 0, 10);
+    test(S("mkpnblfdsahrcqijteog"), "cahif", 10, 1, 10);
+    test(S("gckarqnelodfjhmbptis"), "kehis", 10, 2, 10);
+    test(S("gqpskidtbclomahnrjfe"), "kdlmh", 10, 4, 9);
+    test(S("pkldjsqrfgitbhmaecno"), "paeql", 10, 5, 10);
+    test(S("aftsijrbeklnmcdqhgop"), "aghoqiefnb", 10, 0, 10);
+    test(S("mtlgdrhafjkbiepqnsoc"), "jrbqaikpdo", 10, 1, 10);
+    test(S("pqgirnaefthokdmbsclj"), "smjonaeqcl", 10, 5, 10);
+    test(S("kpdbgjmtherlsfcqoina"), "eqbdrkcfah", 10, 9, 8);
+    test(S("jrlbothiknqmdgcfasep"), "kapmsienhf", 10, 10, 10);
+    test(S("mjogldqferckabinptsh"), "jpqotrlenfcsbhkaimdg", 10, 0, 10);
+    test(S("apoklnefbhmgqcdrisjt"), "jlbmhnfgtcqprikeados", 10, 1, 10);
+    test(S("ifeopcnrjbhkdgatmqls"), "stgbhfmdaljnpqoicker", 10, 10, 8);
+    test(S("ckqhaiesmjdnrgolbtpf"), "oihcetflbjagdsrkmqpn", 10, 19, S::npos);
+    test(S("bnlgapfimcoterskqdjh"), "adtclebmnpjsrqfkigoh", 10, 20, S::npos);
+    test(S("kgdlrobpmjcthqsafeni"), "", 19, 0, 19);
+    test(S("dfkechomjapgnslbtqir"), "beafg", 19, 0, 19);
+    test(S("rloadknfbqtgmhcsipje"), "iclat", 19, 1, 19);
+    test(S("mgjhkolrnadqbpetcifs"), "rkhnf", 19, 2, 19);
+    test(S("cmlfakiojdrgtbsphqen"), "clshq", 19, 4, 19);
+    test(S("kghbfipeomsntdalrqjc"), "dtcoj", 19, 5, 17);
+    test(S("eldiqckrnmtasbghjfpo"), "rqosnjmfth", 19, 0, 19);
+    test(S("abqjcfedgotihlnspkrm"), "siatdfqglh", 19, 1, 19);
+    test(S("qfbadrtjsimkolcenhpg"), "mrlshtpgjq", 19, 5, 19);
+    test(S("abseghclkjqifmtodrnp"), "adlcskgqjt", 19, 9, 19);
+    test(S("ibmsnlrjefhtdokacqpg"), "drshcjknaf", 19, 10, 19);
+    test(S("mrkfciqjebaponsthldg"), "etsaqroinghpkjdlfcbm", 19, 0, 19);
+    test(S("mjkticdeoqshpalrfbgn"), "sgepdnkqliambtrocfhj", 19, 1, 19);
+    test(S("rqnoclbdejgiphtfsakm"), "nlmcjaqgbsortfdihkpe", 19, 10, 18);
+    test(S("plkqbhmtfaeodjcrsing"), "racfnpmosldibqkghjet", 19, 19, 7);
+    test(S("oegalhmstjrfickpbndq"), "fjhdsctkqeiolagrnmbp", 19, 20, S::npos);
+    test(S("rdtgjcaohpblniekmsfq"), "", 20, 0, 19);
+    test(S("ofkqbnjetrmsaidphglc"), "ejanp", 20, 0, 19);
+    test(S("grkpahljcftesdmonqib"), "odife", 20, 1, 19);
+    test(S("jimlgbhfqkteospardcn"), "okaqd", 20, 2, 19);
+    test(S("gftenihpmslrjkqadcob"), "lcdbi", 20, 4, 18);
+    test(S("bmhldogtckrfsanijepq"), "fsqbj", 20, 5, 18);
+    test(S("nfqkrpjdesabgtlcmoih"), "bigdomnplq", 20, 0, 19);
+    test(S("focalnrpiqmdkstehbjg"), "apiblotgcd", 20, 1, 19);
+    test(S("rhqdspkmebiflcotnjga"), "acfhdenops", 20, 5, 18);
+    test(S("rahdtmsckfboqlpniegj"), "jopdeamcrk", 20, 9, 18);
+    test(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, 17);
+    test(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, 19);
+}
+
+void test3()
+{
+    test(S("pboqganrhedjmltsicfk"), "gbkhdnpoietfcmrslajq", 20, 1, 19);
+    test(S("klchabsimetjnqgorfpd"), "rtfnmbsglkjaichoqedp", 20, 10, 19);
+    test(S("sirfgmjqhctndbklaepo"), "ohkmdpfqbsacrtjnlgei", 20, 19, 1);
+    test(S("rlbdsiceaonqjtfpghkm"), "dlbrteoisgphmkncajfq", 20, 20, S::npos);
+    test(S("ecgdanriptblhjfqskom"), "", 21, 0, 19);
+    test(S("fdmiarlpgcskbhoteqjn"), "sjrlo", 21, 0, 19);
+    test(S("rlbstjqopignecmfadkh"), "qjpor", 21, 1, 19);
+    test(S("grjpqmbshektdolcafni"), "odhfn", 21, 2, 19);
+    test(S("sakfcohtqnibprjmlged"), "qtfin", 21, 4, 19);
+    test(S("mjtdglasihqpocebrfkn"), "hpqfo", 21, 5, 19);
+    test(S("okaplfrntghqbmeicsdj"), "fabmertkos", 21, 0, 19);
+    test(S("sahngemrtcjidqbklfpo"), "brqtgkmaej", 21, 1, 19);
+    test(S("dlmsipcnekhbgoaftqjr"), "nfrdeihsgl", 21, 5, 18);
+    test(S("ahegrmqnoiklpfsdbcjt"), "hlfrosekpi", 21, 9, 19);
+    test(S("hdsjbnmlegtkqripacof"), "atgbkrjdsm", 21, 10, 19);
+    test(S("pcnedrfjihqbalkgtoms"), "blnrptjgqmaifsdkhoec", 21, 0, 19);
+    test(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, 19);
+    test(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, 19);
+    test(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, 7);
+    test(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/string_size.pass.cpp
new file mode 100644
index 0000000..c5bb85d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.not.of/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_not_of(const basic_string& str, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.find_last_not_of(str, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.find_last_not_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, S::npos);
+    test(S(""), S("laenf"), 0, S::npos);
+    test(S(""), S("pqlnkmbdjo"), 0, S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), 0, S::npos);
+    test(S(""), S(""), 1, S::npos);
+    test(S(""), S("bjaht"), 1, S::npos);
+    test(S(""), S("hjlcmgpket"), 1, S::npos);
+    test(S(""), S("htaobedqikfplcgjsmrn"), 1, S::npos);
+    test(S("fodgq"), S(""), 0, 0);
+    test(S("qanej"), S("dfkap"), 0, 0);
+    test(S("clbao"), S("ihqrfebgad"), 0, 0);
+    test(S("mekdn"), S("ngtjfcalbseiqrphmkdo"), 0, S::npos);
+    test(S("srdfq"), S(""), 1, 1);
+    test(S("oemth"), S("ikcrq"), 1, 1);
+    test(S("cdaih"), S("dmajblfhsg"), 1, 0);
+    test(S("qohtk"), S("oqftjhdmkgsblacenirp"), 1, S::npos);
+    test(S("cshmd"), S(""), 2, 2);
+    test(S("lhcdo"), S("oebqi"), 2, 2);
+    test(S("qnsoh"), S("kojhpmbsfe"), 2, 1);
+    test(S("pkrof"), S("acbsjqogpltdkhinfrem"), 2, S::npos);
+    test(S("fmtsp"), S(""), 4, 4);
+    test(S("khbpm"), S("aobjd"), 4, 4);
+    test(S("pbsji"), S("pcbahntsje"), 4, 4);
+    test(S("mprdj"), S("fhepcrntkoagbmldqijs"), 4, S::npos);
+    test(S("eqmpa"), S(""), 5, 4);
+    test(S("omigs"), S("kocgb"), 5, 4);
+    test(S("onmje"), S("fbslrjiqkm"), 5, 4);
+    test(S("oqmrj"), S("jeidpcmalhfnqbgtrsko"), 5, S::npos);
+    test(S("schfa"), S(""), 6, 4);
+    test(S("igdsc"), S("qngpd"), 6, 4);
+    test(S("brqgo"), S("rodhqklgmb"), 6, S::npos);
+    test(S("tnrph"), S("thdjgafrlbkoiqcspmne"), 6, S::npos);
+    test(S("hcjitbfapl"), S(""), 0, 0);
+    test(S("daiprenocl"), S("ashjd"), 0, S::npos);
+    test(S("litpcfdghe"), S("mgojkldsqh"), 0, S::npos);
+    test(S("aidjksrolc"), S("imqnaghkfrdtlopbjesc"), 0, S::npos);
+    test(S("qpghtfbaji"), S(""), 1, 1);
+    test(S("gfshlcmdjr"), S("nadkh"), 1, 1);
+    test(S("nkodajteqp"), S("ofdrqmkebl"), 1, 0);
+    test(S("gbmetiprqd"), S("bdfjqgatlksriohemnpc"), 1, S::npos);
+    test(S("crnklpmegd"), S(""), 5, 5);
+    test(S("jsbtafedoc"), S("prqgn"), 5, 5);
+    test(S("qnmodrtkeb"), S("pejafmnokr"), 5, 4);
+    test(S("cpebqsfmnj"), S("odnqkgijrhabfmcestlp"), 5, S::npos);
+    test(S("lmofqdhpki"), S(""), 9, 9);
+    test(S("hnefkqimca"), S("rtjpa"), 9, 8);
+    test(S("drtasbgmfp"), S("ktsrmnqagd"), 9, 9);
+    test(S("lsaijeqhtr"), S("rtdhgcisbnmoaqkfpjle"), 9, S::npos);
+    test(S("elgofjmbrq"), S(""), 10, 9);
+    test(S("mjqdgalkpc"), S("dplqa"), 10, 9);
+    test(S("kthqnfcerm"), S("dkacjoptns"), 10, 9);
+    test(S("dfsjhanorc"), S("hqfimtrgnbekpdcsjalo"), 10, S::npos);
+    test(S("eqsgalomhb"), S(""), 11, 9);
+    test(S("akiteljmoh"), S("lofbc"), 11, 9);
+    test(S("hlbdfreqjo"), S("astoegbfpn"), 11, 8);
+    test(S("taqobhlerg"), S("pdgreqomsncafklhtibj"), 11, S::npos);
+    test(S("snafbdlghrjkpqtoceim"), S(""), 0, 0);
+    test(S("aemtbrgcklhndjisfpoq"), S("lbtqd"), 0, 0);
+    test(S("pnracgfkjdiholtbqsem"), S("tboimldpjh"), 0, S::npos);
+    test(S("dicfltehbsgrmojnpkaq"), S("slcerthdaiqjfnobgkpm"), 0, S::npos);
+    test(S("jlnkraeodhcspfgbqitm"), S(""), 1, 1);
+    test(S("lhosrngtmfjikbqpcade"), S("aqibs"), 1, 1);
+    test(S("rbtaqjhgkneisldpmfoc"), S("gtfblmqinc"), 1, 0);
+    test(S("gpifsqlrdkbonjtmheca"), S("mkqpbtdalgniorhfescj"), 1, S::npos);
+    test(S("hdpkobnsalmcfijregtq"), S(""), 10, 10);
+    test(S("jtlshdgqaiprkbcoenfm"), S("pblas"), 10, 9);
+    test(S("fkdrbqltsgmcoiphneaj"), S("arosdhcfme"), 10, 9);
+    test(S("crsplifgtqedjohnabmk"), S("blkhjeogicatqfnpdmsr"), 10, S::npos);
+    test(S("niptglfbosehkamrdqcj"), S(""), 19, 19);
+    test(S("copqdhstbingamjfkler"), S("djkqc"), 19, 19);
+    test(S("mrtaefilpdsgocnhqbjk"), S("lgokshjtpb"), 19, 16);
+    test(S("kojatdhlcmigpbfrqnes"), S("bqjhtkfepimcnsgrlado"), 19, S::npos);
+    test(S("eaintpchlqsbdgrkjofm"), S(""), 20, 19);
+    test(S("gjnhidfsepkrtaqbmclo"), S("nocfa"), 20, 18);
+    test(S("spocfaktqdbiejlhngmr"), S("bgtajmiedc"), 20, 19);
+    test(S("rphmlekgfscndtaobiqj"), S("lsckfnqgdahejiopbtmr"), 20, S::npos);
+    test(S("liatsqdoegkmfcnbhrpj"), S(""), 21, 19);
+    test(S("binjagtfldkrspcomqeh"), S("gfsrt"), 21, 19);
+    test(S("latkmisecnorjbfhqpdg"), S("pfsocbhjtm"), 21, 19);
+    test(S("lecfratdjkhnsmqpoigb"), S("tpflmdnoicjgkberhqsa"), 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), S(""), S::npos);
+    test(S(""), S("laenf"), S::npos);
+    test(S(""), S("pqlnkmbdjo"), S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), S::npos);
+    test(S("nhmko"), S(""), 4);
+    test(S("lahfb"), S("irkhs"), 4);
+    test(S("gmfhd"), S("kantesmpgj"), 4);
+    test(S("odaft"), S("oknlrstdpiqmjbaghcfe"), S::npos);
+    test(S("eolhfgpjqk"), S(""), 9);
+    test(S("nbatdlmekr"), S("bnrpe"), 8);
+    test(S("jdmciepkaq"), S("jtdaefblso"), 9);
+    test(S("hkbgspoflt"), S("oselktgbcapndfjihrmq"), S::npos);
+    test(S("gprdcokbnjhlsfmtieqa"), S(""), 19);
+    test(S("qjghlnftcaismkropdeb"), S("bjaht"), 18);
+    test(S("pnalfrdtkqcmojiesbhg"), S("hjlcmgpket"), 17);
+    test(S("pniotcfrhqsmgdkjbael"), S("htaobedqikfplcgjsmrn"), S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.of/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/char_size.pass.cpp
new file mode 100644
index 0000000..c678bc6
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_of(charT c, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_last_of(c, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.find_last_of(c) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'm', 0, S::npos);
+    test(S(""), 'm', 1, S::npos);
+    test(S("kitcj"), 'm', 0, S::npos);
+    test(S("qkamf"), 'm', 1, S::npos);
+    test(S("nhmko"), 'm', 2, 2);
+    test(S("tpsaf"), 'm', 4, S::npos);
+    test(S("lahfb"), 'm', 5, S::npos);
+    test(S("irkhs"), 'm', 6, S::npos);
+    test(S("gmfhdaipsr"), 'm', 0, S::npos);
+    test(S("kantesmpgj"), 'm', 1, S::npos);
+    test(S("odaftiegpm"), 'm', 5, S::npos);
+    test(S("oknlrstdpi"), 'm', 9, S::npos);
+    test(S("eolhfgpjqk"), 'm', 10, S::npos);
+    test(S("pcdrofikas"), 'm', 11, S::npos);
+    test(S("nbatdlmekrgcfqsophij"), 'm', 0, S::npos);
+    test(S("bnrpehidofmqtcksjgla"), 'm', 1, S::npos);
+    test(S("jdmciepkaqgotsrfnhlb"), 'm', 10, 2);
+    test(S("jtdaefblsokrmhpgcnqi"), 'm', 19, 12);
+    test(S("hkbgspofltajcnedqmri"), 'm', 20, 17);
+    test(S("oselktgbcapndfjihrmq"), 'm', 21, 18);
+
+    test(S(""), 'm', S::npos);
+    test(S("csope"), 'm', S::npos);
+    test(S("gfsmthlkon"), 'm', 3);
+    test(S("laenfsbridchgotmkqpj"), 'm', 15);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size.pass.cpp
new file mode 100644
index 0000000..36d00d2
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size.pass.cpp
@@ -0,0 +1,146 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_of(const charT* s, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find_last_of(str, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.find_last_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, S::npos);
+    test(S(""), "laenf", 0, S::npos);
+    test(S(""), "pqlnkmbdjo", 0, S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", 0, S::npos);
+    test(S(""), "", 1, S::npos);
+    test(S(""), "bjaht", 1, S::npos);
+    test(S(""), "hjlcmgpket", 1, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 1, S::npos);
+    test(S("fodgq"), "", 0, S::npos);
+    test(S("qanej"), "dfkap", 0, S::npos);
+    test(S("clbao"), "ihqrfebgad", 0, S::npos);
+    test(S("mekdn"), "ngtjfcalbseiqrphmkdo", 0, 0);
+    test(S("srdfq"), "", 1, S::npos);
+    test(S("oemth"), "ikcrq", 1, S::npos);
+    test(S("cdaih"), "dmajblfhsg", 1, 1);
+    test(S("qohtk"), "oqftjhdmkgsblacenirp", 1, 1);
+    test(S("cshmd"), "", 2, S::npos);
+    test(S("lhcdo"), "oebqi", 2, S::npos);
+    test(S("qnsoh"), "kojhpmbsfe", 2, 2);
+    test(S("pkrof"), "acbsjqogpltdkhinfrem", 2, 2);
+    test(S("fmtsp"), "", 4, S::npos);
+    test(S("khbpm"), "aobjd", 4, 2);
+    test(S("pbsji"), "pcbahntsje", 4, 3);
+    test(S("mprdj"), "fhepcrntkoagbmldqijs", 4, 4);
+    test(S("eqmpa"), "", 5, S::npos);
+    test(S("omigs"), "kocgb", 5, 3);
+    test(S("onmje"), "fbslrjiqkm", 5, 3);
+    test(S("oqmrj"), "jeidpcmalhfnqbgtrsko", 5, 4);
+    test(S("schfa"), "", 6, S::npos);
+    test(S("igdsc"), "qngpd", 6, 2);
+    test(S("brqgo"), "rodhqklgmb", 6, 4);
+    test(S("tnrph"), "thdjgafrlbkoiqcspmne", 6, 4);
+    test(S("hcjitbfapl"), "", 0, S::npos);
+    test(S("daiprenocl"), "ashjd", 0, 0);
+    test(S("litpcfdghe"), "mgojkldsqh", 0, 0);
+    test(S("aidjksrolc"), "imqnaghkfrdtlopbjesc", 0, 0);
+    test(S("qpghtfbaji"), "", 1, S::npos);
+    test(S("gfshlcmdjr"), "nadkh", 1, S::npos);
+    test(S("nkodajteqp"), "ofdrqmkebl", 1, 1);
+    test(S("gbmetiprqd"), "bdfjqgatlksriohemnpc", 1, 1);
+    test(S("crnklpmegd"), "", 5, S::npos);
+    test(S("jsbtafedoc"), "prqgn", 5, S::npos);
+    test(S("qnmodrtkeb"), "pejafmnokr", 5, 5);
+    test(S("cpebqsfmnj"), "odnqkgijrhabfmcestlp", 5, 5);
+    test(S("lmofqdhpki"), "", 9, S::npos);
+    test(S("hnefkqimca"), "rtjpa", 9, 9);
+    test(S("drtasbgmfp"), "ktsrmnqagd", 9, 7);
+    test(S("lsaijeqhtr"), "rtdhgcisbnmoaqkfpjle", 9, 9);
+    test(S("elgofjmbrq"), "", 10, S::npos);
+    test(S("mjqdgalkpc"), "dplqa", 10, 8);
+    test(S("kthqnfcerm"), "dkacjoptns", 10, 6);
+    test(S("dfsjhanorc"), "hqfimtrgnbekpdcsjalo", 10, 9);
+    test(S("eqsgalomhb"), "", 11, S::npos);
+    test(S("akiteljmoh"), "lofbc", 11, 8);
+    test(S("hlbdfreqjo"), "astoegbfpn", 11, 9);
+    test(S("taqobhlerg"), "pdgreqomsncafklhtibj", 11, 9);
+    test(S("snafbdlghrjkpqtoceim"), "", 0, S::npos);
+    test(S("aemtbrgcklhndjisfpoq"), "lbtqd", 0, S::npos);
+    test(S("pnracgfkjdiholtbqsem"), "tboimldpjh", 0, 0);
+    test(S("dicfltehbsgrmojnpkaq"), "slcerthdaiqjfnobgkpm", 0, 0);
+    test(S("jlnkraeodhcspfgbqitm"), "", 1, S::npos);
+    test(S("lhosrngtmfjikbqpcade"), "aqibs", 1, S::npos);
+    test(S("rbtaqjhgkneisldpmfoc"), "gtfblmqinc", 1, 1);
+    test(S("gpifsqlrdkbonjtmheca"), "mkqpbtdalgniorhfescj", 1, 1);
+    test(S("hdpkobnsalmcfijregtq"), "", 10, S::npos);
+    test(S("jtlshdgqaiprkbcoenfm"), "pblas", 10, 10);
+    test(S("fkdrbqltsgmcoiphneaj"), "arosdhcfme", 10, 10);
+    test(S("crsplifgtqedjohnabmk"), "blkhjeogicatqfnpdmsr", 10, 10);
+    test(S("niptglfbosehkamrdqcj"), "", 19, S::npos);
+    test(S("copqdhstbingamjfkler"), "djkqc", 19, 16);
+    test(S("mrtaefilpdsgocnhqbjk"), "lgokshjtpb", 19, 19);
+    test(S("kojatdhlcmigpbfrqnes"), "bqjhtkfepimcnsgrlado", 19, 19);
+    test(S("eaintpchlqsbdgrkjofm"), "", 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), "nocfa", 20, 19);
+    test(S("spocfaktqdbiejlhngmr"), "bgtajmiedc", 20, 18);
+    test(S("rphmlekgfscndtaobiqj"), "lsckfnqgdahejiopbtmr", 20, 19);
+    test(S("liatsqdoegkmfcnbhrpj"), "", 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), "gfsrt", 21, 12);
+    test(S("latkmisecnorjbfhqpdg"), "pfsocbhjtm", 21, 17);
+    test(S("lecfratdjkhnsmqpoigb"), "tpflmdnoicjgkberhqsa", 21, 19);
+}
+
+void test1()
+{
+    test(S(""), "", S::npos);
+    test(S(""), "laenf", S::npos);
+    test(S(""), "pqlnkmbdjo", S::npos);
+    test(S(""), "qkamfogpnljdcshbreti", S::npos);
+    test(S("nhmko"), "", S::npos);
+    test(S("lahfb"), "irkhs", 2);
+    test(S("gmfhd"), "kantesmpgj", 1);
+    test(S("odaft"), "oknlrstdpiqmjbaghcfe", 4);
+    test(S("eolhfgpjqk"), "", S::npos);
+    test(S("nbatdlmekr"), "bnrpe", 9);
+    test(S("jdmciepkaq"), "jtdaefblso", 8);
+    test(S("hkbgspoflt"), "oselktgbcapndfjihrmq", 9);
+    test(S("gprdcokbnjhlsfmtieqa"), "", S::npos);
+    test(S("qjghlnftcaismkropdeb"), "bjaht", 19);
+    test(S("pnalfrdtkqcmojiesbhg"), "hjlcmgpket", 19);
+    test(S("pniotcfrhqsmgdkjbael"), "htaobedqikfplcgjsmrn", 19);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..73e854d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_of(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type n, typename S::size_type x)
+{
+    assert(s.find_last_of(str, pos, n) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, S::npos);
+    test(S(""), "irkhs", 0, 0, S::npos);
+    test(S(""), "kante", 0, 1, S::npos);
+    test(S(""), "oknlr", 0, 2, S::npos);
+    test(S(""), "pcdro", 0, 4, S::npos);
+    test(S(""), "bnrpe", 0, 5, S::npos);
+    test(S(""), "jtdaefblso", 0, 0, S::npos);
+    test(S(""), "oselktgbca", 0, 1, S::npos);
+    test(S(""), "eqgaplhckj", 0, 5, S::npos);
+    test(S(""), "bjahtcmnlp", 0, 9, S::npos);
+    test(S(""), "hjlcmgpket", 0, 10, S::npos);
+    test(S(""), "htaobedqikfplcgjsmrn", 0, 0, S::npos);
+    test(S(""), "hpqiarojkcdlsgnmfetb", 0, 1, S::npos);
+    test(S(""), "dfkaprhjloqetcsimnbg", 0, 10, S::npos);
+    test(S(""), "ihqrfebgadntlpmjksoc", 0, 19, S::npos);
+    test(S(""), "ngtjfcalbseiqrphmkdo", 0, 20, S::npos);
+    test(S(""), "", 1, 0, S::npos);
+    test(S(""), "lbtqd", 1, 0, S::npos);
+    test(S(""), "tboim", 1, 1, S::npos);
+    test(S(""), "slcer", 1, 2, S::npos);
+    test(S(""), "cbjfs", 1, 4, S::npos);
+    test(S(""), "aqibs", 1, 5, S::npos);
+    test(S(""), "gtfblmqinc", 1, 0, S::npos);
+    test(S(""), "mkqpbtdalg", 1, 1, S::npos);
+    test(S(""), "kphatlimcd", 1, 5, S::npos);
+    test(S(""), "pblasqogic", 1, 9, S::npos);
+    test(S(""), "arosdhcfme", 1, 10, S::npos);
+    test(S(""), "blkhjeogicatqfnpdmsr", 1, 0, S::npos);
+    test(S(""), "bmhineprjcoadgstflqk", 1, 1, S::npos);
+    test(S(""), "djkqcmetslnghpbarfoi", 1, 10, S::npos);
+    test(S(""), "lgokshjtpbemarcdqnfi", 1, 19, S::npos);
+    test(S(""), "bqjhtkfepimcnsgrlado", 1, 20, S::npos);
+    test(S("eaint"), "", 0, 0, S::npos);
+    test(S("binja"), "gfsrt", 0, 0, S::npos);
+    test(S("latkm"), "pfsoc", 0, 1, S::npos);
+    test(S("lecfr"), "tpflm", 0, 2, S::npos);
+    test(S("eqkst"), "sgkec", 0, 4, 0);
+    test(S("cdafr"), "romds", 0, 5, S::npos);
+    test(S("prbhe"), "qhjistlgmr", 0, 0, S::npos);
+    test(S("lbisk"), "pedfirsglo", 0, 1, S::npos);
+    test(S("hrlpd"), "aqcoslgrmk", 0, 5, S::npos);
+    test(S("ehmja"), "dabckmepqj", 0, 9, 0);
+    test(S("mhqgd"), "pqscrjthli", 0, 10, S::npos);
+    test(S("tgklq"), "kfphdcsjqmobliagtren", 0, 0, S::npos);
+    test(S("bocjs"), "rokpefncljibsdhqtagm", 0, 1, S::npos);
+    test(S("grbsd"), "afionmkphlebtcjqsgrd", 0, 10, S::npos);
+    test(S("ofjqr"), "aenmqplidhkofrjbctsg", 0, 19, 0);
+    test(S("btlfi"), "osjmbtcadhiklegrpqnf", 0, 20, 0);
+    test(S("clrgb"), "", 1, 0, S::npos);
+    test(S("tjmek"), "osmia", 1, 0, S::npos);
+    test(S("bgstp"), "ckonl", 1, 1, S::npos);
+    test(S("hstrk"), "ilcaj", 1, 2, S::npos);
+    test(S("kmspj"), "lasiq", 1, 4, S::npos);
+    test(S("tjboh"), "kfqmr", 1, 5, S::npos);
+    test(S("ilbcj"), "klnitfaobg", 1, 0, S::npos);
+    test(S("jkngf"), "gjhmdlqikp", 1, 1, S::npos);
+    test(S("gfcql"), "skbgtahqej", 1, 5, 0);
+    test(S("dqtlg"), "bjsdgtlpkf", 1, 9, 0);
+    test(S("bthpg"), "bjgfmnlkio", 1, 10, 0);
+    test(S("dgsnq"), "lbhepotfsjdqigcnamkr", 1, 0, S::npos);
+    test(S("rmfhp"), "tebangckmpsrqdlfojhi", 1, 1, S::npos);
+    test(S("jfdam"), "joflqbdkhtegimscpanr", 1, 10, 1);
+    test(S("edapb"), "adpmcohetfbsrjinlqkg", 1, 19, 1);
+    test(S("brfsm"), "iacldqjpfnogbsrhmetk", 1, 20, 1);
+    test(S("ndrhl"), "", 2, 0, S::npos);
+    test(S("mrecp"), "otkgb", 2, 0, S::npos);
+    test(S("qlasf"), "cqsjl", 2, 1, S::npos);
+    test(S("smaqd"), "dpifl", 2, 2, S::npos);
+    test(S("hjeni"), "oapht", 2, 4, 0);
+    test(S("ocmfj"), "cifts", 2, 5, 1);
+    test(S("hmftq"), "nmsckbgalo", 2, 0, S::npos);
+    test(S("fklad"), "tpksqhamle", 2, 1, S::npos);
+    test(S("dirnm"), "tpdrchmkji", 2, 5, 2);
+    test(S("hrgdc"), "ijagfkblst", 2, 9, 2);
+    test(S("ifakg"), "kpocsignjb", 2, 10, 0);
+    test(S("ebrgd"), "pecqtkjsnbdrialgmohf", 2, 0, S::npos);
+    test(S("rcjml"), "aiortphfcmkjebgsndql", 2, 1, S::npos);
+    test(S("peqmt"), "sdbkeamglhipojqftrcn", 2, 10, 1);
+    test(S("frehn"), "ljqncehgmfktroapidbs", 2, 19, 2);
+    test(S("tqolf"), "rtcfodilamkbenjghqps", 2, 20, 2);
+    test(S("cjgao"), "", 4, 0, S::npos);
+    test(S("kjplq"), "mabns", 4, 0, S::npos);
+    test(S("herni"), "bdnrp", 4, 1, S::npos);
+    test(S("tadrb"), "scidp", 4, 2, S::npos);
+    test(S("pkfeo"), "agbjl", 4, 4, S::npos);
+    test(S("hoser"), "jfmpr", 4, 5, 4);
+    test(S("kgrsp"), "rbpefghsmj", 4, 0, S::npos);
+    test(S("pgejb"), "apsfntdoqc", 4, 1, S::npos);
+    test(S("thlnq"), "ndkjeisgcl", 4, 5, 3);
+    test(S("nbmit"), "rnfpqatdeo", 4, 9, 4);
+    test(S("jgmib"), "bntjlqrfik", 4, 10, 4);
+    test(S("ncrfj"), "kcrtmpolnaqejghsfdbi", 4, 0, S::npos);
+    test(S("ncsik"), "lobheanpkmqidsrtcfgj", 4, 1, S::npos);
+    test(S("sgbfh"), "athdkljcnreqbgpmisof", 4, 10, 4);
+    test(S("dktbn"), "qkdmjialrscpbhefgont", 4, 19, 4);
+    test(S("fthqm"), "dmasojntqleribkgfchp", 4, 20, 4);
+    test(S("klopi"), "", 5, 0, S::npos);
+    test(S("dajhn"), "psthd", 5, 0, S::npos);
+    test(S("jbgno"), "rpmjd", 5, 1, S::npos);
+    test(S("hkjae"), "dfsmk", 5, 2, S::npos);
+}
+
+void test1()
+{
+    test(S("gbhqo"), "skqne", 5, 4, 3);
+    test(S("ktdor"), "kipnf", 5, 5, 0);
+    test(S("ldprn"), "hmrnqdgifl", 5, 0, S::npos);
+    test(S("egmjk"), "fsmjcdairn", 5, 1, S::npos);
+    test(S("armql"), "pcdgltbrfj", 5, 5, 4);
+    test(S("cdhjo"), "aekfctpirg", 5, 9, 0);
+    test(S("jcons"), "ledihrsgpf", 5, 10, 4);
+    test(S("cbrkp"), "mqcklahsbtirgopefndj", 5, 0, S::npos);
+    test(S("fhgna"), "kmlthaoqgecrnpdbjfis", 5, 1, S::npos);
+    test(S("ejfcd"), "sfhbamcdptojlkrenqgi", 5, 10, 4);
+    test(S("kqjhe"), "pbniofmcedrkhlstgaqj", 5, 19, 4);
+    test(S("pbdjl"), "mongjratcskbhqiepfdl", 5, 20, 4);
+    test(S("gajqn"), "", 6, 0, S::npos);
+    test(S("stedk"), "hrnat", 6, 0, S::npos);
+    test(S("tjkaf"), "gsqdt", 6, 1, S::npos);
+    test(S("dthpe"), "bspkd", 6, 2, S::npos);
+    test(S("klhde"), "ohcmb", 6, 4, 2);
+    test(S("bhlki"), "heatr", 6, 5, 1);
+    test(S("lqmoh"), "pmblckedfn", 6, 0, S::npos);
+    test(S("mtqin"), "aceqmsrbik", 6, 1, S::npos);
+    test(S("dpqbr"), "lmbtdehjrn", 6, 5, 3);
+    test(S("kdhmo"), "teqmcrlgib", 6, 9, 3);
+    test(S("jblqp"), "njolbmspac", 6, 10, 4);
+    test(S("qmjgl"), "pofnhidklamecrbqjgst", 6, 0, S::npos);
+    test(S("rothp"), "jbhckmtgrqnosafedpli", 6, 1, S::npos);
+    test(S("ghknq"), "dobntpmqklicsahgjerf", 6, 10, 4);
+    test(S("eopfi"), "tpdshainjkbfoemlrgcq", 6, 19, 4);
+    test(S("dsnmg"), "oldpfgeakrnitscbjmqh", 6, 20, 4);
+    test(S("jnkrfhotgl"), "", 0, 0, S::npos);
+    test(S("dltjfngbko"), "rqegt", 0, 0, S::npos);
+    test(S("bmjlpkiqde"), "dashm", 0, 1, S::npos);
+    test(S("skrflobnqm"), "jqirk", 0, 2, S::npos);
+    test(S("jkpldtshrm"), "rckeg", 0, 4, S::npos);
+    test(S("ghasdbnjqo"), "jscie", 0, 5, S::npos);
+    test(S("igrkhpbqjt"), "efsphndliq", 0, 0, S::npos);
+    test(S("ikthdgcamf"), "gdicosleja", 0, 1, S::npos);
+    test(S("pcofgeniam"), "qcpjibosfl", 0, 5, 0);
+    test(S("rlfjgesqhc"), "lrhmefnjcq", 0, 9, 0);
+    test(S("itphbqsker"), "dtablcrseo", 0, 10, S::npos);
+    test(S("skjafcirqm"), "apckjsftedbhgomrnilq", 0, 0, S::npos);
+    test(S("tcqomarsfd"), "pcbrgflehjtiadnsokqm", 0, 1, S::npos);
+    test(S("rocfeldqpk"), "nsiadegjklhobrmtqcpf", 0, 10, S::npos);
+    test(S("cfpegndlkt"), "cpmajdqnolikhgsbretf", 0, 19, 0);
+    test(S("fqbtnkeasj"), "jcflkntmgiqrphdosaeb", 0, 20, 0);
+    test(S("shbcqnmoar"), "", 1, 0, S::npos);
+    test(S("bdoshlmfin"), "ontrs", 1, 0, S::npos);
+    test(S("khfrebnsgq"), "pfkna", 1, 1, S::npos);
+    test(S("getcrsaoji"), "ekosa", 1, 2, 1);
+    test(S("fjiknedcpq"), "anqhk", 1, 4, S::npos);
+    test(S("tkejgnafrm"), "jekca", 1, 5, 1);
+    test(S("jnakolqrde"), "ikemsjgacf", 1, 0, S::npos);
+    test(S("lcjptsmgbe"), "arolgsjkhm", 1, 1, S::npos);
+    test(S("itfsmcjorl"), "oftkbldhre", 1, 5, 1);
+    test(S("omchkfrjea"), "gbkqdoeftl", 1, 9, 0);
+    test(S("cigfqkated"), "sqcflrgtim", 1, 10, 1);
+    test(S("tscenjikml"), "fmhbkislrjdpanogqcet", 1, 0, S::npos);
+    test(S("qcpaemsinf"), "rnioadktqlgpbcjsmhef", 1, 1, S::npos);
+    test(S("gltkojeipd"), "oakgtnldpsefihqmjcbr", 1, 10, 1);
+    test(S("qistfrgnmp"), "gbnaelosidmcjqktfhpr", 1, 19, 1);
+    test(S("bdnpfcqaem"), "akbripjhlosndcmqgfet", 1, 20, 1);
+    test(S("ectnhskflp"), "", 5, 0, S::npos);
+    test(S("fgtianblpq"), "pijag", 5, 0, S::npos);
+    test(S("mfeqklirnh"), "jrckd", 5, 1, S::npos);
+    test(S("astedncjhk"), "qcloh", 5, 2, S::npos);
+    test(S("fhlqgcajbr"), "thlmp", 5, 4, 2);
+    test(S("epfhocmdng"), "qidmo", 5, 5, 4);
+    test(S("apcnsibger"), "lnegpsjqrd", 5, 0, S::npos);
+    test(S("aqkocrbign"), "rjqdablmfs", 5, 1, 5);
+    test(S("ijsmdtqgce"), "enkgpbsjaq", 5, 5, S::npos);
+    test(S("clobgsrken"), "kdsgoaijfh", 5, 9, 5);
+    test(S("jbhcfposld"), "trfqgmckbe", 5, 10, 4);
+    test(S("oqnpblhide"), "igetsracjfkdnpoblhqm", 5, 0, S::npos);
+    test(S("lroeasctif"), "nqctfaogirshlekbdjpm", 5, 1, S::npos);
+    test(S("bpjlgmiedh"), "csehfgomljdqinbartkp", 5, 10, 5);
+    test(S("pamkeoidrj"), "qahoegcmplkfsjbdnitr", 5, 19, 5);
+    test(S("espogqbthk"), "dpteiajrqmsognhlfbkc", 5, 20, 5);
+    test(S("shoiedtcjb"), "", 9, 0, S::npos);
+    test(S("ebcinjgads"), "tqbnh", 9, 0, S::npos);
+    test(S("dqmregkcfl"), "akmle", 9, 1, S::npos);
+    test(S("ngcrieqajf"), "iqfkm", 9, 2, 6);
+    test(S("qosmilgnjb"), "tqjsr", 9, 4, 8);
+    test(S("ikabsjtdfl"), "jplqg", 9, 5, 9);
+    test(S("ersmicafdh"), "oilnrbcgtj", 9, 0, S::npos);
+    test(S("fdnplotmgh"), "morkglpesn", 9, 1, 7);
+    test(S("fdbicojerm"), "dmicerngat", 9, 5, 9);
+    test(S("mbtafndjcq"), "radgeskbtc", 9, 9, 6);
+    test(S("mlenkpfdtc"), "ljikprsmqo", 9, 10, 5);
+    test(S("ahlcifdqgs"), "trqihkcgsjamfdbolnpe", 9, 0, S::npos);
+    test(S("bgjemaltks"), "lqmthbsrekajgnofcipd", 9, 1, 6);
+    test(S("pdhslbqrfc"), "jtalmedribkgqsopcnfh", 9, 10, 7);
+    test(S("dirhtsnjkc"), "spqfoiclmtagejbndkrh", 9, 19, 9);
+    test(S("dlroktbcja"), "nmotklspigjrdhcfaebq", 9, 20, 9);
+    test(S("ncjpmaekbs"), "", 10, 0, S::npos);
+    test(S("hlbosgmrak"), "hpmsd", 10, 0, S::npos);
+    test(S("pqfhsgilen"), "qnpor", 10, 1, 1);
+    test(S("gqtjsbdckh"), "otdma", 10, 2, 2);
+    test(S("cfkqpjlegi"), "efhjg", 10, 4, 7);
+    test(S("beanrfodgj"), "odpte", 10, 5, 7);
+    test(S("adtkqpbjfi"), "bctdgfmolr", 10, 0, S::npos);
+    test(S("iomkfthagj"), "oaklidrbqg", 10, 1, 1);
+}
+
+void test2()
+{
+    test(S("sdpcilonqj"), "dnjfsagktr", 10, 5, 9);
+    test(S("gtfbdkqeml"), "nejaktmiqg", 10, 9, 8);
+    test(S("bmeqgcdorj"), "pjqonlebsf", 10, 10, 9);
+    test(S("etqlcanmob"), "dshmnbtolcjepgaikfqr", 10, 0, S::npos);
+    test(S("roqmkbdtia"), "iogfhpabtjkqlrnemcds", 10, 1, 8);
+    test(S("kadsithljf"), "ngridfabjsecpqltkmoh", 10, 10, 9);
+    test(S("sgtkpbfdmh"), "athmknplcgofrqejsdib", 10, 19, 9);
+    test(S("qgmetnabkl"), "ldobhmqcafnjtkeisgrp", 10, 20, 9);
+    test(S("cqjohampgd"), "", 11, 0, S::npos);
+    test(S("hobitmpsan"), "aocjb", 11, 0, S::npos);
+    test(S("tjehkpsalm"), "jbrnk", 11, 1, 1);
+    test(S("ngfbojitcl"), "tqedg", 11, 2, 7);
+    test(S("rcfkdbhgjo"), "nqskp", 11, 4, 3);
+    test(S("qghptonrea"), "eaqkl", 11, 5, 9);
+    test(S("hnprfgqjdl"), "reaoicljqm", 11, 0, S::npos);
+    test(S("hlmgabenti"), "lsftgajqpm", 11, 1, 1);
+    test(S("ofcjanmrbs"), "rlpfogmits", 11, 5, 7);
+    test(S("jqedtkornm"), "shkncmiaqj", 11, 9, 9);
+    test(S("rfedlasjmg"), "fpnatrhqgs", 11, 10, 9);
+    test(S("talpqjsgkm"), "sjclemqhnpdbgikarfot", 11, 0, S::npos);
+    test(S("lrkcbtqpie"), "otcmedjikgsfnqbrhpla", 11, 1, S::npos);
+    test(S("cipogdskjf"), "bonsaefdqiprkhlgtjcm", 11, 10, 9);
+    test(S("nqedcojahi"), "egpscmahijlfnkrodqtb", 11, 19, 9);
+    test(S("hefnrkmctj"), "kmqbfepjthgilscrndoa", 11, 20, 9);
+    test(S("atqirnmekfjolhpdsgcb"), "", 0, 0, S::npos);
+    test(S("echfkmlpribjnqsaogtd"), "prboq", 0, 0, S::npos);
+    test(S("qnhiftdgcleajbpkrosm"), "fjcqh", 0, 1, S::npos);
+    test(S("chamfknorbedjitgslpq"), "fmosa", 0, 2, S::npos);
+    test(S("njhqpibfmtlkaecdrgso"), "qdbok", 0, 4, S::npos);
+    test(S("ebnghfsqkprmdcljoiat"), "amslg", 0, 5, S::npos);
+    test(S("letjomsgihfrpqbkancd"), "smpltjneqb", 0, 0, S::npos);
+    test(S("nblgoipcrqeaktshjdmf"), "flitskrnge", 0, 1, S::npos);
+    test(S("cehkbngtjoiflqapsmrd"), "pgqihmlbef", 0, 5, S::npos);
+    test(S("mignapfoklbhcqjetdrs"), "cfpdqjtgsb", 0, 9, S::npos);
+    test(S("ceatbhlsqjgpnokfrmdi"), "htpsiaflom", 0, 10, S::npos);
+    test(S("ocihkjgrdelpfnmastqb"), "kpjfiaceghsrdtlbnomq", 0, 0, S::npos);
+    test(S("noelgschdtbrjfmiqkap"), "qhtbomidljgafneksprc", 0, 1, S::npos);
+    test(S("dkclqfombepritjnghas"), "nhtjobkcefldimpsaqgr", 0, 10, S::npos);
+    test(S("miklnresdgbhqcojftap"), "prabcjfqnoeskilmtgdh", 0, 19, 0);
+    test(S("htbcigojaqmdkfrnlsep"), "dtrgmchilkasqoebfpjn", 0, 20, 0);
+    test(S("febhmqtjanokscdirpgl"), "", 1, 0, S::npos);
+    test(S("loakbsqjpcrdhftniegm"), "sqome", 1, 0, S::npos);
+    test(S("reagphsqflbitdcjmkno"), "smfte", 1, 1, S::npos);
+    test(S("jitlfrqemsdhkopncabg"), "ciboh", 1, 2, 1);
+    test(S("mhtaepscdnrjqgbkifol"), "haois", 1, 4, 1);
+    test(S("tocesrfmnglpbjihqadk"), "abfki", 1, 5, S::npos);
+    test(S("lpfmctjrhdagneskbqoi"), "frdkocntmq", 1, 0, S::npos);
+    test(S("lsmqaepkdhncirbtjfgo"), "oasbpedlnr", 1, 1, S::npos);
+    test(S("epoiqmtldrabnkjhcfsg"), "kltqmhgand", 1, 5, S::npos);
+    test(S("emgasrilpknqojhtbdcf"), "gdtfjchpmr", 1, 9, 1);
+    test(S("hnfiagdpcklrjetqbsom"), "ponmcqblet", 1, 10, 1);
+    test(S("nsdfebgajhmtricpoklq"), "sgphqdnofeiklatbcmjr", 1, 0, S::npos);
+    test(S("atjgfsdlpobmeiqhncrk"), "ljqprsmigtfoneadckbh", 1, 1, S::npos);
+    test(S("sitodfgnrejlahcbmqkp"), "ligeojhafnkmrcsqtbdp", 1, 10, 1);
+    test(S("fraghmbiceknltjpqosd"), "lsimqfnjarbopedkhcgt", 1, 19, 1);
+    test(S("pmafenlhqtdbkirjsogc"), "abedmfjlghniorcqptks", 1, 20, 1);
+    test(S("pihgmoeqtnakrjslcbfd"), "", 10, 0, S::npos);
+    test(S("gjdkeprctqblnhiafsom"), "hqtoa", 10, 0, S::npos);
+    test(S("mkpnblfdsahrcqijteog"), "cahif", 10, 1, S::npos);
+    test(S("gckarqnelodfjhmbptis"), "kehis", 10, 2, 7);
+    test(S("gqpskidtbclomahnrjfe"), "kdlmh", 10, 4, 10);
+    test(S("pkldjsqrfgitbhmaecno"), "paeql", 10, 5, 6);
+    test(S("aftsijrbeklnmcdqhgop"), "aghoqiefnb", 10, 0, S::npos);
+    test(S("mtlgdrhafjkbiepqnsoc"), "jrbqaikpdo", 10, 1, 9);
+    test(S("pqgirnaefthokdmbsclj"), "smjonaeqcl", 10, 5, 5);
+    test(S("kpdbgjmtherlsfcqoina"), "eqbdrkcfah", 10, 9, 10);
+    test(S("jrlbothiknqmdgcfasep"), "kapmsienhf", 10, 10, 9);
+    test(S("mjogldqferckabinptsh"), "jpqotrlenfcsbhkaimdg", 10, 0, S::npos);
+    test(S("apoklnefbhmgqcdrisjt"), "jlbmhnfgtcqprikeados", 10, 1, S::npos);
+    test(S("ifeopcnrjbhkdgatmqls"), "stgbhfmdaljnpqoicker", 10, 10, 10);
+    test(S("ckqhaiesmjdnrgolbtpf"), "oihcetflbjagdsrkmqpn", 10, 19, 10);
+    test(S("bnlgapfimcoterskqdjh"), "adtclebmnpjsrqfkigoh", 10, 20, 10);
+    test(S("kgdlrobpmjcthqsafeni"), "", 19, 0, S::npos);
+    test(S("dfkechomjapgnslbtqir"), "beafg", 19, 0, S::npos);
+    test(S("rloadknfbqtgmhcsipje"), "iclat", 19, 1, 16);
+    test(S("mgjhkolrnadqbpetcifs"), "rkhnf", 19, 2, 7);
+    test(S("cmlfakiojdrgtbsphqen"), "clshq", 19, 4, 16);
+    test(S("kghbfipeomsntdalrqjc"), "dtcoj", 19, 5, 19);
+    test(S("eldiqckrnmtasbghjfpo"), "rqosnjmfth", 19, 0, S::npos);
+    test(S("abqjcfedgotihlnspkrm"), "siatdfqglh", 19, 1, 15);
+    test(S("qfbadrtjsimkolcenhpg"), "mrlshtpgjq", 19, 5, 17);
+    test(S("abseghclkjqifmtodrnp"), "adlcskgqjt", 19, 9, 16);
+    test(S("ibmsnlrjefhtdokacqpg"), "drshcjknaf", 19, 10, 16);
+    test(S("mrkfciqjebaponsthldg"), "etsaqroinghpkjdlfcbm", 19, 0, S::npos);
+    test(S("mjkticdeoqshpalrfbgn"), "sgepdnkqliambtrocfhj", 19, 1, 10);
+    test(S("rqnoclbdejgiphtfsakm"), "nlmcjaqgbsortfdihkpe", 19, 10, 19);
+    test(S("plkqbhmtfaeodjcrsing"), "racfnpmosldibqkghjet", 19, 19, 19);
+    test(S("oegalhmstjrfickpbndq"), "fjhdsctkqeiolagrnmbp", 19, 20, 19);
+    test(S("rdtgjcaohpblniekmsfq"), "", 20, 0, S::npos);
+    test(S("ofkqbnjetrmsaidphglc"), "ejanp", 20, 0, S::npos);
+    test(S("grkpahljcftesdmonqib"), "odife", 20, 1, 15);
+    test(S("jimlgbhfqkteospardcn"), "okaqd", 20, 2, 12);
+    test(S("gftenihpmslrjkqadcob"), "lcdbi", 20, 4, 19);
+    test(S("bmhldogtckrfsanijepq"), "fsqbj", 20, 5, 19);
+    test(S("nfqkrpjdesabgtlcmoih"), "bigdomnplq", 20, 0, S::npos);
+    test(S("focalnrpiqmdkstehbjg"), "apiblotgcd", 20, 1, 3);
+    test(S("rhqdspkmebiflcotnjga"), "acfhdenops", 20, 5, 19);
+    test(S("rahdtmsckfboqlpniegj"), "jopdeamcrk", 20, 9, 19);
+    test(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, 19);
+    test(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos);
+}
+
+void test3()
+{
+    test(S("pboqganrhedjmltsicfk"), "gbkhdnpoietfcmrslajq", 20, 1, 4);
+    test(S("klchabsimetjnqgorfpd"), "rtfnmbsglkjaichoqedp", 20, 10, 17);
+    test(S("sirfgmjqhctndbklaepo"), "ohkmdpfqbsacrtjnlgei", 20, 19, 19);
+    test(S("rlbdsiceaonqjtfpghkm"), "dlbrteoisgphmkncajfq", 20, 20, 19);
+    test(S("ecgdanriptblhjfqskom"), "", 21, 0, S::npos);
+    test(S("fdmiarlpgcskbhoteqjn"), "sjrlo", 21, 0, S::npos);
+    test(S("rlbstjqopignecmfadkh"), "qjpor", 21, 1, 6);
+    test(S("grjpqmbshektdolcafni"), "odhfn", 21, 2, 13);
+    test(S("sakfcohtqnibprjmlged"), "qtfin", 21, 4, 10);
+    test(S("mjtdglasihqpocebrfkn"), "hpqfo", 21, 5, 17);
+    test(S("okaplfrntghqbmeicsdj"), "fabmertkos", 21, 0, S::npos);
+    test(S("sahngemrtcjidqbklfpo"), "brqtgkmaej", 21, 1, 14);
+    test(S("dlmsipcnekhbgoaftqjr"), "nfrdeihsgl", 21, 5, 19);
+    test(S("ahegrmqnoiklpfsdbcjt"), "hlfrosekpi", 21, 9, 14);
+    test(S("hdsjbnmlegtkqripacof"), "atgbkrjdsm", 21, 10, 16);
+    test(S("pcnedrfjihqbalkgtoms"), "blnrptjgqmaifsdkhoec", 21, 0, S::npos);
+    test(S("qjidealmtpskrbfhocng"), "ctpmdahebfqjgknloris", 21, 1, 17);
+    test(S("qeindtagmokpfhsclrbj"), "apnkeqthrmlbfodiscgj", 21, 10, 17);
+    test(S("kpfegbjhsrnodltqciam"), "jdgictpframeoqlsbknh", 21, 19, 19);
+    test(S("hnbrcplsjfgiktoedmaq"), "qprlsfojamgndekthibc", 21, 20, 19);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find.last.of/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/string_size.pass.cpp
new file mode 100644
index 0000000..414e564
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find.last.of/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find_last_of(const basic_string& str, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.find_last_of(str, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x < s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.find_last_of(str) == x);
+    if (x != S::npos)
+        assert(x < s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, S::npos);
+    test(S(""), S("laenf"), 0, S::npos);
+    test(S(""), S("pqlnkmbdjo"), 0, S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), 0, S::npos);
+    test(S(""), S(""), 1, S::npos);
+    test(S(""), S("bjaht"), 1, S::npos);
+    test(S(""), S("hjlcmgpket"), 1, S::npos);
+    test(S(""), S("htaobedqikfplcgjsmrn"), 1, S::npos);
+    test(S("fodgq"), S(""), 0, S::npos);
+    test(S("qanej"), S("dfkap"), 0, S::npos);
+    test(S("clbao"), S("ihqrfebgad"), 0, S::npos);
+    test(S("mekdn"), S("ngtjfcalbseiqrphmkdo"), 0, 0);
+    test(S("srdfq"), S(""), 1, S::npos);
+    test(S("oemth"), S("ikcrq"), 1, S::npos);
+    test(S("cdaih"), S("dmajblfhsg"), 1, 1);
+    test(S("qohtk"), S("oqftjhdmkgsblacenirp"), 1, 1);
+    test(S("cshmd"), S(""), 2, S::npos);
+    test(S("lhcdo"), S("oebqi"), 2, S::npos);
+    test(S("qnsoh"), S("kojhpmbsfe"), 2, 2);
+    test(S("pkrof"), S("acbsjqogpltdkhinfrem"), 2, 2);
+    test(S("fmtsp"), S(""), 4, S::npos);
+    test(S("khbpm"), S("aobjd"), 4, 2);
+    test(S("pbsji"), S("pcbahntsje"), 4, 3);
+    test(S("mprdj"), S("fhepcrntkoagbmldqijs"), 4, 4);
+    test(S("eqmpa"), S(""), 5, S::npos);
+    test(S("omigs"), S("kocgb"), 5, 3);
+    test(S("onmje"), S("fbslrjiqkm"), 5, 3);
+    test(S("oqmrj"), S("jeidpcmalhfnqbgtrsko"), 5, 4);
+    test(S("schfa"), S(""), 6, S::npos);
+    test(S("igdsc"), S("qngpd"), 6, 2);
+    test(S("brqgo"), S("rodhqklgmb"), 6, 4);
+    test(S("tnrph"), S("thdjgafrlbkoiqcspmne"), 6, 4);
+    test(S("hcjitbfapl"), S(""), 0, S::npos);
+    test(S("daiprenocl"), S("ashjd"), 0, 0);
+    test(S("litpcfdghe"), S("mgojkldsqh"), 0, 0);
+    test(S("aidjksrolc"), S("imqnaghkfrdtlopbjesc"), 0, 0);
+    test(S("qpghtfbaji"), S(""), 1, S::npos);
+    test(S("gfshlcmdjr"), S("nadkh"), 1, S::npos);
+    test(S("nkodajteqp"), S("ofdrqmkebl"), 1, 1);
+    test(S("gbmetiprqd"), S("bdfjqgatlksriohemnpc"), 1, 1);
+    test(S("crnklpmegd"), S(""), 5, S::npos);
+    test(S("jsbtafedoc"), S("prqgn"), 5, S::npos);
+    test(S("qnmodrtkeb"), S("pejafmnokr"), 5, 5);
+    test(S("cpebqsfmnj"), S("odnqkgijrhabfmcestlp"), 5, 5);
+    test(S("lmofqdhpki"), S(""), 9, S::npos);
+    test(S("hnefkqimca"), S("rtjpa"), 9, 9);
+    test(S("drtasbgmfp"), S("ktsrmnqagd"), 9, 7);
+    test(S("lsaijeqhtr"), S("rtdhgcisbnmoaqkfpjle"), 9, 9);
+    test(S("elgofjmbrq"), S(""), 10, S::npos);
+    test(S("mjqdgalkpc"), S("dplqa"), 10, 8);
+    test(S("kthqnfcerm"), S("dkacjoptns"), 10, 6);
+    test(S("dfsjhanorc"), S("hqfimtrgnbekpdcsjalo"), 10, 9);
+    test(S("eqsgalomhb"), S(""), 11, S::npos);
+    test(S("akiteljmoh"), S("lofbc"), 11, 8);
+    test(S("hlbdfreqjo"), S("astoegbfpn"), 11, 9);
+    test(S("taqobhlerg"), S("pdgreqomsncafklhtibj"), 11, 9);
+    test(S("snafbdlghrjkpqtoceim"), S(""), 0, S::npos);
+    test(S("aemtbrgcklhndjisfpoq"), S("lbtqd"), 0, S::npos);
+    test(S("pnracgfkjdiholtbqsem"), S("tboimldpjh"), 0, 0);
+    test(S("dicfltehbsgrmojnpkaq"), S("slcerthdaiqjfnobgkpm"), 0, 0);
+    test(S("jlnkraeodhcspfgbqitm"), S(""), 1, S::npos);
+    test(S("lhosrngtmfjikbqpcade"), S("aqibs"), 1, S::npos);
+    test(S("rbtaqjhgkneisldpmfoc"), S("gtfblmqinc"), 1, 1);
+    test(S("gpifsqlrdkbonjtmheca"), S("mkqpbtdalgniorhfescj"), 1, 1);
+    test(S("hdpkobnsalmcfijregtq"), S(""), 10, S::npos);
+    test(S("jtlshdgqaiprkbcoenfm"), S("pblas"), 10, 10);
+    test(S("fkdrbqltsgmcoiphneaj"), S("arosdhcfme"), 10, 10);
+    test(S("crsplifgtqedjohnabmk"), S("blkhjeogicatqfnpdmsr"), 10, 10);
+    test(S("niptglfbosehkamrdqcj"), S(""), 19, S::npos);
+    test(S("copqdhstbingamjfkler"), S("djkqc"), 19, 16);
+    test(S("mrtaefilpdsgocnhqbjk"), S("lgokshjtpb"), 19, 19);
+    test(S("kojatdhlcmigpbfrqnes"), S("bqjhtkfepimcnsgrlado"), 19, 19);
+    test(S("eaintpchlqsbdgrkjofm"), S(""), 20, S::npos);
+    test(S("gjnhidfsepkrtaqbmclo"), S("nocfa"), 20, 19);
+    test(S("spocfaktqdbiejlhngmr"), S("bgtajmiedc"), 20, 18);
+    test(S("rphmlekgfscndtaobiqj"), S("lsckfnqgdahejiopbtmr"), 20, 19);
+    test(S("liatsqdoegkmfcnbhrpj"), S(""), 21, S::npos);
+    test(S("binjagtfldkrspcomqeh"), S("gfsrt"), 21, 12);
+    test(S("latkmisecnorjbfhqpdg"), S("pfsocbhjtm"), 21, 17);
+    test(S("lecfratdjkhnsmqpoigb"), S("tpflmdnoicjgkberhqsa"), 21, 19);
+}
+
+void test1()
+{
+    test(S(""), S(""), S::npos);
+    test(S(""), S("laenf"), S::npos);
+    test(S(""), S("pqlnkmbdjo"), S::npos);
+    test(S(""), S("qkamfogpnljdcshbreti"), S::npos);
+    test(S("nhmko"), S(""), S::npos);
+    test(S("lahfb"), S("irkhs"), 2);
+    test(S("gmfhd"), S("kantesmpgj"), 1);
+    test(S("odaft"), S("oknlrstdpiqmjbaghcfe"), 4);
+    test(S("eolhfgpjqk"), S(""), S::npos);
+    test(S("nbatdlmekr"), S("bnrpe"), 9);
+    test(S("jdmciepkaq"), S("jtdaefblso"), 8);
+    test(S("hkbgspoflt"), S("oselktgbcapndfjihrmq"), 9);
+    test(S("gprdcokbnjhlsfmtieqa"), S(""), S::npos);
+    test(S("qjghlnftcaismkropdeb"), S("bjaht"), 19);
+    test(S("pnalfrdtkqcmojiesbhg"), S("hjlcmgpket"), 19);
+    test(S("pniotcfrhqsmgdkjbael"), S("htaobedqikfplcgjsmrn"), 19);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find/char_size.pass.cpp
new file mode 100644
index 0000000..b60b157
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find(charT c, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find(c, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x + 1 <= s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.find(c) == x);
+    if (x != S::npos)
+        assert(0 <= x && x + 1 <= s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'c', 0, S::npos);
+    test(S(""), 'c', 1, S::npos);
+    test(S("abcde"), 'c', 0, 2);
+    test(S("abcde"), 'c', 1, 2);
+    test(S("abcde"), 'c', 2, 2);
+    test(S("abcde"), 'c', 4, S::npos);
+    test(S("abcde"), 'c', 5, S::npos);
+    test(S("abcde"), 'c', 6, S::npos);
+    test(S("abcdeabcde"), 'c', 0, 2);
+    test(S("abcdeabcde"), 'c', 1, 2);
+    test(S("abcdeabcde"), 'c', 5, 7);
+    test(S("abcdeabcde"), 'c', 9, S::npos);
+    test(S("abcdeabcde"), 'c', 10, S::npos);
+    test(S("abcdeabcde"), 'c', 11, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 0, 2);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 1, 2);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 10, 12);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 21, S::npos);
+
+    test(S(""), 'c', S::npos);
+    test(S("abcde"), 'c', 2);
+    test(S("abcdeabcde"), 'c', 2);
+    test(S("abcdeabcdeabcdeabcde"), 'c', 2);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size.pass.cpp
new file mode 100644
index 0000000..f05dd5d
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size.pass.cpp
@@ -0,0 +1,152 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find(const charT* s, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.find(str, pos) == x);
+    if (x != S::npos)
+    {
+        typename S::size_type n = S::traits_type::length(str);
+        assert(pos <= x && x + n <= s.size());
+    }
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.find(str) == x);
+    if (x != S::npos)
+    {
+        typename S::size_type n = S::traits_type::length(str);
+        assert(0 <= x && x + n <= s.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0);
+    test(S(""), "abcde", 0, S::npos);
+    test(S(""), "abcdeabcde", 0, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S(""), "", 1, S::npos);
+    test(S(""), "abcde", 1, S::npos);
+    test(S(""), "abcdeabcde", 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcde"), "", 0, 0);
+    test(S("abcde"), "abcde", 0, 0);
+    test(S("abcde"), "abcdeabcde", 0, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S("abcde"), "", 1, 1);
+    test(S("abcde"), "abcde", 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcde"), "", 2, 2);
+    test(S("abcde"), "abcde", 2, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, S::npos);
+    test(S("abcde"), "", 4, 4);
+    test(S("abcde"), "abcde", 4, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, S::npos);
+    test(S("abcde"), "", 5, 5);
+    test(S("abcde"), "abcde", 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
+    test(S("abcde"), "", 6, S::npos);
+    test(S("abcde"), "abcde", 6, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, S::npos);
+    test(S("abcdeabcde"), "", 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S("abcdeabcde"), "", 1, 1);
+    test(S("abcdeabcde"), "abcde", 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcdeabcde"), "", 5, 5);
+    test(S("abcdeabcde"), "abcde", 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
+    test(S("abcdeabcde"), "", 9, 9);
+    test(S("abcdeabcde"), "abcde", 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, S::npos);
+    test(S("abcdeabcde"), "", 10, 10);
+    test(S("abcdeabcde"), "abcde", 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
+    test(S("abcdeabcde"), "", 11, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 1, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 19, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 20, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), "", 0);
+    test(S(""), "abcde", S::npos);
+    test(S(""), "abcdeabcde", S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcde"), "", 0);
+    test(S("abcde"), "abcde", 0);
+    test(S("abcde"), "abcdeabcde", S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcdeabcde"), "", 0);
+    test(S("abcdeabcde"), "abcde", 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..3c39a92
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type n, typename S::size_type x)
+{
+    assert(s.find(str, pos, n) == x);
+    if (x != S::npos)
+        assert(pos <= x && x + n <= s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, 0);
+    test(S(""), "abcde", 0, 0, 0);
+    test(S(""), "abcde", 0, 1, S::npos);
+    test(S(""), "abcde", 0, 2, S::npos);
+    test(S(""), "abcde", 0, 4, S::npos);
+    test(S(""), "abcde", 0, 5, S::npos);
+    test(S(""), "abcdeabcde", 0, 0, 0);
+    test(S(""), "abcdeabcde", 0, 1, S::npos);
+    test(S(""), "abcdeabcde", 0, 5, S::npos);
+    test(S(""), "abcdeabcde", 0, 9, S::npos);
+    test(S(""), "abcdeabcde", 0, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S(""), "", 1, 0, S::npos);
+    test(S(""), "abcde", 1, 0, S::npos);
+    test(S(""), "abcde", 1, 1, S::npos);
+    test(S(""), "abcde", 1, 2, S::npos);
+    test(S(""), "abcde", 1, 4, S::npos);
+    test(S(""), "abcde", 1, 5, S::npos);
+    test(S(""), "abcdeabcde", 1, 0, S::npos);
+    test(S(""), "abcdeabcde", 1, 1, S::npos);
+    test(S(""), "abcdeabcde", 1, 5, S::npos);
+    test(S(""), "abcdeabcde", 1, 9, S::npos);
+    test(S(""), "abcdeabcde", 1, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 0, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcde"), "", 0, 0, 0);
+    test(S("abcde"), "abcde", 0, 0, 0);
+    test(S("abcde"), "abcde", 0, 1, 0);
+    test(S("abcde"), "abcde", 0, 2, 0);
+    test(S("abcde"), "abcde", 0, 4, 0);
+    test(S("abcde"), "abcde", 0, 5, 0);
+    test(S("abcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcde"), "abcdeabcde", 0, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 0, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S("abcde"), "", 1, 0, 1);
+    test(S("abcde"), "abcde", 1, 0, 1);
+    test(S("abcde"), "abcde", 1, 1, S::npos);
+    test(S("abcde"), "abcde", 1, 2, S::npos);
+    test(S("abcde"), "abcde", 1, 4, S::npos);
+    test(S("abcde"), "abcde", 1, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcde"), "abcdeabcde", 1, 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcde"), "", 2, 0, 2);
+    test(S("abcde"), "abcde", 2, 0, 2);
+    test(S("abcde"), "abcde", 2, 1, S::npos);
+    test(S("abcde"), "abcde", 2, 2, S::npos);
+    test(S("abcde"), "abcde", 2, 4, S::npos);
+    test(S("abcde"), "abcde", 2, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, 0, 2);
+    test(S("abcde"), "abcdeabcde", 2, 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 0, 2);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 20, S::npos);
+    test(S("abcde"), "", 4, 0, 4);
+    test(S("abcde"), "abcde", 4, 0, 4);
+    test(S("abcde"), "abcde", 4, 1, S::npos);
+    test(S("abcde"), "abcde", 4, 2, S::npos);
+    test(S("abcde"), "abcde", 4, 4, S::npos);
+    test(S("abcde"), "abcde", 4, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, 0, 4);
+    test(S("abcde"), "abcdeabcde", 4, 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 0, 4);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 20, S::npos);
+    test(S("abcde"), "", 5, 0, 5);
+    test(S("abcde"), "abcde", 5, 0, 5);
+    test(S("abcde"), "abcde", 5, 1, S::npos);
+    test(S("abcde"), "abcde", 5, 2, S::npos);
+}
+
+void test1()
+{
+    test(S("abcde"), "abcde", 5, 4, S::npos);
+    test(S("abcde"), "abcde", 5, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, 0, 5);
+    test(S("abcde"), "abcdeabcde", 5, 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 0, 5);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 20, S::npos);
+    test(S("abcde"), "", 6, 0, S::npos);
+    test(S("abcde"), "abcde", 6, 0, S::npos);
+    test(S("abcde"), "abcde", 6, 1, S::npos);
+    test(S("abcde"), "abcde", 6, 2, S::npos);
+    test(S("abcde"), "abcde", 6, 4, S::npos);
+    test(S("abcde"), "abcde", 6, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 0, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 1, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 5, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 0, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 20, S::npos);
+    test(S("abcdeabcde"), "", 0, 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcde", 0, 2, 0);
+    test(S("abcdeabcde"), "abcde", 0, 4, 0);
+    test(S("abcdeabcde"), "abcde", 0, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S("abcdeabcde"), "", 1, 0, 1);
+    test(S("abcdeabcde"), "abcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcde", 1, 1, 5);
+    test(S("abcdeabcde"), "abcde", 1, 2, 5);
+    test(S("abcdeabcde"), "abcde", 1, 4, 5);
+    test(S("abcdeabcde"), "abcde", 1, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcdeabcde"), "", 5, 0, 5);
+    test(S("abcdeabcde"), "abcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcde", 5, 2, 5);
+    test(S("abcdeabcde"), "abcde", 5, 4, 5);
+    test(S("abcdeabcde"), "abcde", 5, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 20, S::npos);
+    test(S("abcdeabcde"), "", 9, 0, 9);
+    test(S("abcdeabcde"), "abcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcde", 9, 1, S::npos);
+    test(S("abcdeabcde"), "abcde", 9, 2, S::npos);
+    test(S("abcdeabcde"), "abcde", 9, 4, S::npos);
+    test(S("abcdeabcde"), "abcde", 9, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 20, S::npos);
+    test(S("abcdeabcde"), "", 10, 0, 10);
+    test(S("abcdeabcde"), "abcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcde", 10, 1, S::npos);
+    test(S("abcdeabcde"), "abcde", 10, 2, S::npos);
+    test(S("abcdeabcde"), "abcde", 10, 4, S::npos);
+    test(S("abcdeabcde"), "abcde", 10, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 1, S::npos);
+}
+
+void test2()
+{
+    test(S("abcdeabcde"), "abcdeabcde", 10, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 20, S::npos);
+    test(S("abcdeabcde"), "", 11, 0, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, 0, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, 1, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, 2, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, 4, S::npos);
+    test(S("abcdeabcde"), "abcde", 11, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 0, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 5, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 9, S::npos);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 0, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 1, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 10, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 2, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 4, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 9, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 2, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 4, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 5, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 5, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 9, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 10, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 10, 5);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 2, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 4, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 5, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 5, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 9, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 2, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 4, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 9, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 2, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 4, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 9, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20);
+}
+
+void test3()
+{
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 21, 0, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 0, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 2, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 4, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 0, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 5, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 9, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 0, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 20, S::npos);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::find/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::find/string_size.pass.cpp
new file mode 100644
index 0000000..802d249
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::find/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type find(const basic_string& str, size_type pos = 0) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.find(str, pos) == x);
+    if (x != S::npos)
+        assert(pos <= x && x + str.size() <= s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.find(str) == x);
+    if (x != S::npos)
+        assert(0 <= x && x + str.size() <= s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, 0);
+    test(S(""), S("abcde"), 0, S::npos);
+    test(S(""), S("abcdeabcde"), 0, S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S(""), S(""), 1, S::npos);
+    test(S(""), S("abcde"), 1, S::npos);
+    test(S(""), S("abcdeabcde"), 1, S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcde"), S(""), 0, 0);
+    test(S("abcde"), S("abcde"), 0, 0);
+    test(S("abcde"), S("abcdeabcde"), 0, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S("abcde"), S(""), 1, 1);
+    test(S("abcde"), S("abcde"), 1, S::npos);
+    test(S("abcde"), S("abcdeabcde"), 1, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcde"), S(""), 2, 2);
+    test(S("abcde"), S("abcde"), 2, S::npos);
+    test(S("abcde"), S("abcdeabcde"), 2, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 2, S::npos);
+    test(S("abcde"), S(""), 4, 4);
+    test(S("abcde"), S("abcde"), 4, S::npos);
+    test(S("abcde"), S("abcdeabcde"), 4, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 4, S::npos);
+    test(S("abcde"), S(""), 5, 5);
+    test(S("abcde"), S("abcde"), 5, S::npos);
+    test(S("abcde"), S("abcdeabcde"), 5, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 5, S::npos);
+    test(S("abcde"), S(""), 6, S::npos);
+    test(S("abcde"), S("abcde"), 6, S::npos);
+    test(S("abcde"), S("abcdeabcde"), 6, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 6, S::npos);
+    test(S("abcdeabcde"), S(""), 0, 0);
+    test(S("abcdeabcde"), S("abcde"), 0, 0);
+    test(S("abcdeabcde"), S("abcdeabcde"), 0, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S("abcdeabcde"), S(""), 1, 1);
+    test(S("abcdeabcde"), S("abcde"), 1, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 1, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcdeabcde"), S(""), 5, 5);
+    test(S("abcdeabcde"), S("abcde"), 5, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 5, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 5, S::npos);
+    test(S("abcdeabcde"), S(""), 9, 9);
+    test(S("abcdeabcde"), S("abcde"), 9, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcde"), 9, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 9, S::npos);
+    test(S("abcdeabcde"), S(""), 10, 10);
+    test(S("abcdeabcde"), S("abcde"), 10, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcde"), 10, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 10, S::npos);
+    test(S("abcdeabcde"), S(""), 11, S::npos);
+    test(S("abcdeabcde"), S("abcde"), 11, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcde"), 11, S::npos);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 11, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 1, 1);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 1, 5);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 10, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 19, 19);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 19, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 20, 20);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 21, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 21, S::npos);
+}
+
+void test1()
+{
+    test(S(""), S(""), 0);
+    test(S(""), S("abcde"), S::npos);
+    test(S(""), S("abcdeabcde"), S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcde"), S(""), 0);
+    test(S("abcde"), S("abcde"), 0);
+    test(S("abcde"), S("abcdeabcde"), S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcdeabcde"), S(""), 0);
+    test(S("abcdeabcde"), S("abcde"), 0);
+    test(S("abcdeabcde"), S("abcdeabcde"), 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::rfind/char_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::rfind/char_size.pass.cpp
new file mode 100644
index 0000000..a23c718
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::rfind/char_size.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type rfind(charT c, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.rfind(c, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x + 1 <= s.size());
+}
+
+template <class S>
+void
+test(const S& s, typename S::value_type c, typename S::size_type x)
+{
+    assert(s.rfind(c) == x);
+    if (x != S::npos)
+        assert(x + 1 <= s.size());
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 'b', 0, S::npos);
+    test(S(""), 'b', 1, S::npos);
+    test(S("abcde"), 'b', 0, S::npos);
+    test(S("abcde"), 'b', 1, 1);
+    test(S("abcde"), 'b', 2, 1);
+    test(S("abcde"), 'b', 4, 1);
+    test(S("abcde"), 'b', 5, 1);
+    test(S("abcde"), 'b', 6, 1);
+    test(S("abcdeabcde"), 'b', 0, S::npos);
+    test(S("abcdeabcde"), 'b', 1, 1);
+    test(S("abcdeabcde"), 'b', 5, 1);
+    test(S("abcdeabcde"), 'b', 9, 6);
+    test(S("abcdeabcde"), 'b', 10, 6);
+    test(S("abcdeabcde"), 'b', 11, 6);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 0, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 1, 1);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 10, 6);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 19, 16);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 20, 16);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 21, 16);
+
+    test(S(""), 'b', S::npos);
+    test(S("abcde"), 'b', 1);
+    test(S("abcdeabcde"), 'b', 6);
+    test(S("abcdeabcdeabcdeabcde"), 'b', 16);
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size.pass.cpp
new file mode 100644
index 0000000..2999d7f
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size.pass.cpp
@@ -0,0 +1,153 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type rfind(const charT* s, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+     typename S::size_type x)
+{
+    assert(s.rfind(str, pos) == x);
+    if (x != S::npos)
+    {
+        typename S::size_type n = S::traits_type::length(str);
+        assert(x <= pos && x + n <= s.size());
+    }
+}
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type x)
+{
+    assert(s.rfind(str) == x);
+    if (x != S::npos)
+    {
+        typename S::size_type pos = s.size();
+        typename S::size_type n = S::traits_type::length(str);
+        assert(x <= pos && x + n <= s.size());
+    }
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0);
+    test(S(""), "abcde", 0, S::npos);
+    test(S(""), "abcdeabcde", 0, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S(""), "", 1, 0);
+    test(S(""), "abcde", 1, S::npos);
+    test(S(""), "abcdeabcde", 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcde"), "", 0, 0);
+    test(S("abcde"), "abcde", 0, 0);
+    test(S("abcde"), "abcdeabcde", 0, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S("abcde"), "", 1, 1);
+    test(S("abcde"), "abcde", 1, 0);
+    test(S("abcde"), "abcdeabcde", 1, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcde"), "", 2, 2);
+    test(S("abcde"), "abcde", 2, 0);
+    test(S("abcde"), "abcdeabcde", 2, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, S::npos);
+    test(S("abcde"), "", 4, 4);
+    test(S("abcde"), "abcde", 4, 0);
+    test(S("abcde"), "abcdeabcde", 4, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, S::npos);
+    test(S("abcde"), "", 5, 5);
+    test(S("abcde"), "abcde", 5, 0);
+    test(S("abcde"), "abcdeabcde", 5, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
+    test(S("abcde"), "", 6, 5);
+    test(S("abcde"), "abcde", 6, 0);
+    test(S("abcde"), "abcdeabcde", 6, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, S::npos);
+    test(S("abcdeabcde"), "", 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, S::npos);
+    test(S("abcdeabcde"), "", 1, 1);
+    test(S("abcdeabcde"), "abcde", 1, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, S::npos);
+    test(S("abcdeabcde"), "", 5, 5);
+    test(S("abcdeabcde"), "abcde", 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, S::npos);
+    test(S("abcdeabcde"), "", 9, 9);
+    test(S("abcdeabcde"), "abcde", 9, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, S::npos);
+    test(S("abcdeabcde"), "", 10, 10);
+    test(S("abcdeabcde"), "abcde", 10, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, S::npos);
+    test(S("abcdeabcde"), "", 11, 10);
+    test(S("abcdeabcde"), "abcde", 11, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 1, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 19, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 20, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 21, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 0);
+}
+
+void test1()
+{
+    test(S(""), "", 0);
+    test(S(""), "abcde", S::npos);
+    test(S(""), "abcdeabcde", S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcde"), "", 5);
+    test(S("abcde"), "abcde", 0);
+    test(S("abcde"), "abcdeabcde", S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcdeabcde"), "", 10);
+    test(S("abcdeabcde"), "abcde", 5);
+    test(S("abcdeabcde"), "abcdeabcde", 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size_size.pass.cpp
new file mode 100644
index 0000000..7ed8b80
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::rfind/pointer_size_size.pass.cpp
@@ -0,0 +1,371 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type rfind(const charT* s, size_type pos, size_type n) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const typename S::value_type* str, typename S::size_type pos,
+      typename S::size_type n, typename S::size_type x)
+{
+    assert(s.rfind(str, pos, n) == x);
+    if (x != S::npos)
+        assert(x <= pos && x + n <= s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), "", 0, 0, 0);
+    test(S(""), "abcde", 0, 0, 0);
+    test(S(""), "abcde", 0, 1, S::npos);
+    test(S(""), "abcde", 0, 2, S::npos);
+    test(S(""), "abcde", 0, 4, S::npos);
+    test(S(""), "abcde", 0, 5, S::npos);
+    test(S(""), "abcdeabcde", 0, 0, 0);
+    test(S(""), "abcdeabcde", 0, 1, S::npos);
+    test(S(""), "abcdeabcde", 0, 5, S::npos);
+    test(S(""), "abcdeabcde", 0, 9, S::npos);
+    test(S(""), "abcdeabcde", 0, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S(""), "", 1, 0, 0);
+    test(S(""), "abcde", 1, 0, 0);
+    test(S(""), "abcde", 1, 1, S::npos);
+    test(S(""), "abcde", 1, 2, S::npos);
+    test(S(""), "abcde", 1, 4, S::npos);
+    test(S(""), "abcde", 1, 5, S::npos);
+    test(S(""), "abcdeabcde", 1, 0, 0);
+    test(S(""), "abcdeabcde", 1, 1, S::npos);
+    test(S(""), "abcdeabcde", 1, 5, S::npos);
+    test(S(""), "abcdeabcde", 1, 9, S::npos);
+    test(S(""), "abcdeabcde", 1, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 0, 0);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 1, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 10, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S(""), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcde"), "", 0, 0, 0);
+    test(S("abcde"), "abcde", 0, 0, 0);
+    test(S("abcde"), "abcde", 0, 1, 0);
+    test(S("abcde"), "abcde", 0, 2, 0);
+    test(S("abcde"), "abcde", 0, 4, 0);
+    test(S("abcde"), "abcde", 0, 5, 0);
+    test(S("abcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcde"), "abcdeabcde", 0, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 0, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S("abcde"), "", 1, 0, 1);
+    test(S("abcde"), "abcde", 1, 0, 1);
+    test(S("abcde"), "abcde", 1, 1, 0);
+    test(S("abcde"), "abcde", 1, 2, 0);
+    test(S("abcde"), "abcde", 1, 4, 0);
+    test(S("abcde"), "abcde", 1, 5, 0);
+    test(S("abcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcde"), "abcdeabcde", 1, 1, 0);
+    test(S("abcde"), "abcdeabcde", 1, 5, 0);
+    test(S("abcde"), "abcdeabcde", 1, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 1, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcde"), "", 2, 0, 2);
+    test(S("abcde"), "abcde", 2, 0, 2);
+    test(S("abcde"), "abcde", 2, 1, 0);
+    test(S("abcde"), "abcde", 2, 2, 0);
+    test(S("abcde"), "abcde", 2, 4, 0);
+    test(S("abcde"), "abcde", 2, 5, 0);
+    test(S("abcde"), "abcdeabcde", 2, 0, 2);
+    test(S("abcde"), "abcdeabcde", 2, 1, 0);
+    test(S("abcde"), "abcdeabcde", 2, 5, 0);
+    test(S("abcde"), "abcdeabcde", 2, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 2, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 0, 2);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 2, 20, S::npos);
+    test(S("abcde"), "", 4, 0, 4);
+    test(S("abcde"), "abcde", 4, 0, 4);
+    test(S("abcde"), "abcde", 4, 1, 0);
+    test(S("abcde"), "abcde", 4, 2, 0);
+    test(S("abcde"), "abcde", 4, 4, 0);
+    test(S("abcde"), "abcde", 4, 5, 0);
+    test(S("abcde"), "abcdeabcde", 4, 0, 4);
+    test(S("abcde"), "abcdeabcde", 4, 1, 0);
+    test(S("abcde"), "abcdeabcde", 4, 5, 0);
+    test(S("abcde"), "abcdeabcde", 4, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 4, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 0, 4);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 4, 20, S::npos);
+    test(S("abcde"), "", 5, 0, 5);
+    test(S("abcde"), "abcde", 5, 0, 5);
+    test(S("abcde"), "abcde", 5, 1, 0);
+    test(S("abcde"), "abcde", 5, 2, 0);
+}
+
+void test1()
+{
+    test(S("abcde"), "abcde", 5, 4, 0);
+    test(S("abcde"), "abcde", 5, 5, 0);
+    test(S("abcde"), "abcdeabcde", 5, 0, 5);
+    test(S("abcde"), "abcdeabcde", 5, 1, 0);
+    test(S("abcde"), "abcdeabcde", 5, 5, 0);
+    test(S("abcde"), "abcdeabcde", 5, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 5, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 0, 5);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 5, 20, S::npos);
+    test(S("abcde"), "", 6, 0, 5);
+    test(S("abcde"), "abcde", 6, 0, 5);
+    test(S("abcde"), "abcde", 6, 1, 0);
+    test(S("abcde"), "abcde", 6, 2, 0);
+    test(S("abcde"), "abcde", 6, 4, 0);
+    test(S("abcde"), "abcde", 6, 5, 0);
+    test(S("abcde"), "abcdeabcde", 6, 0, 5);
+    test(S("abcde"), "abcdeabcde", 6, 1, 0);
+    test(S("abcde"), "abcdeabcde", 6, 5, 0);
+    test(S("abcde"), "abcdeabcde", 6, 9, S::npos);
+    test(S("abcde"), "abcdeabcde", 6, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 0, 5);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 1, 0);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 10, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 19, S::npos);
+    test(S("abcde"), "abcdeabcdeabcdeabcde", 6, 20, S::npos);
+    test(S("abcdeabcde"), "", 0, 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcde", 0, 2, 0);
+    test(S("abcdeabcde"), "abcde", 0, 4, 0);
+    test(S("abcdeabcde"), "abcde", 0, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 0, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 0, 20, S::npos);
+    test(S("abcdeabcde"), "", 1, 0, 1);
+    test(S("abcdeabcde"), "abcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcde", 1, 1, 0);
+    test(S("abcdeabcde"), "abcde", 1, 2, 0);
+    test(S("abcdeabcde"), "abcde", 1, 4, 0);
+    test(S("abcdeabcde"), "abcde", 1, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 5, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 1, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 1, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 1, 20, S::npos);
+    test(S("abcdeabcde"), "", 5, 0, 5);
+    test(S("abcdeabcde"), "abcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcde", 5, 2, 5);
+    test(S("abcdeabcde"), "abcde", 5, 4, 5);
+    test(S("abcdeabcde"), "abcde", 5, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 5, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 0, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 5, 20, S::npos);
+    test(S("abcdeabcde"), "", 9, 0, 9);
+    test(S("abcdeabcde"), "abcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcde", 9, 1, 5);
+    test(S("abcdeabcde"), "abcde", 9, 2, 5);
+    test(S("abcdeabcde"), "abcde", 9, 4, 5);
+    test(S("abcdeabcde"), "abcde", 9, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 9, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 0, 9);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 9, 20, S::npos);
+    test(S("abcdeabcde"), "", 10, 0, 10);
+    test(S("abcdeabcde"), "abcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcde", 10, 1, 5);
+    test(S("abcdeabcde"), "abcde", 10, 2, 5);
+    test(S("abcdeabcde"), "abcde", 10, 4, 5);
+    test(S("abcdeabcde"), "abcde", 10, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 1, 5);
+}
+
+void test2()
+{
+    test(S("abcdeabcde"), "abcdeabcde", 10, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 10, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 10, 20, S::npos);
+    test(S("abcdeabcde"), "", 11, 0, 10);
+    test(S("abcdeabcde"), "abcde", 11, 0, 10);
+    test(S("abcdeabcde"), "abcde", 11, 1, 5);
+    test(S("abcdeabcde"), "abcde", 11, 2, 5);
+    test(S("abcdeabcde"), "abcde", 11, 4, 5);
+    test(S("abcdeabcde"), "abcde", 11, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 5, 5);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 9, 0);
+    test(S("abcdeabcde"), "abcdeabcde", 11, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 0, 10);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 1, 5);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 10, 0);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 19, S::npos);
+    test(S("abcdeabcde"), "abcdeabcdeabcdeabcde", 11, 20, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), "", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 2, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 4, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 0, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 9, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 0, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 0, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 2, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 4, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 1, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 5, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 9, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 1, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 0, 1);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 1, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 2, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 4, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 10, 5, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 5, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 9, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 10, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 0, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 1, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 10, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 2, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 4, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 19, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 9, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 19, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 0, 19);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 19, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 2, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 4, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 20, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 9, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20);
+}
+
+void test3()
+{
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), "", 21, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 2, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 4, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcde", 21, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 5, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 9, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 21, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 0, 20);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 1, 15);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 21, 20, 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+    test2();
+    test3();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::rfind/string_size.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::rfind/string_size.pass.cpp
new file mode 100644
index 0000000..0dc07a8
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::rfind/string_size.pass.cpp
@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// size_type rfind(const basic_string& str, size_type pos = npos) const;
+
+#include <string>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type pos, typename S::size_type x)
+{
+    assert(s.rfind(str, pos) == x);
+    if (x != S::npos)
+        assert(x <= pos && x + str.size() <= s.size());
+}
+
+template <class S>
+void
+test(const S& s, const S& str, typename S::size_type x)
+{
+    assert(s.rfind(str) == x);
+    if (x != S::npos)
+        assert(0 <= x && x + str.size() <= s.size());
+}
+
+typedef std::string S;
+
+void test0()
+{
+    test(S(""), S(""), 0, 0);
+    test(S(""), S("abcde"), 0, S::npos);
+    test(S(""), S("abcdeabcde"), 0, S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S(""), S(""), 1, 0);
+    test(S(""), S("abcde"), 1, S::npos);
+    test(S(""), S("abcdeabcde"), 1, S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcde"), S(""), 0, 0);
+    test(S("abcde"), S("abcde"), 0, 0);
+    test(S("abcde"), S("abcdeabcde"), 0, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S("abcde"), S(""), 1, 1);
+    test(S("abcde"), S("abcde"), 1, 0);
+    test(S("abcde"), S("abcdeabcde"), 1, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcde"), S(""), 2, 2);
+    test(S("abcde"), S("abcde"), 2, 0);
+    test(S("abcde"), S("abcdeabcde"), 2, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 2, S::npos);
+    test(S("abcde"), S(""), 4, 4);
+    test(S("abcde"), S("abcde"), 4, 0);
+    test(S("abcde"), S("abcdeabcde"), 4, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 4, S::npos);
+    test(S("abcde"), S(""), 5, 5);
+    test(S("abcde"), S("abcde"), 5, 0);
+    test(S("abcde"), S("abcdeabcde"), 5, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 5, S::npos);
+    test(S("abcde"), S(""), 6, 5);
+    test(S("abcde"), S("abcde"), 6, 0);
+    test(S("abcde"), S("abcdeabcde"), 6, S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), 6, S::npos);
+    test(S("abcdeabcde"), S(""), 0, 0);
+    test(S("abcdeabcde"), S("abcde"), 0, 0);
+    test(S("abcdeabcde"), S("abcdeabcde"), 0, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 0, S::npos);
+    test(S("abcdeabcde"), S(""), 1, 1);
+    test(S("abcdeabcde"), S("abcde"), 1, 0);
+    test(S("abcdeabcde"), S("abcdeabcde"), 1, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 1, S::npos);
+    test(S("abcdeabcde"), S(""), 5, 5);
+    test(S("abcdeabcde"), S("abcde"), 5, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 5, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 5, S::npos);
+    test(S("abcdeabcde"), S(""), 9, 9);
+    test(S("abcdeabcde"), S("abcde"), 9, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 9, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 9, S::npos);
+    test(S("abcdeabcde"), S(""), 10, 10);
+    test(S("abcdeabcde"), S("abcde"), 10, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 10, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 10, S::npos);
+    test(S("abcdeabcde"), S(""), 11, 10);
+    test(S("abcdeabcde"), S("abcde"), 11, 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 11, 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), 11, S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 0, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 1, 1);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 1, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 10, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 10, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 19, 19);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 19, 15);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 19, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 19, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 20, 20);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 20, 15);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 20, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 20, 0);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 21, 20);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 21, 15);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 21, 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 21, 0);
+}
+
+void test1()
+{
+    test(S(""), S(""), 0);
+    test(S(""), S("abcde"), S::npos);
+    test(S(""), S("abcdeabcde"), S::npos);
+    test(S(""), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcde"), S(""), 5);
+    test(S("abcde"), S("abcde"), 0);
+    test(S("abcde"), S("abcdeabcde"), S::npos);
+    test(S("abcde"), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcdeabcde"), S(""), 10);
+    test(S("abcdeabcde"), S("abcde"), 5);
+    test(S("abcdeabcde"), S("abcdeabcde"), 0);
+    test(S("abcdeabcde"), S("abcdeabcdeabcdeabcde"), S::npos);
+    test(S("abcdeabcdeabcdeabcde"), S(""), 20);
+    test(S("abcdeabcdeabcdeabcde"), S("abcde"), 15);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcde"), 10);
+    test(S("abcdeabcdeabcdeabcde"), S("abcdeabcdeabcdeabcde"), 0);
+}
+
+int main()
+{
+    test0();
+    test1();
+}
diff --git a/libcxx/test/strings/basic.string/string.ops/string::substr/substr.pass.cpp b/libcxx/test/strings/basic.string/string.ops/string::substr/substr.pass.cpp
new file mode 100644
index 0000000..4a2d483
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.ops/string::substr/substr.pass.cpp
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// basic_string substr(size_type pos = 0, size_type n = npos) const;
+
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+template <class S>
+void
+test(const S& s, typename S::size_type pos, typename S::size_type n)
+{
+    try
+    {
+        S str = s.substr(pos, n);
+        assert(str.__invariants());
+        assert(pos <= s.size());
+        typename S::size_type rlen = std::min(n, s.size() - pos);
+        assert(str.size() == rlen);
+        assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
+    }
+    catch (std::out_of_range&)
+    {
+        assert(pos > s.size());
+    }
+}
+
+typedef std::string S;
+
+int main()
+{
+    test(S(""), 0, 0);
+    test(S(""), 1, 0);
+    test(S("pniot"), 0, 0);
+    test(S("htaob"), 0, 1);
+    test(S("fodgq"), 0, 2);
+    test(S("hpqia"), 0, 4);
+    test(S("qanej"), 0, 5);
+    test(S("dfkap"), 1, 0);
+    test(S("clbao"), 1, 1);
+    test(S("ihqrf"), 1, 2);
+    test(S("mekdn"), 1, 3);
+    test(S("ngtjf"), 1, 4);
+    test(S("srdfq"), 2, 0);
+    test(S("qkdrs"), 2, 1);
+    test(S("ikcrq"), 2, 2);
+    test(S("cdaih"), 2, 3);
+    test(S("dmajb"), 4, 0);
+    test(S("karth"), 4, 1);
+    test(S("lhcdo"), 5, 0);
+    test(S("acbsj"), 6, 0);
+    test(S("pbsjikaole"), 0, 0);
+    test(S("pcbahntsje"), 0, 1);
+    test(S("mprdjbeiak"), 0, 5);
+    test(S("fhepcrntko"), 0, 9);
+    test(S("eqmpaidtls"), 0, 10);
+    test(S("joidhalcmq"), 1, 0);
+    test(S("omigsphflj"), 1, 1);
+    test(S("kocgbphfji"), 1, 4);
+    test(S("onmjekafbi"), 1, 8);
+    test(S("fbslrjiqkm"), 1, 9);
+    test(S("oqmrjahnkg"), 5, 0);
+    test(S("jeidpcmalh"), 5, 1);
+    test(S("schfalibje"), 5, 2);
+    test(S("crliponbqe"), 5, 4);
+    test(S("igdscopqtm"), 5, 5);
+    test(S("qngpdkimlc"), 9, 0);
+    test(S("thdjgafrlb"), 9, 1);
+    test(S("hcjitbfapl"), 10, 0);
+    test(S("mgojkldsqh"), 11, 0);
+    test(S("gfshlcmdjreqipbontak"), 0, 0);
+    test(S("nadkhpfemgclosibtjrq"), 0, 1);
+    test(S("nkodajteqplrbifhmcgs"), 0, 10);
+    test(S("ofdrqmkeblthacpgijsn"), 0, 19);
+    test(S("gbmetiprqdoasckjfhln"), 0, 20);
+    test(S("bdfjqgatlksriohemnpc"), 1, 0);
+    test(S("crnklpmegdqfiashtojb"), 1, 1);
+    test(S("ejqcnahdrkfsmptilgbo"), 1, 9);
+    test(S("jsbtafedocnirgpmkhql"), 1, 18);
+    test(S("prqgnlbaejsmkhdctoif"), 1, 19);
+    test(S("qnmodrtkebhpasifgcjl"), 10, 0);
+    test(S("pejafmnokrqhtisbcdgl"), 10, 1);
+    test(S("cpebqsfmnjdolhkratgi"), 10, 5);
+    test(S("odnqkgijrhabfmcestlp"), 10, 9);
+    test(S("lmofqdhpkibagnrcjste"), 10, 10);
+    test(S("lgjqketopbfahrmnsicd"), 19, 0);
+    test(S("ktsrmnqagdecfhijpobl"), 19, 1);
+    test(S("lsaijeqhtrbgcdmpfkno"), 20, 0);
+    test(S("dplqartnfgejichmoskb"), 21, 0);
+}
diff --git a/libcxx/test/strings/basic.string/string.require/nothing_to_do.pass.cpp b/libcxx/test/strings/basic.string/string.require/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/basic.string/string.require/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/basic.string/test_allocator.h b/libcxx/test/strings/basic.string/test_allocator.h
new file mode 100644
index 0000000..a949a25
--- /dev/null
+++ b/libcxx/test/strings/basic.string/test_allocator.h
@@ -0,0 +1,70 @@
+#ifndef TEST_ALLOCATOR_H
+#define TEST_ALLOCATOR_H
+
+#include <cstddef>
+#include <type_traits>
+#include <cstdlib>
+#include <new>
+#include <climits>
+
+class test_alloc_base
+{
+protected:
+    static int count;
+public:
+    static int throw_after;
+};
+
+int test_alloc_base::count = 0;
+int test_alloc_base::throw_after = INT_MAX;
+
+template <class T>
+class test_allocator
+    : public test_alloc_base
+{
+    int data_;
+
+    template <class U> friend class test_allocator;
+public:
+
+    typedef unsigned                                                   size_type;
+    typedef int                                                        difference_type;
+    typedef T                                                          value_type;
+    typedef value_type*                                                pointer;
+    typedef const value_type*                                          const_pointer;
+    typedef typename std::add_lvalue_reference<value_type>::type       reference;
+    typedef typename std::add_lvalue_reference<const value_type>::type const_reference;
+
+    template <class U> struct rebind {typedef test_allocator<U> other;};
+
+    test_allocator() throw() : data_(-1) {}
+    explicit test_allocator(int i) throw() : data_(i) {}
+    test_allocator(const test_allocator& a) throw()
+        : data_(a.data_) {}
+    template <class U> test_allocator(const test_allocator<U>& a) throw()
+        : data_(a.data_) {}
+    ~test_allocator() throw() {data_ = 0;}
+    pointer address(reference x) const {return &x;}
+    const_pointer address(const_reference x) const {return &x;}
+    pointer allocate(size_type n, const void* = 0)
+        {
+            if (count >= throw_after)
+                throw std::bad_alloc();
+            ++count;
+            return (pointer)std::malloc(n * sizeof(T));
+        }
+    void deallocate(pointer p, size_type n)
+        {std::free(p);}
+    size_type max_size() const throw()
+        {return UINT_MAX / sizeof(T);}
+    void construct(pointer p, const T& val)
+        {::new(p) T(val);}
+    void destroy(pointer p) {p->~T();}
+
+    friend bool operator==(const test_allocator& x, const test_allocator& y)
+        {return x.data_ == y.data_;}
+    friend bool operator!=(const test_allocator& x, const test_allocator& y)
+        {return !(x == y);}
+};
+
+#endif
diff --git a/libcxx/test/strings/basic.string/test_traits.h b/libcxx/test/strings/basic.string/test_traits.h
new file mode 100644
index 0000000..885d50b
--- /dev/null
+++ b/libcxx/test/strings/basic.string/test_traits.h
@@ -0,0 +1,10 @@
+#ifndef TEST_TRAITS_H
+#define TEST_TRAITS_H
+
+template <class charT>
+struct test_traits
+{
+    typedef charT     char_type;
+};
+
+#endif
diff --git a/libcxx/test/strings/basic.string/types.pass.cpp b/libcxx/test/strings/basic.string/types.pass.cpp
new file mode 100644
index 0000000..5f337ab
--- /dev/null
+++ b/libcxx/test/strings/basic.string/types.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// Test nested types and default template args:
+
+// template<class charT, class traits = char_traits<charT>, 
+//   class Allocator = allocator<charT> >
+// {
+// public:
+//     // types: 
+//     typedef traits traits_type; 
+//     typedef typename traits::char_type value_type; 
+//     typedef Allocator allocator_type; 
+//     typedef typename Allocator::size_type size_type; 
+//     typedef typename Allocator::difference_type difference_type; 
+//     typedef typename Allocator::reference reference; 
+//     typedef typename Allocator::const_reference const_reference; 
+//     typedef typename Allocator::pointer pointer; 
+//     typedef typename Allocator::const_pointer const_pointer; 
+//     typedef implementation-defined iterator; // See 23.1 
+//     typedef implementation-defined const_iterator; // See 23.1 
+//     typedef std::reverse_iterator<iterator> reverse_iterator; 
+//     typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 
+//     static const size_type npos = -1; 
+// };
+
+#include <string>
+#include <iterator>
+#include <type_traits>
+
+#include "test_traits.h"
+#include "test_allocator.h"
+
+template <class Traits, class Allocator>
+void
+test()
+{
+    typedef std::basic_string<typename Traits::char_type, Traits, Allocator> S;
+
+    static_assert((std::is_same<typename S::traits_type, Traits>::value), "");
+    static_assert((std::is_same<typename S::value_type, typename Traits::char_type>::value), "");
+    static_assert((std::is_same<typename S::value_type, typename Allocator::value_type>::value), "");
+    static_assert((std::is_same<typename S::allocator_type, Allocator>::value), "");
+    static_assert((std::is_same<typename S::size_type, typename Allocator::size_type>::value), "");
+    static_assert((std::is_same<typename S::difference_type, typename Allocator::difference_type>::value), "");
+    static_assert((std::is_same<typename S::reference, typename Allocator::reference>::value), "");
+    static_assert((std::is_same<typename S::const_reference, typename Allocator::const_reference>::value), "");
+    static_assert((std::is_same<typename S::pointer, typename Allocator::pointer>::value), "");
+    static_assert((std::is_same<typename S::const_pointer, typename Allocator::const_pointer>::value), "");
+    static_assert((std::is_same<
+        typename std::iterator_traits<typename S::iterator>::iterator_category,
+        std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<
+        typename std::iterator_traits<typename S::const_iterator>::iterator_category,
+        std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<
+        typename S::reverse_iterator,
+        std::reverse_iterator<typename S::iterator> >::value), "");
+    static_assert((std::is_same<
+        typename S::const_reverse_iterator,
+        std::reverse_iterator<typename S::const_iterator> >::value), "");
+    static_assert(S::npos == -1, "");
+}
+
+int main()
+{
+    test<test_traits<char>, test_allocator<char> >();
+    test<std::char_traits<wchar_t>, std::allocator<wchar_t> >();
+    static_assert((std::is_same<std::basic_string<char>::traits_type,
+                                std::char_traits<char> >::value), "");
+    static_assert((std::is_same<std::basic_string<char>::allocator_type,
+                                std::allocator<char> >::value), "");
+}
diff --git a/libcxx/test/strings/c.strings/cctype.pass.cpp b/libcxx/test/strings/c.strings/cctype.pass.cpp
new file mode 100644
index 0000000..69b3ed0
--- /dev/null
+++ b/libcxx/test/strings/c.strings/cctype.pass.cpp
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cctype>
+
+#include <cctype>
+#include <type_traits>
+#include <cassert>
+
+#ifdef isalnum
+#error isalnum defined
+#endif
+
+#ifdef isalpha
+#error isalpha defined
+#endif
+
+#ifdef isblank
+#error isblank defined
+#endif
+
+#ifdef iscntrl
+#error iscntrl defined
+#endif
+
+#ifdef isdigit
+#error isdigit defined
+#endif
+
+#ifdef isgraph
+#error isgraph defined
+#endif
+
+#ifdef islower
+#error islower defined
+#endif
+
+#ifdef isprint
+#error isprint defined
+#endif
+
+#ifdef ispunct
+#error ispunct defined
+#endif
+
+#ifdef isspace
+#error isspace defined
+#endif
+
+#ifdef isupper
+#error isupper defined
+#endif
+
+#ifdef isxdigit
+#error isxdigit defined
+#endif
+
+#ifdef tolower
+#error tolower defined
+#endif
+
+#ifdef toupper
+#error toupper defined
+#endif
+
+int main()
+{
+    static_assert((std::is_same<decltype(std::isalnum(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isalpha(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isblank(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iscntrl(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isdigit(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isgraph(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::islower(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isprint(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::ispunct(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isspace(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isupper(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::isxdigit(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::tolower(0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::toupper(0)), int>::value), "");
+
+    assert(isalnum('a'));
+    assert(isalpha('a'));
+    assert(isblank(' '));
+    assert(!iscntrl(' '));
+    assert(!isdigit('a'));
+    assert(isgraph('a'));
+    assert(islower('a'));
+    assert(isprint('a'));
+    assert(!ispunct('a'));
+    assert(!isspace('a'));
+    assert(!isupper('a'));
+    assert(isxdigit('a'));
+    assert(tolower('A') == 'a');
+    assert(toupper('a') == 'A');
+}
diff --git a/libcxx/test/strings/c.strings/cstring.pass.cpp b/libcxx/test/strings/c.strings/cstring.pass.cpp
new file mode 100644
index 0000000..dbb611f
--- /dev/null
+++ b/libcxx/test/strings/c.strings/cstring.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cstring>
+
+#include <cstring>
+#include <type_traits>
+
+#ifndef NULL
+#error NULL not defined
+#endif
+
+int main()
+{
+    std::size_t s = 0;
+    void* vp = 0;
+    const void* vpc = 0;
+    char* cp = 0;
+    const char* cpc = 0;
+    static_assert((std::is_same<decltype(std::memcpy(vp, vpc, s)), void*>::value), "");
+    static_assert((std::is_same<decltype(std::memmove(vp, vpc, s)), void*>::value), "");
+    static_assert((std::is_same<decltype(std::strcpy(cp, cpc)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strncpy(cp, cpc, s)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strcat(cp, cpc)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strncat(cp, cpc, s)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::memcmp(vpc, vpc, s)), int>::value), "");
+    static_assert((std::is_same<decltype(std::strcmp(cpc, cpc)), int>::value), "");
+    static_assert((std::is_same<decltype(std::strncmp(cpc, cpc, s)), int>::value), "");
+    static_assert((std::is_same<decltype(std::strcoll(cpc, cpc)), int>::value), "");
+    static_assert((std::is_same<decltype(std::strxfrm(cp, cpc, s)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::memchr(vpc, 0, s)), const void*>::value), "");
+    static_assert((std::is_same<decltype(std::memchr(vp, 0, s)), void*>::value), "");
+    static_assert((std::is_same<decltype(std::strchr(cpc, 0)), const char*>::value), "");
+    static_assert((std::is_same<decltype(std::strchr(cp, 0)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strcspn(cpc, cpc)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::strpbrk(cpc, cpc)), const char*>::value), "");
+    static_assert((std::is_same<decltype(std::strpbrk(cp, cpc)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strrchr(cpc, 0)), const char*>::value), "");
+    static_assert((std::is_same<decltype(std::strrchr(cp, 0)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strspn(cpc, cpc)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::strstr(cpc, cpc)), const char*>::value), "");
+    static_assert((std::is_same<decltype(std::strstr(cp, cpc)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strtok(cp, cpc)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::memset(vp, 0, s)), void*>::value), "");
+    static_assert((std::is_same<decltype(std::strerror(0)), char*>::value), "");
+    static_assert((std::is_same<decltype(std::strlen(cpc)), std::size_t>::value), "");
+}
diff --git a/libcxx/test/strings/c.strings/cuchar.pass.cpp b/libcxx/test/strings/c.strings/cuchar.pass.cpp
new file mode 100644
index 0000000..ec5f6a0
--- /dev/null
+++ b/libcxx/test/strings/c.strings/cuchar.pass.cpp
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cuchar>
+
+#include <cuchar>
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/c.strings/cwchar.pass.cpp b/libcxx/test/strings/c.strings/cwchar.pass.cpp
new file mode 100644
index 0000000..92a70c5
--- /dev/null
+++ b/libcxx/test/strings/c.strings/cwchar.pass.cpp
@@ -0,0 +1,105 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cwchar>
+
+#include <cwchar>
+#include <type_traits>
+
+#ifndef NULL
+#error NULL not defined
+#endif
+
+#ifndef WCHAR_MAX
+#error WCHAR_MAX not defined
+#endif
+
+#ifndef WCHAR_MIN
+#error WCHAR_MIN not defined
+#endif
+
+#ifndef WEOF
+#error WEOF not defined
+#endif
+
+int main()
+{
+    std::mbstate_t mb = {0};
+    std::size_t s = 0;
+    std::tm tm = {0};
+    std::wint_t w = 0;
+    ::FILE* fp = 0;
+    __darwin_va_list va;
+    char* ns = 0;
+    wchar_t* ws = 0;
+    static_assert((std::is_same<decltype(std::fwprintf(fp, L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::fwscanf(fp, L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::swprintf(ws, s, L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::swscanf(L"", L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::vfwprintf(fp, L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::vfwscanf(fp, L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::vswprintf(ws, s, L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::vswscanf(L"", L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::vwprintf(L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::vwscanf(L"", va)), int>::value), "");
+    static_assert((std::is_same<decltype(std::wprintf(L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::wscanf(L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::fgetwc(fp)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::fgetws(ws, 0, fp)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::fputwc(L' ', fp)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::fputws(L"", fp)), int>::value), "");
+    static_assert((std::is_same<decltype(std::fwide(fp, 0)), int>::value), "");
+    static_assert((std::is_same<decltype(std::getwc(fp)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::getwchar()), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::putwc(L' ', fp)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::putwchar(L' ')), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::ungetwc(L' ', fp)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcstod(L"", (wchar_t**)0)), double>::value), "");
+    static_assert((std::is_same<decltype(std::wcstof(L"", (wchar_t**)0)), float>::value), "");
+    static_assert((std::is_same<decltype(std::wcstold(L"", (wchar_t**)0)), long double>::value), "");
+    static_assert((std::is_same<decltype(std::wcstol(L"", (wchar_t**)0, 0)), long>::value), "");
+    static_assert((std::is_same<decltype(std::wcstoll(L"", (wchar_t**)0, 0)), long long>::value), "");
+    static_assert((std::is_same<decltype(std::wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), "");
+    static_assert((std::is_same<decltype(std::wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), "");
+    static_assert((std::is_same<decltype(std::wcscpy(ws, L"")), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsncpy(ws, L"", s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcscat(ws, L"")), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsncat(ws, L"", s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcscmp(L"", L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::wcscoll(L"", L"")), int>::value), "");
+    static_assert((std::is_same<decltype(std::wcsncmp(L"", L"", s)), int>::value), "");
+    static_assert((std::is_same<decltype(std::wcsxfrm(ws, L"", s)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcschr((const wchar_t*)0, L' ')), const wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcschr((wchar_t*)0, L' ')), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcscspn(L"", L"")), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcslen(L"")), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcspbrk((const wchar_t*)0, L"")), const wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsrchr((const wchar_t*)0, L' ')), const wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsspn(L"", L"")), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcsstr((const wchar_t*)0, L"")), const wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsstr((wchar_t*)0, L"")), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wmemchr((const wchar_t*)0, L' ', s)), const wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wmemcmp(L"", L"", s)), int>::value), "");
+    static_assert((std::is_same<decltype(std::wmemcpy(ws, L"", s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wmemmove(ws, L"", s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wmemset(ws, L' ', s)), wchar_t*>::value), "");
+    static_assert((std::is_same<decltype(std::wcsftime(ws, s, L"", &tm)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::btowc(0)), wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::wctob(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::mbsinit(&mb)), int>::value), "");
+    static_assert((std::is_same<decltype(std::mbrlen("", s, &mb)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::mbrtowc(ws, "", s, &mb)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcrtomb(ns, L' ', &mb)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::mbsrtowcs(ws, (const char**)0, s, &mb)), std::size_t>::value), "");
+    static_assert((std::is_same<decltype(std::wcsrtombs(ns, (const wchar_t**)0, s, &mb)), std::size_t>::value), "");
+}
diff --git a/libcxx/test/strings/c.strings/cwctype.pass.cpp b/libcxx/test/strings/c.strings/cwctype.pass.cpp
new file mode 100644
index 0000000..64934bd
--- /dev/null
+++ b/libcxx/test/strings/c.strings/cwctype.pass.cpp
@@ -0,0 +1,114 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cwctype>
+
+#include <cwctype>
+#include <type_traits>
+
+#ifndef WEOF
+#error WEOF not defined
+#endif
+
+#ifdef iswalnum
+#error iswalnum defined
+#endif
+
+#ifdef iswalpha
+#error iswalpha defined
+#endif
+
+#ifdef iswblank
+#error iswblank defined
+#endif
+
+#ifdef iswcntrl
+#error iswcntrl defined
+#endif
+
+#ifdef iswdigit
+#error iswdigit defined
+#endif
+
+#ifdef iswgraph
+#error iswgraph defined
+#endif
+
+#ifdef iswlower
+#error iswlower defined
+#endif
+
+#ifdef iswprint
+#error iswprint defined
+#endif
+
+#ifdef iswpunct
+#error iswpunct defined
+#endif
+
+#ifdef iswspace
+#error iswspace defined
+#endif
+
+#ifdef iswupper
+#error iswupper defined
+#endif
+
+#ifdef iswxdigit
+#error iswxdigit defined
+#endif
+
+#ifdef iswctype
+#error iswctype defined
+#endif
+
+#ifdef wctype
+#error wctype defined
+#endif
+
+#ifdef towlower
+#error towlower defined
+#endif
+
+#ifdef towupper
+#error towupper defined
+#endif
+
+#ifdef towctrans
+#error towctrans defined
+#endif
+
+#ifdef wctrans
+#error wctrans defined
+#endif
+
+int main()
+{
+    std::wint_t w = 0;
+    std::wctrans_t wctr = 0;
+    std::wctype_t wct = 0;
+    static_assert((std::is_same<decltype(std::iswalnum(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswalpha(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswblank(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswcntrl(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswdigit(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswgraph(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswlower(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswprint(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswpunct(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswspace(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswupper(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswxdigit(w)), int>::value), "");
+    static_assert((std::is_same<decltype(std::iswctype(w, wct)), int>::value), "");
+    static_assert((std::is_same<decltype(std::wctype("")), std::wctype_t>::value), "");
+    static_assert((std::is_same<decltype(std::towlower(w)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::towupper(w)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::towctrans(w, wctr)), std::wint_t>::value), "");
+    static_assert((std::is_same<decltype(std::wctrans("")), std::wctrans_t>::value), "");
+}
diff --git a/libcxx/test/strings/c.strings/version_cctype.pass.cpp b/libcxx/test/strings/c.strings/version_cctype.pass.cpp
new file mode 100644
index 0000000..5c2e817
--- /dev/null
+++ b/libcxx/test/strings/c.strings/version_cctype.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cctype>
+
+#include <cctype>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/c.strings/version_cstring.pass.cpp b/libcxx/test/strings/c.strings/version_cstring.pass.cpp
new file mode 100644
index 0000000..670e0e1
--- /dev/null
+++ b/libcxx/test/strings/c.strings/version_cstring.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cstring>
+
+#include <cstring>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/c.strings/version_cuchar.pass.cpp b/libcxx/test/strings/c.strings/version_cuchar.pass.cpp
new file mode 100644
index 0000000..11bbeb6
--- /dev/null
+++ b/libcxx/test/strings/c.strings/version_cuchar.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cuchar>
+
+#include <cuchar>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/c.strings/version_cwchar.pass.cpp b/libcxx/test/strings/c.strings/version_cwchar.pass.cpp
new file mode 100644
index 0000000..612762b
--- /dev/null
+++ b/libcxx/test/strings/c.strings/version_cwchar.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cwchar>
+
+#include <cwchar>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/c.strings/version_cwctype.pass.cpp b/libcxx/test/strings/c.strings/version_cwctype.pass.cpp
new file mode 100644
index 0000000..bc3c090
--- /dev/null
+++ b/libcxx/test/strings/c.strings/version_cwctype.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <cwctype>
+
+#include <cwctype>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.require/nothing_to_do.pass.cpp b/libcxx/test/strings/char.traits/char.traits.require/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.require/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp
new file mode 100644
index 0000000..92b1ea4
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign2.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static void assign(char_type& c1, const char_type& c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char c = '\0';
+    std::char_traits<char>::assign(c, 'a');
+    assert(c == 'a');
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp
new file mode 100644
index 0000000..5a44ea3
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/assign3.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static char_type* assign(char_type* s, size_t n, char_type a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char s1[] = {1, 2, 3};
+    char s2[3] = {0};
+    assert(std::char_traits<char>::assign(s2, 3, char(5)) == s2);
+    assert(s2[0] == char(5));
+    assert(s2[1] == char(5));
+    assert(s2[2] == char(5));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp
new file mode 100644
index 0000000..6f51db7
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/compare.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static int compare(const char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::compare("", "", 0) == 0);
+
+    assert(std::char_traits<char>::compare("1", "1", 1) == 0);
+    assert(std::char_traits<char>::compare("1", "2", 1) < 0);
+    assert(std::char_traits<char>::compare("2", "1", 1) > 0);
+
+    assert(std::char_traits<char>::compare("12", "12", 2) == 0);
+    assert(std::char_traits<char>::compare("12", "13", 2) < 0);
+    assert(std::char_traits<char>::compare("12", "22", 2) < 0);
+    assert(std::char_traits<char>::compare("13", "12", 2) > 0);
+    assert(std::char_traits<char>::compare("22", "12", 2) > 0);
+
+    assert(std::char_traits<char>::compare("123", "123", 3) == 0);
+    assert(std::char_traits<char>::compare("123", "223", 3) < 0);
+    assert(std::char_traits<char>::compare("123", "133", 3) < 0);
+    assert(std::char_traits<char>::compare("123", "124", 3) < 0);
+    assert(std::char_traits<char>::compare("223", "123", 3) > 0);
+    assert(std::char_traits<char>::compare("133", "123", 3) > 0);
+    assert(std::char_traits<char>::compare("124", "123", 3) > 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp
new file mode 100644
index 0000000..45cfc50
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/copy.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static char_type* copy(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char s1[] = {1, 2, 3};
+    char s2[3] = {0};
+    assert(std::char_traits<char>::copy(s2, s1, 3) == s2);
+    assert(s2[0] == char(1));
+    assert(s2[1] == char(2));
+    assert(s2[2] == char(3));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eof.pass.cpp
new file mode 100644
index 0000000..041b4d0
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eof.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr int_type eof();
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::eof() == EOF);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq.pass.cpp
new file mode 100644
index 0000000..f2ddbfa
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr bool eq(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char c = '\0';
+    assert(std::char_traits<char>::eq('a', 'a'));
+    assert(!std::char_traits<char>::eq('a', 'A'));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq_int_type.pass.cpp
new file mode 100644
index 0000000..446a83f
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/eq_int_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr bool eq_int_type(int_type c1, int_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert( std::char_traits<char>::eq_int_type('a', 'a'));
+    assert(!std::char_traits<char>::eq_int_type('a', 'A'));
+    assert(!std::char_traits<char>::eq_int_type(std::char_traits<char>::eof(), 'A'));
+    assert( std::char_traits<char>::eq_int_type(std::char_traits<char>::eof(),
+                                                std::char_traits<char>::eof()));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp
new file mode 100644
index 0000000..2e0f2ff
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/find.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static const char_type* find(const char_type* s, size_t n, const char_type& a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char s1[] = {1, 2, 3};
+    assert(std::char_traits<char>::find(s1, 3, char(1)) == s1);
+    assert(std::char_traits<char>::find(s1, 3, char(2)) == s1+1);
+    assert(std::char_traits<char>::find(s1, 3, char(3)) == s1+2);
+    assert(std::char_traits<char>::find(s1, 3, char(4)) == 0);
+    assert(std::char_traits<char>::find(s1, 3, char(0)) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp
new file mode 100644
index 0000000..b111ba4
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/length.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static size_t length(const char_type* s);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::length("") == 0);
+    assert(std::char_traits<char>::length("a") == 1);
+    assert(std::char_traits<char>::length("aa") == 2);
+    assert(std::char_traits<char>::length("aaa") == 3);
+    assert(std::char_traits<char>::length("aaaa") == 4);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/lt.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/lt.pass.cpp
new file mode 100644
index 0000000..6479c66
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/lt.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr bool lt(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char c = '\0';
+    assert(!std::char_traits<char>::lt('a', 'a'));
+    assert( std::char_traits<char>::lt('A', 'a'));
+    assert(!std::char_traits<char>::lt('A' + 127, 'a'));
+    assert(!std::char_traits<char>::lt('A' - 127, 'a'));
+    assert( std::char_traits<char>::lt('A', 'a' + 127));
+    assert( std::char_traits<char>::lt('A', 'a' - 127));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp
new file mode 100644
index 0000000..3627550
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/move.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static char_type* move(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    char s1[] = {1, 2, 3};
+    assert(std::char_traits<char>::move(s1, s1+1, 2) == s1);
+    assert(s1[0] == char(2));
+    assert(s1[1] == char(3));
+    assert(s1[2] == char(3));
+    s1[2] = char(0);
+    assert(std::char_traits<char>::move(s1+1, s1, 2) == s1+1);
+    assert(s1[0] == char(2));
+    assert(s1[1] == char(2));
+    assert(s1[2] == char(3));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/not_eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/not_eof.pass.cpp
new file mode 100644
index 0000000..44d26be
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/not_eof.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr int_type not_eof(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::not_eof('a') == 'a');
+    assert(std::char_traits<char>::not_eof('A') == 'A');
+    assert(std::char_traits<char>::not_eof(0) == 0);
+    assert(std::char_traits<char>::not_eof(std::char_traits<char>::eof()) !=
+           std::char_traits<char>::eof());
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_char_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_char_type.pass.cpp
new file mode 100644
index 0000000..8b5d1b1
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_char_type.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr char_type to_char_type(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::to_char_type('a') == 'a');
+    assert(std::char_traits<char>::to_char_type('A') == 'A');
+    assert(std::char_traits<char>::to_char_type(0) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_int_type.pass.cpp
new file mode 100644
index 0000000..2cb41de
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/to_int_type.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// static constexpr int_type to_int_type(char_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<char>::to_int_type('a') == 'a');
+    assert(std::char_traits<char>::to_int_type('A') == 'A');
+    assert(std::char_traits<char>::to_int_type(0) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp
new file mode 100644
index 0000000..dd0afbf
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char/types.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char>
+
+// typedef char      char_type; 
+// typedef int       int_type; 
+// typedef streamoff off_type; 
+// typedef streampos pos_type; 
+// typedef mbstate_t state_type; 
+
+#include <string>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::char_traits<char>::char_type, char>::value), "");
+    static_assert((std::is_same<std::char_traits<char>::int_type, int>::value), "");
+    static_assert((std::is_same<std::char_traits<char>::off_type, std::streamoff>::value), "");
+    static_assert((std::is_same<std::char_traits<char>::pos_type, std::streampos>::value), "");
+    static_assert((std::is_same<std::char_traits<char>::state_type, std::mbstate_t>::value), "");
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp
new file mode 100644
index 0000000..6002d0b
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign2.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static void assign(char_type& c1, const char_type& c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t c = u'\0';
+    std::char_traits<char16_t>::assign(c, u'a');
+    assert(c == u'a');
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp
new file mode 100644
index 0000000..c5a98a5
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/assign3.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static char_type* assign(char_type* s, size_t n, char_type a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t s1[] = {1, 2, 3};
+    char16_t s2[3] = {0};
+    assert(std::char_traits<char16_t>::assign(s2, 3, char16_t(5)) == s2);
+    assert(s2[0] == char16_t(5));
+    assert(s2[1] == char16_t(5));
+    assert(s2[2] == char16_t(5));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp
new file mode 100644
index 0000000..55e82d5
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/compare.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static int compare(const char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char16_t>::compare(u"", u"", 0) == 0);
+
+    assert(std::char_traits<char16_t>::compare(u"1", u"1", 1) == 0);
+    assert(std::char_traits<char16_t>::compare(u"1", u"2", 1) < 0);
+    assert(std::char_traits<char16_t>::compare(u"2", u"1", 1) > 0);
+
+    assert(std::char_traits<char16_t>::compare(u"12", u"12", 2) == 0);
+    assert(std::char_traits<char16_t>::compare(u"12", u"13", 2) < 0);
+    assert(std::char_traits<char16_t>::compare(u"12", u"22", 2) < 0);
+    assert(std::char_traits<char16_t>::compare(u"13", u"12", 2) > 0);
+    assert(std::char_traits<char16_t>::compare(u"22", u"12", 2) > 0);
+
+    assert(std::char_traits<char16_t>::compare(u"123", u"123", 3) == 0);
+    assert(std::char_traits<char16_t>::compare(u"123", u"223", 3) < 0);
+    assert(std::char_traits<char16_t>::compare(u"123", u"133", 3) < 0);
+    assert(std::char_traits<char16_t>::compare(u"123", u"124", 3) < 0);
+    assert(std::char_traits<char16_t>::compare(u"223", u"123", 3) > 0);
+    assert(std::char_traits<char16_t>::compare(u"133", u"123", 3) > 0);
+    assert(std::char_traits<char16_t>::compare(u"124", u"123", 3) > 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp
new file mode 100644
index 0000000..7edf6e6
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/copy.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static char_type* copy(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t s1[] = {1, 2, 3};
+    char16_t s2[3] = {0};
+    assert(std::char_traits<char16_t>::copy(s2, s1, 3) == s2);
+    assert(s2[0] == char16_t(1));
+    assert(s2[1] == char16_t(2));
+    assert(s2[2] == char16_t(3));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eof.pass.cpp
new file mode 100644
index 0000000..dad0ba9
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eof.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr int_type eof();
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    std::char_traits<char16_t>::int_type i = std::char_traits<char16_t>::eof();
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq.pass.cpp
new file mode 100644
index 0000000..1a8be4e
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr bool eq(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t c = u'\0';
+    assert(std::char_traits<char16_t>::eq(u'a', u'a'));
+    assert(!std::char_traits<char16_t>::eq(u'a', u'A'));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq_int_type.pass.cpp
new file mode 100644
index 0000000..13befce
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/eq_int_type.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr bool eq_int_type(int_type c1, int_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert( std::char_traits<char16_t>::eq_int_type(u'a', u'a'));
+    assert(!std::char_traits<char16_t>::eq_int_type(u'a', u'A'));
+    assert(!std::char_traits<char16_t>::eq_int_type(std::char_traits<char16_t>::eof(), u'A'));
+    assert( std::char_traits<char16_t>::eq_int_type(std::char_traits<char16_t>::eof(),
+                                                    std::char_traits<char16_t>::eof()));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp
new file mode 100644
index 0000000..765da3e
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/find.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static const char_type* find(const char_type* s, size_t n, const char_type& a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t s1[] = {1, 2, 3};
+    assert(std::char_traits<char16_t>::find(s1, 3, char16_t(1)) == s1);
+    assert(std::char_traits<char16_t>::find(s1, 3, char16_t(2)) == s1+1);
+    assert(std::char_traits<char16_t>::find(s1, 3, char16_t(3)) == s1+2);
+    assert(std::char_traits<char16_t>::find(s1, 3, char16_t(4)) == 0);
+    assert(std::char_traits<char16_t>::find(s1, 3, char16_t(0)) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp
new file mode 100644
index 0000000..4810980
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/length.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static size_t length(const char_type* s);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char16_t>::length(u"") == 0);
+    assert(std::char_traits<char16_t>::length(u"a") == 1);
+    assert(std::char_traits<char16_t>::length(u"aa") == 2);
+    assert(std::char_traits<char16_t>::length(u"aaa") == 3);
+    assert(std::char_traits<char16_t>::length(u"aaaa") == 4);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/lt.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/lt.pass.cpp
new file mode 100644
index 0000000..a322196
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/lt.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr bool lt(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t c = u'\0';
+    assert(!std::char_traits<char16_t>::lt(u'a', u'a'));
+    assert( std::char_traits<char16_t>::lt(u'A', u'a'));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp
new file mode 100644
index 0000000..7c172e6
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/move.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static char_type* move(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char16_t s1[] = {1, 2, 3};
+    assert(std::char_traits<char16_t>::move(s1, s1+1, 2) == s1);
+    assert(s1[0] == char16_t(2));
+    assert(s1[1] == char16_t(3));
+    assert(s1[2] == char16_t(3));
+    s1[2] = char16_t(0);
+    assert(std::char_traits<char16_t>::move(s1+1, s1, 2) == s1+1);
+    assert(s1[0] == char16_t(2));
+    assert(s1[1] == char16_t(2));
+    assert(s1[2] == char16_t(3));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/not_eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/not_eof.pass.cpp
new file mode 100644
index 0000000..3de319c
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/not_eof.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr int_type not_eof(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char16_t>::not_eof(u'a') == u'a');
+    assert(std::char_traits<char16_t>::not_eof(u'A') == u'A');
+    assert(std::char_traits<char16_t>::not_eof(0) == 0);
+    assert(std::char_traits<char16_t>::not_eof(std::char_traits<char16_t>::eof()) !=
+           std::char_traits<char16_t>::eof());
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_char_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_char_type.pass.cpp
new file mode 100644
index 0000000..e60ef91
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_char_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr char_type to_char_type(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char16_t>::to_char_type(u'a') == u'a');
+    assert(std::char_traits<char16_t>::to_char_type(u'A') == u'A');
+    assert(std::char_traits<char16_t>::to_char_type(0) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_int_type.pass.cpp
new file mode 100644
index 0000000..6d07b79
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/to_int_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// static constexpr int_type to_int_type(char_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char16_t>::to_int_type(u'a') == u'a');
+    assert(std::char_traits<char16_t>::to_int_type(u'A') == u'A');
+    assert(std::char_traits<char16_t>::to_int_type(0) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp
new file mode 100644
index 0000000..95ce8ec
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char16_t/types.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char16_t>
+
+// typedef char16_t       char_type; 
+// typedef uint_least16_t int_type; 
+// typedef streamoff      off_type; 
+// typedef u16streampos   pos_type; 
+// typedef mbstate_t      state_type; 
+
+#include <string>
+#include <type_traits>
+#include <cstdint>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    static_assert((std::is_same<std::char_traits<char16_t>::char_type, char16_t>::value), "");
+    static_assert((std::is_same<std::char_traits<char16_t>::int_type, std::uint_least16_t>::value), "");
+    static_assert((std::is_same<std::char_traits<char16_t>::off_type, std::streamoff>::value), "");
+    static_assert((std::is_same<std::char_traits<char16_t>::pos_type, std::u16streampos>::value), "");
+    static_assert((std::is_same<std::char_traits<char16_t>::state_type, std::mbstate_t>::value), "");
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp
new file mode 100644
index 0000000..0caf5fd
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign2.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static void assign(char_type& c1, const char_type& c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t c = U'\0';
+    std::char_traits<char32_t>::assign(c, U'a');
+    assert(c == U'a');
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp
new file mode 100644
index 0000000..e3702d4
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/assign3.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static char_type* assign(char_type* s, size_t n, char_type a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t s1[] = {1, 2, 3};
+    char32_t s2[3] = {0};
+    assert(std::char_traits<char32_t>::assign(s2, 3, char32_t(5)) == s2);
+    assert(s2[0] == char32_t(5));
+    assert(s2[1] == char32_t(5));
+    assert(s2[2] == char32_t(5));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp
new file mode 100644
index 0000000..0f0999b
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/compare.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static int compare(const char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char32_t>::compare(U"", U"", 0) == 0);
+
+    assert(std::char_traits<char32_t>::compare(U"1", U"1", 1) == 0);
+    assert(std::char_traits<char32_t>::compare(U"1", U"2", 1) < 0);
+    assert(std::char_traits<char32_t>::compare(U"2", U"1", 1) > 0);
+
+    assert(std::char_traits<char32_t>::compare(U"12", U"12", 2) == 0);
+    assert(std::char_traits<char32_t>::compare(U"12", U"13", 2) < 0);
+    assert(std::char_traits<char32_t>::compare(U"12", U"22", 2) < 0);
+    assert(std::char_traits<char32_t>::compare(U"13", U"12", 2) > 0);
+    assert(std::char_traits<char32_t>::compare(U"22", U"12", 2) > 0);
+
+    assert(std::char_traits<char32_t>::compare(U"123", U"123", 3) == 0);
+    assert(std::char_traits<char32_t>::compare(U"123", U"223", 3) < 0);
+    assert(std::char_traits<char32_t>::compare(U"123", U"133", 3) < 0);
+    assert(std::char_traits<char32_t>::compare(U"123", U"124", 3) < 0);
+    assert(std::char_traits<char32_t>::compare(U"223", U"123", 3) > 0);
+    assert(std::char_traits<char32_t>::compare(U"133", U"123", 3) > 0);
+    assert(std::char_traits<char32_t>::compare(U"124", U"123", 3) > 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp
new file mode 100644
index 0000000..8e5aa66
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/copy.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static char_type* copy(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t s1[] = {1, 2, 3};
+    char32_t s2[3] = {0};
+    assert(std::char_traits<char32_t>::copy(s2, s1, 3) == s2);
+    assert(s2[0] == char32_t(1));
+    assert(s2[1] == char32_t(2));
+    assert(s2[2] == char32_t(3));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eof.pass.cpp
new file mode 100644
index 0000000..f783867
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eof.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr int_type eof();
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    std::char_traits<char32_t>::int_type i = std::char_traits<char32_t>::eof();
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq.pass.cpp
new file mode 100644
index 0000000..fddd200
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr bool eq(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t c = U'\0';
+    assert(std::char_traits<char32_t>::eq(U'a', U'a'));
+    assert(!std::char_traits<char32_t>::eq(U'a', U'A'));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq_int_type.pass.cpp
new file mode 100644
index 0000000..d52172c
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/eq_int_type.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr bool eq_int_type(int_type c1, int_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert( std::char_traits<char32_t>::eq_int_type(U'a', U'a'));
+    assert(!std::char_traits<char32_t>::eq_int_type(U'a', U'A'));
+    assert(!std::char_traits<char32_t>::eq_int_type(std::char_traits<char32_t>::eof(), U'A'));
+    assert( std::char_traits<char32_t>::eq_int_type(std::char_traits<char32_t>::eof(),
+                                                    std::char_traits<char32_t>::eof()));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp
new file mode 100644
index 0000000..4352ecf
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/find.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static const char_type* find(const char_type* s, size_t n, const char_type& a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t s1[] = {1, 2, 3};
+    assert(std::char_traits<char32_t>::find(s1, 3, char32_t(1)) == s1);
+    assert(std::char_traits<char32_t>::find(s1, 3, char32_t(2)) == s1+1);
+    assert(std::char_traits<char32_t>::find(s1, 3, char32_t(3)) == s1+2);
+    assert(std::char_traits<char32_t>::find(s1, 3, char32_t(4)) == 0);
+    assert(std::char_traits<char32_t>::find(s1, 3, char32_t(0)) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp
new file mode 100644
index 0000000..2c35e50
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/length.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static size_t length(const char_type* s);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char32_t>::length(U"") == 0);
+    assert(std::char_traits<char32_t>::length(U"a") == 1);
+    assert(std::char_traits<char32_t>::length(U"aa") == 2);
+    assert(std::char_traits<char32_t>::length(U"aaa") == 3);
+    assert(std::char_traits<char32_t>::length(U"aaaa") == 4);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/lt.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/lt.pass.cpp
new file mode 100644
index 0000000..2b7e3cd
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/lt.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr bool lt(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t c = U'\0';
+    assert(!std::char_traits<char32_t>::lt(U'a', U'a'));
+    assert( std::char_traits<char32_t>::lt(U'A', U'a'));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp
new file mode 100644
index 0000000..dc0bb78
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/move.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static char_type* move(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    char32_t s1[] = {1, 2, 3};
+    assert(std::char_traits<char32_t>::move(s1, s1+1, 2) == s1);
+    assert(s1[0] == char32_t(2));
+    assert(s1[1] == char32_t(3));
+    assert(s1[2] == char32_t(3));
+    s1[2] = char32_t(0);
+    assert(std::char_traits<char32_t>::move(s1+1, s1, 2) == s1+1);
+    assert(s1[0] == char32_t(2));
+    assert(s1[1] == char32_t(2));
+    assert(s1[2] == char32_t(3));
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/not_eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/not_eof.pass.cpp
new file mode 100644
index 0000000..1722282
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/not_eof.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr int_type not_eof(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char32_t>::not_eof(U'a') == U'a');
+    assert(std::char_traits<char32_t>::not_eof(U'A') == U'A');
+    assert(std::char_traits<char32_t>::not_eof(0) == 0);
+    assert(std::char_traits<char32_t>::not_eof(std::char_traits<char32_t>::eof()) !=
+           std::char_traits<char32_t>::eof());
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_char_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_char_type.pass.cpp
new file mode 100644
index 0000000..fd1825a
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_char_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr char_type to_char_type(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char32_t>::to_char_type(U'a') == U'a');
+    assert(std::char_traits<char32_t>::to_char_type(U'A') == U'A');
+    assert(std::char_traits<char32_t>::to_char_type(0) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_int_type.pass.cpp
new file mode 100644
index 0000000..7d5dbe4
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/to_int_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// static constexpr int_type to_int_type(char_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    assert(std::char_traits<char32_t>::to_int_type(U'a') == U'a');
+    assert(std::char_traits<char32_t>::to_int_type(U'A') == U'A');
+    assert(std::char_traits<char32_t>::to_int_type(0) == 0);
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.pass.cpp
new file mode 100644
index 0000000..db1d393
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.char32_t/types.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<char32_t>
+
+// typedef char32_t       char_type; 
+// typedef uint_least32_t int_type; 
+// typedef streamoff      off_type; 
+// typedef u32streampos   pos_type; 
+// typedef mbstate_t      state_type; 
+
+#include <string>
+#include <type_traits>
+#include <cstdint>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    static_assert((std::is_same<std::char_traits<char32_t>::char_type, char32_t>::value), "");
+    static_assert((std::is_same<std::char_traits<char32_t>::int_type, std::uint_least32_t>::value), "");
+    static_assert((std::is_same<std::char_traits<char32_t>::off_type, std::streamoff>::value), "");
+    static_assert((std::is_same<std::char_traits<char32_t>::pos_type, std::u32streampos>::value), "");
+    static_assert((std::is_same<std::char_traits<char32_t>::state_type, std::mbstate_t>::value), "");
+#endif
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp
new file mode 100644
index 0000000..650b8ba
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign2.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static void assign(char_type& c1, const char_type& c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t c = L'\0';
+    std::char_traits<wchar_t>::assign(c, L'a');
+    assert(c == L'a');
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp
new file mode 100644
index 0000000..a28da61
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/assign3.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static char_type* assign(char_type* s, size_t n, char_type a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t s1[] = {1, 2, 3};
+    wchar_t s2[3] = {0};
+    assert(std::char_traits<wchar_t>::assign(s2, 3, wchar_t(5)) == s2);
+    assert(s2[0] == wchar_t(5));
+    assert(s2[1] == wchar_t(5));
+    assert(s2[2] == wchar_t(5));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp
new file mode 100644
index 0000000..d8cac4f
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/compare.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static int compare(const char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::compare(L"", L"", 0) == 0);
+
+    assert(std::char_traits<wchar_t>::compare(L"1", L"1", 1) == 0);
+    assert(std::char_traits<wchar_t>::compare(L"1", L"2", 1) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"2", L"1", 1) > 0);
+
+    assert(std::char_traits<wchar_t>::compare(L"12", L"12", 2) == 0);
+    assert(std::char_traits<wchar_t>::compare(L"12", L"13", 2) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"12", L"22", 2) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"13", L"12", 2) > 0);
+    assert(std::char_traits<wchar_t>::compare(L"22", L"12", 2) > 0);
+
+    assert(std::char_traits<wchar_t>::compare(L"123", L"123", 3) == 0);
+    assert(std::char_traits<wchar_t>::compare(L"123", L"223", 3) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"123", L"133", 3) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"123", L"124", 3) < 0);
+    assert(std::char_traits<wchar_t>::compare(L"223", L"123", 3) > 0);
+    assert(std::char_traits<wchar_t>::compare(L"133", L"123", 3) > 0);
+    assert(std::char_traits<wchar_t>::compare(L"124", L"123", 3) > 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp
new file mode 100644
index 0000000..abecfc1
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/copy.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static char_type* copy(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t s1[] = {1, 2, 3};
+    wchar_t s2[3] = {0};
+    assert(std::char_traits<wchar_t>::copy(s2, s1, 3) == s2);
+    assert(s2[0] == wchar_t(1));
+    assert(s2[1] == wchar_t(2));
+    assert(s2[2] == wchar_t(3));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eof.pass.cpp
new file mode 100644
index 0000000..77637e0
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eof.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr int_type eof();
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::eof() == WEOF);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq.pass.cpp
new file mode 100644
index 0000000..53ff74e
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr bool eq(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t c = L'\0';
+    assert(std::char_traits<wchar_t>::eq(L'a', L'a'));
+    assert(!std::char_traits<wchar_t>::eq(L'a', L'A'));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq_int_type.pass.cpp
new file mode 100644
index 0000000..3cb1df9
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/eq_int_type.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr bool eq_int_type(int_type c1, int_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert( std::char_traits<wchar_t>::eq_int_type(L'a', L'a'));
+    assert(!std::char_traits<wchar_t>::eq_int_type(L'a', L'A'));
+    assert(!std::char_traits<wchar_t>::eq_int_type(std::char_traits<wchar_t>::eof(), L'A'));
+    assert( std::char_traits<wchar_t>::eq_int_type(std::char_traits<wchar_t>::eof(),
+                                                   std::char_traits<wchar_t>::eof()));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp
new file mode 100644
index 0000000..6a416e8
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/find.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static const char_type* find(const char_type* s, size_t n, const char_type& a);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t s1[] = {1, 2, 3};
+    assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(1)) == s1);
+    assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(2)) == s1+1);
+    assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(3)) == s1+2);
+    assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(4)) == 0);
+    assert(std::char_traits<wchar_t>::find(s1, 3, wchar_t(0)) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp
new file mode 100644
index 0000000..8d437ce
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/length.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static size_t length(const char_type* s);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::length(L"") == 0);
+    assert(std::char_traits<wchar_t>::length(L"a") == 1);
+    assert(std::char_traits<wchar_t>::length(L"aa") == 2);
+    assert(std::char_traits<wchar_t>::length(L"aaa") == 3);
+    assert(std::char_traits<wchar_t>::length(L"aaaa") == 4);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/lt.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/lt.pass.cpp
new file mode 100644
index 0000000..b4978e1
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/lt.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr bool lt(char_type c1, char_type c2);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t c = L'\0';
+    assert(!std::char_traits<wchar_t>::lt(L'a', L'a'));
+    assert( std::char_traits<wchar_t>::lt(L'A', L'a'));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp
new file mode 100644
index 0000000..3227e7e
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/move.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static char_type* move(char_type* s1, const char_type* s2, size_t n);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    wchar_t s1[] = {1, 2, 3};
+    assert(std::char_traits<wchar_t>::move(s1, s1+1, 2) == s1);
+    assert(s1[0] == wchar_t(2));
+    assert(s1[1] == wchar_t(3));
+    assert(s1[2] == wchar_t(3));
+    s1[2] = wchar_t(0);
+    assert(std::char_traits<wchar_t>::move(s1+1, s1, 2) == s1+1);
+    assert(s1[0] == wchar_t(2));
+    assert(s1[1] == wchar_t(2));
+    assert(s1[2] == wchar_t(3));
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/not_eof.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/not_eof.pass.cpp
new file mode 100644
index 0000000..f68b05c
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/not_eof.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr int_type not_eof(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::not_eof(L'a') == L'a');
+    assert(std::char_traits<wchar_t>::not_eof(L'A') == L'A');
+    assert(std::char_traits<wchar_t>::not_eof(0) == 0);
+    assert(std::char_traits<wchar_t>::not_eof(std::char_traits<wchar_t>::eof()) !=
+           std::char_traits<wchar_t>::eof());
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_char_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_char_type.pass.cpp
new file mode 100644
index 0000000..40d941a
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_char_type.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr char_type to_char_type(int_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::to_char_type(L'a') == L'a');
+    assert(std::char_traits<wchar_t>::to_char_type(L'A') == L'A');
+    assert(std::char_traits<wchar_t>::to_char_type(0) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_int_type.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_int_type.pass.cpp
new file mode 100644
index 0000000..e993cd9
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/to_int_type.pass.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// static constexpr int_type to_int_type(char_type c);
+
+#include <string>
+#include <cassert>
+
+int main()
+{
+    assert(std::char_traits<wchar_t>::to_int_type(L'a') == L'a');
+    assert(std::char_traits<wchar_t>::to_int_type(L'A') == L'A');
+    assert(std::char_traits<wchar_t>::to_int_type(0) == 0);
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp
new file mode 100644
index 0000000..2353cb1
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/char.traits.specializations.wchar.t/types.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<> struct char_traits<wchar_t>
+
+// typedef wchar_t   char_type; 
+// typedef int       int_type; 
+// typedef streamoff off_type; 
+// typedef streampos pos_type; 
+// typedef mbstate_t state_type; 
+
+#include <string>
+#include <type_traits>
+
+int main()
+{
+    static_assert((std::is_same<std::char_traits<wchar_t>::char_type, wchar_t>::value), "");
+    static_assert((std::is_same<std::char_traits<wchar_t>::int_type, std::wint_t>::value), "");
+    static_assert((std::is_same<std::char_traits<wchar_t>::off_type, std::streamoff>::value), "");
+    static_assert((std::is_same<std::char_traits<wchar_t>::pos_type, std::wstreampos>::value), "");
+    static_assert((std::is_same<std::char_traits<wchar_t>::state_type, std::mbstate_t>::value), "");
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.specializations/nothing_to_do.pass.cpp b/libcxx/test/strings/char.traits/char.traits.specializations/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.specializations/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/char.traits/char.traits.typedefs/nothing_to_do.pass.cpp b/libcxx/test/strings/char.traits/char.traits.typedefs/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/char.traits/char.traits.typedefs/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/char.traits/nothing_to_do.pass.cpp b/libcxx/test/strings/char.traits/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/libcxx/test/strings/char.traits/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/strings/string.classes/typedefs.pass.cpp b/libcxx/test/strings/string.classes/typedefs.pass.cpp
new file mode 100644
index 0000000..f4b0cb0
--- /dev/null
+++ b/libcxx/test/strings/string.classes/typedefs.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// Test for the existence of:
+
+// basic_string typedef names 
+// typedef basic_string<char> string; 
+// typedef basic_string<char16_t> u16string; 
+// typedef basic_string<char32_t> u32string; 
+// typedef basic_string<wchar_t> wstring;
+
+#include <string>
+
+int main()
+{
+    typedef std::string test1;
+    typedef std::wstring test2;
+#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
+    typedef std::u16string test3;
+    typedef std::u32string test4;
+#endif
+}
diff --git a/libcxx/test/strings/version.pass.cpp b/libcxx/test/strings/version.pass.cpp
new file mode 100644
index 0000000..9756277
--- /dev/null
+++ b/libcxx/test/strings/version.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+#include <string>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}