SFML/test/System/String.test.cpp

561 lines
20 KiB
C++
Raw Permalink Normal View History

#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>
#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 && "Invalid to select between identical inputs");
2023-03-23 11:40:17 +08:00
if constexpr (sizeof(wchar_t) == 2)
return string16;
else
return string32;
}
2024-05-17 10:56:30 +08:00
auto toHex(const std::uint32_t character)
{
std::ostringstream stream;
2024-05-17 10:56:30 +08:00
stream << "[\\x" << std::uppercase << std::hex << 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<sf::U8String>
2023-03-23 11:40:17 +08:00
{
static std::string convert(const sf::U8String& 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-01-18 12:51:08 +08:00
} // namespace Catch
2023-03-23 11:40:17 +08:00
TEST_CASE("[System] sf::U8StringCharTraits")
{
SECTION("Type traits")
{
STATIC_CHECK(std::is_copy_constructible_v<sf::U8StringCharTraits>);
STATIC_CHECK(std::is_copy_assignable_v<sf::U8StringCharTraits>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::U8StringCharTraits>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::U8StringCharTraits>);
}
SECTION("assign(char_type&, const char_type&)")
{
sf::U8StringCharTraits::char_type c1 = 'a';
const sf::U8StringCharTraits::char_type c2 = 'b';
sf::U8StringCharTraits::assign(c1, c2);
CHECK(c1 == 'b');
CHECK(c2 == 'b');
}
SECTION("assign(char_type*, std::size_t, char_type)")
{
sf::U8StringCharTraits::char_type s[] = {'a', 'b', 'c', '\0'};
CHECK(sf::U8StringCharTraits::assign(s, 2, 'd') == &s[0]);
CHECK(s[0] == 'd');
CHECK(s[1] == 'd');
CHECK(s[2] == 'c');
}
SECTION("eq()")
{
CHECK(sf::U8StringCharTraits::eq(0, 0));
CHECK(!sf::U8StringCharTraits::eq(1, 0));
CHECK(!sf::U8StringCharTraits::eq(0, 1));
CHECK(sf::U8StringCharTraits::eq(1, 1));
}
SECTION("lt()")
{
CHECK(!sf::U8StringCharTraits::lt(0, 0));
CHECK(!sf::U8StringCharTraits::lt(1, 0));
CHECK(sf::U8StringCharTraits::lt(0, 1));
CHECK(!sf::U8StringCharTraits::lt(1, 1));
}
SECTION("move()")
{
sf::U8StringCharTraits::char_type s1[] = {'a', 'b', 'c', '\0'};
const sf::U8StringCharTraits::char_type s2[] = {'d', 'e', 'f', '\0'};
CHECK(sf::U8StringCharTraits::move(s1, s2, std::size(s2)) == s1);
CHECK(s1[0] == 'd');
CHECK(s1[1] == 'e');
CHECK(s1[2] == 'f');
CHECK(s2[0] == 'd');
CHECK(s2[1] == 'e');
CHECK(s2[2] == 'f');
}
SECTION("copy()")
{
sf::U8StringCharTraits::char_type s1[] = {'a', 'b', 'c', '\0'};
const sf::U8StringCharTraits::char_type s2[] = {'d', 'e', 'f', '\0'};
CHECK(sf::U8StringCharTraits::copy(s1, s2, std::size(s2)) == s1);
CHECK(s1[0] == 'd');
CHECK(s1[1] == 'e');
CHECK(s1[2] == 'f');
CHECK(s2[0] == 'd');
CHECK(s2[1] == 'e');
CHECK(s2[2] == 'f');
}
SECTION("compare()")
{
const sf::U8StringCharTraits::char_type s1[] = {'a', 'b', 'c', '\0'};
const sf::U8StringCharTraits::char_type s2[] = {'a', 'b', 'c', '\0'};
const sf::U8StringCharTraits::char_type s3[] = {'d', 'e', 'f', '\0'};
CHECK(sf::U8StringCharTraits::compare(s1, s2, std::size(s1)) == 0);
CHECK(sf::U8StringCharTraits::compare(s1, s3, std::size(s1)) < 0);
CHECK(sf::U8StringCharTraits::compare(s3, s1, std::size(s3)) > 0);
}
SECTION("length()")
{
const sf::U8StringCharTraits::char_type s1[] = {'a', '\0'};
const sf::U8StringCharTraits::char_type s2[] = {'a', 'b', 'c', 'd', 'e', '\0'};
CHECK(sf::U8StringCharTraits::length(s1) == 1);
CHECK(sf::U8StringCharTraits::length(s2) == 5);
}
SECTION("find()")
{
const sf::U8StringCharTraits::char_type s[] = {'a', 'b', 'c', 'd', 'e'};
CHECK(*sf::U8StringCharTraits::find(s, std::size(s), 'a') == 'a');
CHECK(sf::U8StringCharTraits::find(s, std::size(s), 'f') == nullptr);
}
SECTION("to_char_type()")
{
CHECK(sf::U8StringCharTraits::to_char_type(sf::U8StringCharTraits::int_type{0}) ==
sf::U8StringCharTraits::char_type{0});
CHECK(sf::U8StringCharTraits::to_char_type(sf::U8StringCharTraits::int_type{1}) ==
sf::U8StringCharTraits::char_type{1});
CHECK(sf::U8StringCharTraits::to_char_type(sf::U8StringCharTraits::int_type{10}) ==
sf::U8StringCharTraits::char_type{10});
}
SECTION("to_int_type()")
{
CHECK(sf::U8StringCharTraits::to_int_type(sf::U8StringCharTraits::char_type{0}) ==
sf::U8StringCharTraits::int_type{0});
CHECK(sf::U8StringCharTraits::to_int_type(sf::U8StringCharTraits::char_type{1}) ==
sf::U8StringCharTraits::int_type{1});
CHECK(sf::U8StringCharTraits::to_int_type(sf::U8StringCharTraits::char_type{10}) ==
sf::U8StringCharTraits::int_type{10});
}
SECTION("eq_int_type()")
{
CHECK(sf::U8StringCharTraits::eq_int_type(sf::U8StringCharTraits::int_type{0}, sf::U8StringCharTraits::int_type{0}));
CHECK(sf::U8StringCharTraits::eq_int_type(sf::U8StringCharTraits::int_type{1}, sf::U8StringCharTraits::int_type{1}));
CHECK(sf::U8StringCharTraits::eq_int_type(sf::U8StringCharTraits::int_type{10},
sf::U8StringCharTraits::int_type{10}));
}
SECTION("eof()")
{
CHECK(sf::U8StringCharTraits::eof() == ~sf::U8StringCharTraits::int_type{0});
}
SECTION("not_eof()")
{
CHECK(sf::U8StringCharTraits::not_eof(sf::U8StringCharTraits::int_type{0}) == sf::U8StringCharTraits::int_type{0});
CHECK(sf::U8StringCharTraits::not_eof(sf::U8StringCharTraits::int_type{1}) == sf::U8StringCharTraits::int_type{1});
CHECK(sf::U8StringCharTraits::not_eof(sf::U8StringCharTraits::int_type{10}) == sf::U8StringCharTraits::int_type{10});
CHECK(sf::U8StringCharTraits::not_eof(sf::U8StringCharTraits::eof()) != sf::U8StringCharTraits::eof());
}
}
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).empty());
CHECK(std::wstring(string).empty());
CHECK(string.toAnsiString().empty());
CHECK(string.toWideString().empty());
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
{
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() == sf::U8String{'a'});
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
{
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() == sf::U8String{'d', 'e', 'f'});
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
{
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() == sf::U8String{'g', 'h', 'i'});
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
{
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() == sf::U8String{0xC3, 0xBA});
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
{
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() == sf::U8String{'j', 0xC3, 0xBA, 'l'});
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
{
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() == sf::U8String{'m', 'n', 'o', 0xC3, 0XBA});
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
{
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() == sf::U8String{0xF4, 0x8A, 0xBE, 0xAF});
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
{
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() == sf::U8String{0xF4, 0x8A, 0xAF, 0x8D, 'r', 's'});
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
{
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() == sf::U8String{'t', 'u', 'v', 0xF4, 0x84, 0x8C, 0xA1});
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")
{
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() == sf::U8String{'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")
{
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() == sf::U8String{0xC3, 0xB1, 'x', 'y', 'z'});
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() == sf::U8String{'w', 0xF4, 0x84, 0x8C, 0xA1, 'y', 'z'});
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"));
}
}
}