mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Test constructing strings from nullptr
This commit is contained in:
parent
fbd8407a5f
commit
0a8f19db7a
@ -240,17 +240,35 @@ TEST_CASE("[System] sf::String")
|
|||||||
|
|
||||||
SECTION("ANSI C string constructor")
|
SECTION("ANSI C string constructor")
|
||||||
{
|
{
|
||||||
const sf::String string = "def";
|
SECTION("Nullptr")
|
||||||
CHECK(std::string(string) == "def"s);
|
{
|
||||||
CHECK(std::wstring(string) == L"def"s);
|
const sf::String string = static_cast<char*>(nullptr);
|
||||||
CHECK(string.toAnsiString() == "def"s);
|
CHECK(std::string(string).empty());
|
||||||
CHECK(string.toWideString() == L"def"s);
|
CHECK(std::wstring(string).empty());
|
||||||
CHECK(string.toUtf8() == sf::U8String{'d', 'e', 'f'});
|
CHECK(string.toAnsiString().empty());
|
||||||
CHECK(string.toUtf16() == u"def"s);
|
CHECK(string.toWideString().empty());
|
||||||
CHECK(string.toUtf32() == U"def"s);
|
CHECK(string.toUtf8().empty());
|
||||||
CHECK(string.getSize() == 3);
|
CHECK(string.toUtf16().empty());
|
||||||
CHECK(!string.isEmpty());
|
CHECK(string.toUtf32().empty());
|
||||||
CHECK(string.getData() != nullptr);
|
CHECK(string.getSize() == 0);
|
||||||
|
CHECK(string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Non-empty string")
|
||||||
|
{
|
||||||
|
const sf::String string = "def";
|
||||||
|
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);
|
||||||
|
CHECK(string.getSize() == 3);
|
||||||
|
CHECK(!string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ANSI string constructor")
|
SECTION("ANSI string constructor")
|
||||||
@ -285,17 +303,35 @@ TEST_CASE("[System] sf::String")
|
|||||||
|
|
||||||
SECTION("Wide C string constructor")
|
SECTION("Wide C string constructor")
|
||||||
{
|
{
|
||||||
const sf::String string = L"j\xFAl";
|
SECTION("Nullptr")
|
||||||
CHECK(std::string(string) == select("j\xFAl"s, "j\0l"s));
|
{
|
||||||
CHECK(std::wstring(string) == L"j\xFAl"s);
|
const sf::String string = static_cast<wchar_t*>(nullptr);
|
||||||
CHECK(string.toAnsiString() == select("j\xFAl"s, "j\0l"s));
|
CHECK(std::string(string).empty());
|
||||||
CHECK(string.toWideString() == L"j\xFAl"s);
|
CHECK(std::wstring(string).empty());
|
||||||
CHECK(string.toUtf8() == sf::U8String{'j', 0xC3, 0xBA, 'l'});
|
CHECK(string.toAnsiString().empty());
|
||||||
CHECK(string.toUtf16() == u"j\xFAl"s);
|
CHECK(string.toWideString().empty());
|
||||||
CHECK(string.toUtf32() == U"j\xFAl"s);
|
CHECK(string.toUtf8().empty());
|
||||||
CHECK(string.getSize() == 3);
|
CHECK(string.toUtf16().empty());
|
||||||
CHECK(!string.isEmpty());
|
CHECK(string.toUtf32().empty());
|
||||||
CHECK(string.getData() != nullptr);
|
CHECK(string.getSize() == 0);
|
||||||
|
CHECK(string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Non-empty string")
|
||||||
|
{
|
||||||
|
const sf::String string = L"j\xFAl";
|
||||||
|
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);
|
||||||
|
CHECK(string.getSize() == 3);
|
||||||
|
CHECK(!string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Wide string constructor")
|
SECTION("Wide string constructor")
|
||||||
@ -330,17 +366,35 @@ TEST_CASE("[System] sf::String")
|
|||||||
|
|
||||||
SECTION("UTF-32 C string constructor")
|
SECTION("UTF-32 C string constructor")
|
||||||
{
|
{
|
||||||
const sf::String string = U"\U0010ABCDrs";
|
SECTION("Nullptr")
|
||||||
CHECK(std::string(string) == "\0rs"s);
|
{
|
||||||
CHECK(std::wstring(string) == select(L"rs"s, L"\U0010ABCDrs"s));
|
const sf::String string = static_cast<char32_t*>(nullptr);
|
||||||
CHECK(string.toAnsiString() == "\0rs"s);
|
CHECK(std::string(string).empty());
|
||||||
CHECK(string.toWideString() == select(L"rs"s, L"\U0010ABCDrs"s));
|
CHECK(std::wstring(string).empty());
|
||||||
CHECK(string.toUtf8() == sf::U8String{0xF4, 0x8A, 0xAF, 0x8D, 'r', 's'});
|
CHECK(string.toAnsiString().empty());
|
||||||
CHECK(string.toUtf16() == u"\U0010ABCDrs"s);
|
CHECK(string.toWideString().empty());
|
||||||
CHECK(string.toUtf32() == U"\U0010ABCDrs"s);
|
CHECK(string.toUtf8().empty());
|
||||||
CHECK(string.getSize() == 3);
|
CHECK(string.toUtf16().empty());
|
||||||
CHECK(!string.isEmpty());
|
CHECK(string.toUtf32().empty());
|
||||||
CHECK(string.getData() != nullptr);
|
CHECK(string.getSize() == 0);
|
||||||
|
CHECK(string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Non-empty string")
|
||||||
|
{
|
||||||
|
const sf::String string = U"\U0010ABCDrs";
|
||||||
|
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);
|
||||||
|
CHECK(string.getSize() == 3);
|
||||||
|
CHECK(!string.isEmpty());
|
||||||
|
CHECK(string.getData() != nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("UTF-32 string constructor")
|
SECTION("UTF-32 string constructor")
|
||||||
|
Loading…
Reference in New Issue
Block a user