2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/System/String.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-03-23 11:40:17 +08:00
|
|
|
|
|
|
|
#include <GraphicsUtil.hpp>
|
|
|
|
#include <array>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-04-24 20:13:52 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2023-03-23 11:40:17 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
// Return either argument depending on whether wchar_t is 16 or 32 bits
|
|
|
|
// Lets us write tests that work on both Windows where wchar_t is 16 bits
|
|
|
|
// and elsewhere where it is 32. Otherwise the tests would only work on
|
|
|
|
// one OS or the other.
|
|
|
|
template <typename T>
|
|
|
|
auto select(const std::basic_string<T>& string16, const std::basic_string<T>& string32)
|
|
|
|
{
|
|
|
|
assert(string16 != string32);
|
|
|
|
if constexpr (sizeof(wchar_t) == 2)
|
|
|
|
return string16;
|
|
|
|
else
|
|
|
|
return string32;
|
|
|
|
}
|
2023-03-26 12:02:29 +08:00
|
|
|
|
|
|
|
template <typename CharT>
|
|
|
|
auto toHex(const CharT character)
|
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << "[\\x" << std::uppercase << std::hex << static_cast<std::uint32_t>(character) << ']';
|
|
|
|
return stream.str();
|
|
|
|
}
|
2023-03-23 11:40:17 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Specialize StringMaker for alternative std::basic_string<T> specializations
|
|
|
|
// std::string's string conversion cannot be specialized but all other string types get special treatment
|
2023-01-18 12:51:08 +08:00
|
|
|
// https://github.com/catchorg/Catch2/blob/devel/docs/tostring.md#catchstringmaker-specialisation
|
|
|
|
namespace Catch
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
template <>
|
|
|
|
struct StringMaker<std::basic_string<std::uint8_t>>
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
static std::string convert(const std::basic_string<std::uint8_t>& string)
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
std::ostringstream output;
|
2023-03-23 11:40:17 +08:00
|
|
|
for (const auto character : string)
|
|
|
|
{
|
|
|
|
if (character >= 32 && character < 127)
|
2023-01-18 12:51:08 +08:00
|
|
|
output << std::string(1, static_cast<char>(character));
|
2023-03-23 11:40:17 +08:00
|
|
|
else
|
2023-01-18 12:51:08 +08:00
|
|
|
output << toHex(character);
|
2023-03-23 11:40:17 +08:00
|
|
|
}
|
2023-01-18 12:51:08 +08:00
|
|
|
return output.str();
|
2023-03-26 12:02:29 +08:00
|
|
|
}
|
|
|
|
};
|
2023-01-18 12:51:08 +08:00
|
|
|
} // namespace Catch
|
2023-03-23 11:40:17 +08:00
|
|
|
|
|
|
|
TEST_CASE("[System] sf::String")
|
|
|
|
{
|
|
|
|
using namespace std::string_literals;
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::String>);
|
|
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::String>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::String>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::String>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Default constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
const sf::String string;
|
|
|
|
CHECK(std::string(string) == ""s);
|
|
|
|
CHECK(std::wstring(string) == L""s);
|
|
|
|
CHECK(string.toAnsiString() == ""s);
|
|
|
|
CHECK(string.toWideString() == L""s);
|
2023-01-18 12:51:08 +08:00
|
|
|
CHECK(string.toUtf8().empty());
|
|
|
|
CHECK(string.toUtf16().empty());
|
|
|
|
CHECK(string.toUtf32().empty());
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 0);
|
|
|
|
CHECK(string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("ANSI character constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = 'a';
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "a"s);
|
|
|
|
CHECK(std::wstring(string) == L"a"s);
|
|
|
|
CHECK(string.toAnsiString() == "a"s);
|
|
|
|
CHECK(string.toWideString() == L"a"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'a'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"a"s);
|
|
|
|
CHECK(string.toUtf32() == U"a"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 1);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("ANSI C string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = "def";
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "def"s);
|
|
|
|
CHECK(std::wstring(string) == L"def"s);
|
|
|
|
CHECK(string.toAnsiString() == "def"s);
|
|
|
|
CHECK(string.toWideString() == L"def"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'d', 'e', 'f'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"def"s);
|
|
|
|
CHECK(string.toUtf32() == U"def"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 3);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("ANSI string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = "ghi"s;
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "ghi"s);
|
|
|
|
CHECK(std::wstring(string) == L"ghi"s);
|
|
|
|
CHECK(string.toAnsiString() == "ghi"s);
|
|
|
|
CHECK(string.toWideString() == L"ghi"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'g', 'h', 'i'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"ghi"s);
|
|
|
|
CHECK(string.toUtf32() == U"ghi"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 3);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Wide character constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = L'\xFA';
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == select("\xFA"s, "\0"s));
|
|
|
|
CHECK(std::wstring(string) == L"\xFA"s);
|
|
|
|
CHECK(string.toAnsiString() == select("\xFA"s, "\0"s));
|
|
|
|
CHECK(string.toWideString() == L"\xFA"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{0xC3, 0xBA});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"\xFA"s);
|
|
|
|
CHECK(string.toUtf32() == U"\xFA"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 1);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Wide C string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = L"j\xFAl";
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == select("j\xFAl"s, "j\0l"s));
|
|
|
|
CHECK(std::wstring(string) == L"j\xFAl"s);
|
|
|
|
CHECK(string.toAnsiString() == select("j\xFAl"s, "j\0l"s));
|
|
|
|
CHECK(string.toWideString() == L"j\xFAl"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'j', 0xC3, 0xBA, 'l'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"j\xFAl"s);
|
|
|
|
CHECK(string.toUtf32() == U"j\xFAl"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 3);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Wide string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = L"mno\xFA"s;
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == select("mno\xFA"s, "mno\0"s));
|
|
|
|
CHECK(std::wstring(string) == L"mno\xFA"s);
|
|
|
|
CHECK(string.toAnsiString() == select("mno\xFA"s, "mno\0"s));
|
|
|
|
CHECK(string.toWideString() == L"mno\xFA"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'m', 'n', 'o', 0xC3, 0XBA});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"mno\xFA"s);
|
|
|
|
CHECK(string.toUtf32() == U"mno\xFA"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 4);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("UTF-32 character constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = U'\U0010AFAF';
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "\0"s);
|
|
|
|
CHECK(std::wstring(string) == select(L""s, L"\U0010AFAF"s));
|
|
|
|
CHECK(string.toAnsiString() == "\0"s);
|
|
|
|
CHECK(string.toWideString() == select(L""s, L"\U0010AFAF"s));
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{0xF4, 0x8A, 0xBE, 0xAF});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"\U0010AFAF"s);
|
|
|
|
CHECK(string.toUtf32() == U"\U0010AFAF"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 1);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("UTF-32 C string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = U"\U0010ABCDrs";
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "\0rs"s);
|
|
|
|
CHECK(std::wstring(string) == select(L"rs"s, L"\U0010ABCDrs"s));
|
|
|
|
CHECK(string.toAnsiString() == "\0rs"s);
|
|
|
|
CHECK(string.toWideString() == select(L"rs"s, L"\U0010ABCDrs"s));
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{0xF4, 0x8A, 0xAF, 0x8D, 'r', 's'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"\U0010ABCDrs"s);
|
|
|
|
CHECK(string.toUtf32() == U"\U0010ABCDrs"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 3);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("UTF-32 string constructor")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-03-26 12:02:29 +08:00
|
|
|
const sf::String string = U"tuv\U00104321"s;
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(std::string(string) == "tuv\0"s);
|
|
|
|
CHECK(std::wstring(string) == select(L"tuv"s, L"tuv\U00104321"s));
|
|
|
|
CHECK(string.toAnsiString() == "tuv\0"s);
|
|
|
|
CHECK(string.toWideString() == select(L"tuv"s, L"tuv\U00104321"s));
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'t', 'u', 'v', 0xF4, 0x84, 0x8C, 0xA1});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"tuv\U00104321"s);
|
|
|
|
CHECK(string.toUtf32() == U"tuv\U00104321"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 4);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("fromUtf8()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Nominal")
|
2023-03-05 16:40:34 +08:00
|
|
|
{
|
|
|
|
constexpr std::array<std::uint8_t, 4> characters{'w', 'x', 'y', 'z'};
|
|
|
|
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
|
|
|
CHECK(std::string(string) == "wxyz"s);
|
|
|
|
CHECK(std::wstring(string) == L"wxyz"s);
|
|
|
|
CHECK(string.toAnsiString() == "wxyz"s);
|
|
|
|
CHECK(string.toWideString() == L"wxyz"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'w', 'x', 'y', 'z'});
|
|
|
|
CHECK(string.toUtf16() == u"wxyz"s);
|
|
|
|
CHECK(string.toUtf32() == U"wxyz"s);
|
|
|
|
CHECK(string.getSize() == 4);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Insufficient input")
|
2023-03-05 16:40:34 +08:00
|
|
|
{
|
|
|
|
constexpr std::array<std::uint8_t, 1> characters{251};
|
|
|
|
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
|
|
|
constexpr char32_t defaultReplacementCharacter = 0;
|
|
|
|
CHECK(string.getSize() == 1);
|
|
|
|
CHECK(string[0] == defaultReplacementCharacter);
|
|
|
|
}
|
2023-03-23 11:40:17 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("fromUtf16()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
constexpr std::array<std::uint16_t, 4> characters{0xF1, 'x', 'y', 'z'};
|
|
|
|
const sf::String string = sf::String::fromUtf16(characters.begin(), characters.end());
|
|
|
|
CHECK(std::string(string) == select("\xF1xyz"s, "\0xyz"s));
|
|
|
|
CHECK(std::wstring(string) == L"\xF1xyz"s);
|
|
|
|
CHECK(string.toAnsiString() == select("\xF1xyz"s, "\0xyz"s));
|
|
|
|
CHECK(string.toWideString() == L"\xF1xyz"s);
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{0xC3, 0xB1, 'x', 'y', 'z'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"\xF1xyz"s);
|
|
|
|
CHECK(string.toUtf32() == U"\xF1xyz"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 4);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("fromUtf32()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
constexpr std::array<std::uint32_t, 4> characters{'w', 0x104321, 'y', 'z'};
|
|
|
|
const sf::String string = sf::String::fromUtf32(characters.begin(), characters.end());
|
|
|
|
CHECK(std::string(string) == "w\0yz"s);
|
|
|
|
CHECK(std::wstring(string) == select(L"wyz"s, L"w\U00104321yz"s));
|
|
|
|
CHECK(string.toAnsiString() == "w\0yz"s);
|
|
|
|
CHECK(string.toWideString() == select(L"wyz"s, L"w\U00104321yz"s));
|
|
|
|
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>{'w', 0xF4, 0x84, 0x8C, 0xA1, 'y', 'z'});
|
2023-03-26 12:02:29 +08:00
|
|
|
CHECK(string.toUtf16() == u"w\U00104321yz"s);
|
|
|
|
CHECK(string.toUtf32() == U"w\U00104321yz"s);
|
2023-03-23 11:40:17 +08:00
|
|
|
CHECK(string.getSize() == 4);
|
|
|
|
CHECK(!string.isEmpty());
|
|
|
|
CHECK(string.getData() != nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("clear()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("you'll never guess what happens when you call clear()");
|
|
|
|
string.clear();
|
|
|
|
CHECK(string == sf::String());
|
|
|
|
CHECK(string.getSize() == 0);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("erase()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("what if i want a shorter string?");
|
|
|
|
string.erase(0, 8);
|
|
|
|
string.erase(string.getSize() - 1, 1);
|
|
|
|
CHECK(string == "i want a shorter string");
|
|
|
|
CHECK(string.getSize() == 23);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("insert()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("please insert text");
|
|
|
|
string.insert(7, "don't ");
|
|
|
|
CHECK(string == "please don't insert text");
|
|
|
|
CHECK(string.getSize() == 24);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("find()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
const sf::String string("a little bit of this and a little bit of that");
|
|
|
|
CHECK(string.find("a little bit") == 0);
|
|
|
|
CHECK(string.find("a little bit", 15) == 25);
|
|
|
|
CHECK(string.find("a little bit", 1'000) == sf::String::InvalidPos);
|
|
|
|
CHECK(string.find("no way you find this") == sf::String::InvalidPos);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("replace()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("sfml is the worst");
|
|
|
|
string.replace(12, 5, "best!");
|
|
|
|
CHECK(string == "sfml is the best!");
|
|
|
|
string.replace("the", "THE");
|
|
|
|
CHECK(string == "sfml is THE best!");
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("substring()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
const sf::String string("let's get some substrings");
|
|
|
|
CHECK(string.substring(0) == "let's get some substrings");
|
|
|
|
CHECK(string.substring(10) == "some substrings");
|
|
|
|
CHECK(string.substring(10, 4) == "some");
|
|
|
|
CHECK_THROWS_AS((void)string.substring(1'000), std::out_of_range);
|
|
|
|
CHECK_THROWS_AS((void)string.substring(420, 69), std::out_of_range);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("begin() and end() const")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
const sf::String string("let's test the const iterators");
|
|
|
|
CHECK(*string.begin() == 'l');
|
|
|
|
CHECK(*(string.end() - 1) == 's');
|
|
|
|
for (const auto character : string)
|
|
|
|
CHECK(character != 0);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("begin() and end()")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("let's test the iterators");
|
|
|
|
CHECK(*string.begin() == 'l');
|
|
|
|
CHECK(*(string.end() - 1) == 's');
|
|
|
|
for (auto& character : string)
|
|
|
|
character = 'x';
|
|
|
|
CHECK(string == "xxxxxxxxxxxxxxxxxxxxxxxx");
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Operators")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator+=")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string;
|
|
|
|
string += sf::String("xyz");
|
|
|
|
CHECK(string.toAnsiString() == "xyz"s);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator[] const")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
const sf::String string("the quick brown fox");
|
|
|
|
CHECK(string[0] == 't');
|
|
|
|
CHECK(string[10] == 'b');
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator[]")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
sf::String string("the quick brown fox");
|
|
|
|
CHECK(string[0] == 't');
|
|
|
|
string[1] = 'x';
|
|
|
|
CHECK(string[1] == 'x');
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator==")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String() == sf::String());
|
|
|
|
CHECK_FALSE(sf::String() == sf::String(' '));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator!=")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String() != sf::String(' '));
|
|
|
|
CHECK_FALSE(sf::String() != sf::String());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator<")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String('a') < sf::String('b'));
|
|
|
|
CHECK_FALSE(sf::String() < sf::String());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator>")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String('b') > sf::String('a'));
|
|
|
|
CHECK_FALSE(sf::String() > sf::String());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator<=")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String() <= sf::String());
|
|
|
|
CHECK(sf::String('a') <= sf::String('b'));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator>=")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String() >= sf::String());
|
|
|
|
CHECK(sf::String('b') >= sf::String('a'));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("operator+")
|
2023-03-23 11:40:17 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::String() + sf::String() == sf::String());
|
|
|
|
CHECK(sf::String("abc") + sf::String("def") == sf::String("abcdef"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|