2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
|
|
|
Copyright (c) 2011-2013 Bolero MURAKAMI
|
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-05-19 09:46:38 +00:00
|
|
|
#ifndef SPROUT_LIBS_STRING_TEST_STRING_CPP
|
|
|
|
#define SPROUT_LIBS_STRING_TEST_STRING_CPP
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/string.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container.hpp>
|
2011-12-23 11:59:33 +00:00
|
|
|
#include <testspr/tools.hpp>
|
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
static void string_test() {
|
|
|
|
using namespace sprout;
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR char cstr[] = "foobar1234";
|
2013-02-04 16:02:59 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR auto str1 = sprout::to_string(cstr);
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str2 = sprout::to_string("hogehoge");
|
2011-12-23 11:59:33 +00:00
|
|
|
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT((std::is_same<decltype(str1), sprout::basic_string<char, 10> const>::value));
|
|
|
|
TESTSPR_BOTH_ASSERT((std::is_same<decltype(str2), sprout::basic_string<char, 8> const>::value));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
2013-08-09 10:04:37 +00:00
|
|
|
// constructor
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type();
|
|
|
|
TESTSPR_BOTH_ASSERT(s1.size() == 0);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = str1;
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == str1);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR std::decay<decltype(str1)>::type s1 = str2;
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == str2);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = std::decay<decltype(str1)>::type(str1, 6);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "1234");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = std::decay<decltype(str1)>::type(str1, 0, 6);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "foobar");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = std::decay<decltype(str1)>::type(str2, 4);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "hoge");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = std::decay<decltype(str1)>::type(str2, 0, 4);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "hoge");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(cstr);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == cstr);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(cstr, 6);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "foobar");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(static_cast<char const*>(cstr));
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == cstr);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(static_cast<char const*>(cstr), 6);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "foobar");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(cstr, cstr + 6);
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "foobar");
|
|
|
|
}
|
2013-09-05 13:52:42 +00:00
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(testspr::reduct_input(str1.begin()), testspr::reduct_input(str1.begin() + 6));
|
|
|
|
TESTSPR_BOTH_ASSERT(s1 == "foobar");
|
|
|
|
}
|
2013-08-09 10:04:37 +00:00
|
|
|
{
|
|
|
|
auto s1 = sprout::string_t<10>::type({'f', 'o', 'o', 'b', 'a', 'r'});
|
|
|
|
TESTSPR_ASSERT(s1 == "foobar");
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:59:33 +00:00
|
|
|
// begin
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *str1.begin());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// cbegin
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *str1.cbegin());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// end
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[9] == *(str1.end() - 1));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// cend
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[9] == *(str1.cend() - 1));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// rbegin
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[9] == *str1.rbegin());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// crbegin
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[9] == *str1.crbegin());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// rend
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *(str1.rend() - 1));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// crend
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *(str1.crend() - 1));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// size
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.size() == 10);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// empty
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(!str1.empty());
|
2013-02-18 17:49:10 +00:00
|
|
|
TESTSPR_BOTH_ASSERT((sprout::string_t<0>::type().empty()));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// max_size
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.max_size() == 10);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator[]
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == str1[0]);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// at
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == str1.at(0));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// front
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == str1.front());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// back
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[9] == str1.back());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// data
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *str1.data());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// c_str
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(cstr[0] == *str1.c_str());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// swap
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s1 = sprout::to_string("abc");
|
|
|
|
auto s2 = sprout::to_string("ABC");
|
2011-12-23 11:59:33 +00:00
|
|
|
s1.swap(s2);
|
|
|
|
TESTSPR_ASSERT(s1[0] == 'A');
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
|
|
|
s.assign(sprout::to_string("ABC"));
|
2011-12-23 11:59:33 +00:00
|
|
|
TESTSPR_ASSERT(s.size() == 3);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
|
|
|
s.assign(sprout::to_string("ABC"), 0, 2);
|
2011-12-23 11:59:33 +00:00
|
|
|
TESTSPR_ASSERT(s.size() == 2);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
2011-12-23 11:59:33 +00:00
|
|
|
s.assign("ABC", 2);
|
|
|
|
TESTSPR_ASSERT(s.size() == 2);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
2011-12-23 11:59:33 +00:00
|
|
|
s.assign("ABC");
|
|
|
|
TESTSPR_ASSERT(s.size() == 3);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
2011-12-23 11:59:33 +00:00
|
|
|
s.assign(1, 'A');
|
|
|
|
TESTSPR_ASSERT(s.size() == 1);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator=
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
|
|
|
s = sprout::to_string("ABC");
|
2011-12-23 11:59:33 +00:00
|
|
|
TESTSPR_ASSERT(s.size() == 3);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
2011-12-23 11:59:33 +00:00
|
|
|
s = "ABC";
|
|
|
|
TESTSPR_ASSERT(s.size() == 3);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
auto s = sprout::to_string("abc");
|
2011-12-23 11:59:33 +00:00
|
|
|
s = 'A';
|
|
|
|
TESTSPR_ASSERT(s.size() == 1);
|
|
|
|
TESTSPR_ASSERT(s[0] == 'A');
|
|
|
|
}
|
|
|
|
|
2012-10-08 05:14:59 +00:00
|
|
|
// find
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find(str2) == npos);
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find(sprout::to_string("bar")) == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find(str2.c_str()) == npos);
|
2012-10-08 09:01:11 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find("bar") == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find(str2.c_str(), 0, 3) == npos);
|
2012-10-08 09:01:11 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find("barbar", 0, 3) == 3);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find('b') == 3);
|
|
|
|
|
|
|
|
// rfind
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind(str2) == npos);
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind(sprout::to_string("bar")) == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str()) == npos);
|
2012-10-08 09:01:11 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind("bar") == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str(), npos, 3) == npos);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind("barbar", npos, 3) == 3);
|
2012-10-08 09:01:11 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.rfind('b') == 3);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
2012-10-08 12:29:35 +00:00
|
|
|
// find_first_of
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::to_string("vwxyz")) == npos);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::to_string("rab")) == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz") == npos);
|
2012-10-08 12:29:35 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of("rab") == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz", 0, 3) == npos);
|
2012-10-08 12:29:35 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of("rabrab", 0, 3) == 3);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_of('b') == 3);
|
|
|
|
|
|
|
|
// find_last_of
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::to_string("vwxyz")) == npos);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::to_string("rab")) == 5);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz") == npos);
|
2012-10-08 12:29:35 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of("rab") == 5);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz", npos, 3) == npos);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of("rabrab", npos, 3) == 5);
|
2012-10-08 12:29:35 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_of('r') == 5);
|
|
|
|
|
2012-10-08 13:14:42 +00:00
|
|
|
// find_first_not_of
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1) == npos);
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of(sprout::to_string("foo")) == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str()) == npos);
|
2012-10-08 13:14:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of("foo") == 3);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str(), 0, 10) == npos);
|
2012-10-08 13:14:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of("foofoo", 0, 3) == 3);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_first_not_of('f') == 1);
|
|
|
|
|
|
|
|
// find_last_not_of
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1) == npos);
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of(sprout::to_string("4321")) == 5);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str()) == npos);
|
2012-10-08 13:14:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of("4321") == 5);
|
2012-10-08 14:49:05 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str(), npos, 10) == npos);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of("43214321", npos, 4) == 5);
|
2012-10-08 13:14:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.find_last_not_of('4') == 8);
|
|
|
|
|
2011-12-23 11:59:33 +00:00
|
|
|
// substr
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr();
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar1234");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr(6);
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "1234");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr(0, 6);
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 05:14:59 +00:00
|
|
|
// compare
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(str1) == 0);
|
2013-02-04 16:02:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(sprout::to_string("zzzz")) < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str2.compare(sprout::to_string("aaaa")) > 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("foo")) == 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("zzzz")) < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::to_string("aaaa")) > 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("foo"), 0, 3) == 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::to_string("zzzz"), 0, 3) < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::to_string("aaaa"), 0, 3) > 0);
|
2012-10-08 05:14:59 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(str1.c_str()) == 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare("zzzz") < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare("aaaa") > 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "foo") == 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "zzzz") < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "aaaa") > 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "foo", 3) == 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "zzzz", 3) < 0);
|
|
|
|
TESTSPR_BOTH_ASSERT(str1.compare(0, 3, "aaaa", 3) > 0);
|
|
|
|
|
2011-12-23 11:59:33 +00:00
|
|
|
// operator==
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(!(str1 == str2));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator!=
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1 != str2);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator<
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1 < str2);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator>
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(!(str1 > str2));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator<=
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str1 <= str2);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator>=
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(!(str1 >= str2));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator+
|
|
|
|
{
|
2013-08-16 15:10:42 +00:00
|
|
|
#ifdef SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
2011-12-23 11:59:33 +00:00
|
|
|
// ! Error in GCC4.7
|
2013-02-04 16:02:59 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = str1 + sprout::to_string("hogehoge");
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar1234hogehoge");
|
2011-12-23 11:59:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str4 = str1 + str2;
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str4 == "foobar1234hogehoge");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// operator<<
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os << str1;
|
|
|
|
TESTSPR_ASSERT(os.str() == cstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator>>
|
|
|
|
{
|
|
|
|
std::istringstream is("hogehoge piyopiyo");
|
|
|
|
auto str3 = str1;
|
|
|
|
is >> str3;
|
|
|
|
TESTSPR_ASSERT(str3 == "hogehoge");
|
|
|
|
}
|
|
|
|
|
|
|
|
// string_from_c_str
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = string_from_c_str<10>(cstr);
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar1234");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = string_from_c_str<10>(cstr, 6);
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make_string
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto str3 = make_string('f', 'o', 'o', 'b', 'a', 'r');
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar");
|
|
|
|
TESTSPR_BOTH_ASSERT(str3.size() == 6);
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// operator basic_string
|
|
|
|
{
|
2013-02-04 16:02:59 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR string_t<10>::type str3 = sprout::to_string("foobar");
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(str3 == "foobar");
|
|
|
|
TESTSPR_BOTH_ASSERT(str3.size() == 6);
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
2013-02-04 16:02:59 +00:00
|
|
|
|
|
|
|
// get
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(str1) == 'f');
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::tuples::get<1>(str1) == 'o');
|
|
|
|
{
|
|
|
|
auto str3 = str1;
|
|
|
|
TESTSPR_ASSERT(sprout::tuples::get<0>(str3) == 'f');
|
|
|
|
TESTSPR_ASSERT(sprout::tuples::get<1>(str3) == 'o');
|
|
|
|
}
|
|
|
|
|
|
|
|
// tuple_size
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size<decltype(str1)>::value == 10);
|
|
|
|
|
|
|
|
// tuple_element
|
|
|
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<0, decltype(str1)>::type, char const>::value));
|
|
|
|
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<1, decltype(str1)>::type, char const>::value));
|
|
|
|
|
|
|
|
// is_string
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::is_string<decltype(str1)>::value);
|
|
|
|
TESTSPR_BOTH_ASSERT(!sprout::is_string<int>::value);
|
|
|
|
|
|
|
|
// sprout::to_hash, sprout::hash
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::to_hash(str1) == sprout::hash<decltype(str1)>()(str1));
|
|
|
|
TESTSPR_BOTH_ASSERT(sprout::to_hash(str1) != sprout::to_hash(str2));
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace testspr
|
|
|
|
|
2012-05-19 09:46:38 +00:00
|
|
|
#ifndef TESTSPR_CPP_INCLUDE
|
|
|
|
# define TESTSPR_TEST_FUNCTION testspr::string_test
|
|
|
|
# include <testspr/include_main.hpp>
|
|
|
|
#endif
|
2011-12-23 11:59:33 +00:00
|
|
|
|
2012-05-19 09:46:38 +00:00
|
|
|
#endif // #ifndef SPROUT_LIBS_STRING_TEST_STRING_CPP
|