Remove Nz::String and Nz::StringStream
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
TEST_CASE("Apply", "[CORE][ALGORITHM]")
|
||||
{
|
||||
@@ -33,60 +33,60 @@ TEST_CASE("ComputeHash", "[CORE][ALGORITHM]")
|
||||
/*SECTION("Compute CRC32 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_CRC32, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "596A3B55");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "596A3B55");
|
||||
}
|
||||
|
||||
SECTION("Compute CRC64 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_CRC64, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "33302B9FC23855A8");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "33302B9FC23855A8");
|
||||
}
|
||||
|
||||
SECTION("Compute Fletcher16 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_Fletcher16, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "F5CA");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "F5CA");
|
||||
}*/
|
||||
|
||||
SECTION("Compute MD5 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_MD5, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "81DC9BDB52D04DC20036DBD8313ED055");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "81DC9BDB52D04DC20036DBD8313ED055");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA1 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA1, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA224 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA224, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA256 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA256, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA384 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA384, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA512 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA512, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB");
|
||||
}
|
||||
|
||||
SECTION("Compute Whirlpool of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_Whirlpool, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8");
|
||||
REQUIRE(Nz::ToUpper(result.ToHex()) == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ void CheckConstructor(const char* title)
|
||||
|
||||
GIVEN("Iterator and default constructor")
|
||||
{
|
||||
Nz::String anotherDataString("0101");
|
||||
std::string anotherDataString("0101");
|
||||
Nz::Bitset<Block> defaultByte;
|
||||
Nz::Bitset<Block> anotherData(anotherDataString.GetConstBuffer());
|
||||
Nz::Bitset<Block> anotherData(anotherDataString.c_str());
|
||||
|
||||
WHEN("We assign 'anotherData'")
|
||||
{
|
||||
@@ -344,7 +344,7 @@ void CheckReverse(const char* title)
|
||||
{
|
||||
GIVEN("A bitset")
|
||||
{
|
||||
Nz::String bits = "010011100010001101001111";
|
||||
std::string bits = "010011100010001101001111";
|
||||
Nz::Bitset<Block> expected(bits);
|
||||
|
||||
WHEN("We reverse the order of bits")
|
||||
@@ -354,7 +354,9 @@ void CheckReverse(const char* title)
|
||||
|
||||
THEN("The order of bits should be reversed")
|
||||
{
|
||||
CHECK(bitset == Nz::Bitset<Block>(bits.Reversed()));
|
||||
std::string reversedBits = bits;
|
||||
std::reverse(reversedBits.begin(), reversedBits.end());
|
||||
CHECK(bitset == Nz::Bitset<Block>(reversedBits));
|
||||
}
|
||||
AND_WHEN("We reverse the bit order again")
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]")
|
||||
{
|
||||
int value = 5;
|
||||
byteStream << value;
|
||||
Nz::String string = "string";
|
||||
std::string string = "string";
|
||||
byteStream << string;
|
||||
|
||||
byteStream.FlushBits();
|
||||
@@ -29,7 +29,7 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]")
|
||||
readStream = Nz::ByteStream(ptrData, byteStream.GetSize());
|
||||
int retrievedValue = 0;
|
||||
readStream >> retrievedValue;
|
||||
Nz::String retrievedString;
|
||||
std::string retrievedString;
|
||||
readStream >> retrievedString;
|
||||
|
||||
CHECK(value == retrievedValue);
|
||||
@@ -70,4 +70,4 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ SCENARIO("File", "[CORE][FILE]")
|
||||
char message[12];
|
||||
REQUIRE(file.Read(message, 11) == 11);
|
||||
message[11] = '\0';
|
||||
REQUIRE(Nz::String(message) == "Test String");
|
||||
REQUIRE(std::string(message) == "Test String");
|
||||
|
||||
REQUIRE(file.Read(message, 11) == 11);
|
||||
message[11] = '\0';
|
||||
REQUIRE(Nz::String(message) == "Test String");
|
||||
REQUIRE(std::string(message) == "Test String");
|
||||
}
|
||||
|
||||
AND_THEN("We can get its size")
|
||||
@@ -70,7 +70,7 @@ SCENARIO("File", "[CORE][FILE]")
|
||||
WHEN("We read the first line of the file")
|
||||
{
|
||||
REQUIRE(fileTest.IsOpen());
|
||||
Nz::String content = fileTest.ReadLine();
|
||||
std::string content = fileTest.ReadLine();
|
||||
|
||||
THEN("The content must be 'Test'")
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
void nullAction(void*)
|
||||
{
|
||||
}
|
||||
@@ -23,9 +21,9 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
long long intFalse = 0;
|
||||
parameterList.SetParameter("intFalse", intFalse);
|
||||
|
||||
Nz::String strTrue = "true";
|
||||
std::string strTrue = "true";
|
||||
parameterList.SetParameter("strTrue", strTrue);
|
||||
Nz::String strFalse = "false";
|
||||
std::string strFalse = "false";
|
||||
parameterList.SetParameter("strFalse", strFalse);
|
||||
|
||||
THEN("We can get it back")
|
||||
@@ -75,7 +73,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
long long intDouble = 3;
|
||||
parameterList.SetParameter("intDouble", intDouble);
|
||||
|
||||
Nz::String strDouble = "3.0";
|
||||
std::string strDouble = "3.0";
|
||||
parameterList.SetParameter("strDouble", strDouble);
|
||||
|
||||
THEN("We can get it back")
|
||||
@@ -113,7 +111,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
double doubleInt = 3;
|
||||
parameterList.SetParameter("doubleInt", doubleInt);
|
||||
|
||||
Nz::String strInt = "3";
|
||||
std::string strInt = "3";
|
||||
parameterList.SetParameter("strInt", strInt);
|
||||
|
||||
THEN("We can get it back")
|
||||
@@ -149,7 +147,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
|
||||
WHEN("We add String 'string' and analogous")
|
||||
{
|
||||
Nz::String string("string");
|
||||
std::string string("string");
|
||||
parameterList.SetParameter("string", string);
|
||||
|
||||
bool trueString = 1;
|
||||
@@ -168,14 +166,14 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Nz::String newString;
|
||||
std::string newString;
|
||||
CHECK(parameterList.GetStringParameter("string", &newString));
|
||||
CHECK(newString == string);
|
||||
}
|
||||
|
||||
THEN("Conversion from bool to str should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("trueString", &retrievedValue));
|
||||
CHECK(retrievedValue == "true");
|
||||
CHECK(parameterList.GetStringParameter("falseString", &retrievedValue));
|
||||
@@ -184,21 +182,21 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
|
||||
THEN("Conversion from color to string should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("colorString", &retrievedValue));
|
||||
CHECK(retrievedValue == colorString.ToString());
|
||||
}
|
||||
|
||||
THEN("Conversion from string to double should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("doubleString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3");
|
||||
CHECK(retrievedValue == "3.000000");
|
||||
}
|
||||
|
||||
THEN("Conversion from string to int should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
std::string retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("intString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3");
|
||||
}
|
||||
|
||||
@@ -249,8 +249,8 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
||||
THEN("String")
|
||||
{
|
||||
context.stream->SetCursorPos(0);
|
||||
Nz::String string = "string";
|
||||
Nz::String copy(string);
|
||||
std::string string = "string";
|
||||
std::string copy(string);
|
||||
REQUIRE(Serialize(context, string));
|
||||
string = "another";
|
||||
REQUIRE(string != copy);
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("String", "[CORE][STRING]")
|
||||
{
|
||||
GIVEN("One string 'a'")
|
||||
{
|
||||
Nz::String aDefaultString(1, 'a');
|
||||
|
||||
WHEN("We add information")
|
||||
{
|
||||
aDefaultString.Append("Default");
|
||||
aDefaultString.Insert(aDefaultString.GetSize(), "String");
|
||||
|
||||
THEN("The result should be 'aDefaultString'")
|
||||
{
|
||||
REQUIRE(aDefaultString == "aDefaultString");
|
||||
REQUIRE(aDefaultString.GetSize() == 14);
|
||||
REQUIRE(aDefaultString.GetCapacity() >= 14);
|
||||
}
|
||||
|
||||
AND_WHEN("We test Contains and Find")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
CHECK(aDefaultString.Contains('D'));
|
||||
CHECK(aDefaultString.Contains("String", 3));
|
||||
CHECK(aDefaultString.Contains(Nz::String("sTRING"), 3, Nz::String::CaseInsensitive));
|
||||
REQUIRE(aDefaultString.FindLast('g') == aDefaultString.GetSize() - 1);
|
||||
CHECK(aDefaultString.EndsWith('G', Nz::String::CaseInsensitive));
|
||||
aDefaultString.Append(" ng bla");
|
||||
REQUIRE(aDefaultString.FindWord("ng") == aDefaultString.GetSize() - 6);
|
||||
//TODO REQUIRE(aDefaultString.FindWord(String("ng")) == aDefaultString.GetSize() - 6);
|
||||
CHECK(aDefaultString.StartsWith("aD"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We do operators")
|
||||
{
|
||||
aDefaultString[0] = 'a';
|
||||
aDefaultString += "Default";
|
||||
aDefaultString = aDefaultString + "String";
|
||||
|
||||
THEN("The result should be 'aDefaultString'")
|
||||
{
|
||||
REQUIRE(aDefaultString == "aDefaultString");
|
||||
REQUIRE(aDefaultString.GetSize() == 14);
|
||||
REQUIRE(aDefaultString.GetCapacity() >= 14);
|
||||
}
|
||||
|
||||
AND_WHEN("We test Count")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(aDefaultString.Count('D') == 1);
|
||||
REQUIRE(aDefaultString.Count("t", 2) == 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("The string of number 16 in base 16")
|
||||
{
|
||||
Nz::String number16;
|
||||
|
||||
CHECK(number16.IsEmpty());
|
||||
CHECK(number16.IsNull());
|
||||
|
||||
WHEN("We assign to number 16")
|
||||
{
|
||||
number16 = Nz::String::Number(16, 16);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
CHECK(number16.IsNumber(16));
|
||||
number16.Prepend("0x");
|
||||
REQUIRE(number16.GetSize() == 4);
|
||||
REQUIRE(number16.GetCapacity() >= 4);
|
||||
REQUIRE(number16.SubStringFrom('x', 1) == "10");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("One character string")
|
||||
{
|
||||
Nz::String characterString;
|
||||
|
||||
WHEN("We set the string to one character")
|
||||
{
|
||||
characterString.Set('/');
|
||||
|
||||
THEN("The string must contain it")
|
||||
{
|
||||
REQUIRE(characterString == '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO
|
||||
GIVEN("One unicode string")
|
||||
{
|
||||
String unicodeString = String::Unicode(U"àéçœÂ官話");
|
||||
|
||||
WHEN("We convert to other UTF")
|
||||
{
|
||||
REQUIRE(unicodeString.GetSize() == 7);
|
||||
REQUIRE(unicodeString.GetCapacity() >= 7);
|
||||
CHECK(unicodeString.Contains("官"));
|
||||
|
||||
THEN("The result should be the identity")
|
||||
{
|
||||
char* utf8 = unicodeString.GetUtf8Buffer();
|
||||
String utf8String = String::Unicode(utf8);
|
||||
char16_t* utf16 = unicodeString.GetUtf16Buffer();
|
||||
String utf16String = String::Unicode(utf16);
|
||||
char32_t* utf32 = unicodeString.GetUtf32Buffer();
|
||||
String utf32String = String::Unicode(utf32);
|
||||
|
||||
REQUIRE(utf8String == utf16String);
|
||||
REQUIRE(utf16String == utf32String);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
GIVEN("A string")
|
||||
{
|
||||
Nz::String replaceAny("abapeilomuky");
|
||||
Nz::String replaceAnyWithCase("abapEilOmuky");
|
||||
|
||||
WHEN("We replace any of vowels after character 3")
|
||||
{
|
||||
unsigned int nbrOfChanges = replaceAny.ReplaceAny("aeiouy", '$', 3);
|
||||
unsigned int nbrOfChangesWithCase = replaceAnyWithCase.ReplaceAny("AEIOUY", '$', 3);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(replaceAny == "abap$$l$m$k$");
|
||||
REQUIRE(nbrOfChanges == 5);
|
||||
REQUIRE(replaceAnyWithCase == "abap$il$muky");
|
||||
REQUIRE(nbrOfChangesWithCase == 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
107
tests/Engine/Core/StringExt.cpp
Normal file
107
tests/Engine/Core/StringExt.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("String", "[CORE][STRING]")
|
||||
{
|
||||
std::string unicodeString(u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98\u46E1");
|
||||
|
||||
WHEN("Converting string back and forth")
|
||||
{
|
||||
CHECK(Nz::FromUtf16String(Nz::ToUtf16String(unicodeString)) == unicodeString);
|
||||
CHECK(Nz::FromUtf32String(Nz::ToUtf32String(unicodeString)) == unicodeString);
|
||||
}
|
||||
|
||||
WHEN("Fetching words")
|
||||
{
|
||||
CHECK(Nz::GetWord({}, 0).empty());
|
||||
CHECK(Nz::GetWord(" ", 0).empty());
|
||||
|
||||
std::string sentence = u8"\nSay hello\tto Nazara\u00A0Engine\n\t! "; //< \u00A0 is a No-Break Space
|
||||
CHECK(Nz::GetWord(sentence, 0) == "Say");
|
||||
CHECK(Nz::GetWord(sentence, 1) == "hello");
|
||||
CHECK(Nz::GetWord(sentence, 2) == "to");
|
||||
CHECK(Nz::GetWord(sentence, 3) == u8"Nazara\u00A0Engine");
|
||||
CHECK(Nz::GetWord(sentence, 4) == "!");
|
||||
CHECK(Nz::GetWord(sentence, 5).empty());
|
||||
|
||||
// Try the same using Unicode aware overloads
|
||||
CHECK(Nz::GetWord(sentence, 0, Nz::UnicodeAware{}) == "Say");
|
||||
CHECK(Nz::GetWord(sentence, 1, Nz::UnicodeAware{}) == "hello");
|
||||
CHECK(Nz::GetWord(sentence, 2, Nz::UnicodeAware{}) == "to");
|
||||
CHECK(Nz::GetWord(sentence, 3, Nz::UnicodeAware{}) == "Nazara");
|
||||
CHECK(Nz::GetWord(sentence, 4, Nz::UnicodeAware{}) == "Engine");
|
||||
CHECK(Nz::GetWord(sentence, 5, Nz::UnicodeAware{}) == "!");
|
||||
CHECK(Nz::GetWord(sentence, 6, Nz::UnicodeAware{}).empty());
|
||||
}
|
||||
|
||||
WHEN("Checking if string is number")
|
||||
{
|
||||
CHECK(Nz::IsNumber("123456"));
|
||||
CHECK(Nz::IsNumber("-123456"));
|
||||
CHECK_FALSE(Nz::IsNumber("123 "));
|
||||
CHECK_FALSE(Nz::IsNumber("Nazara Engine"));
|
||||
CHECK_FALSE(Nz::IsNumber("12345Nazara Engine"));
|
||||
}
|
||||
|
||||
WHEN("Matching patterns")
|
||||
{
|
||||
CHECK(Nz::MatchPattern("Lynix", "?????"));
|
||||
CHECK(Nz::MatchPattern("Lynix", "*Lynix"));
|
||||
CHECK(Nz::MatchPattern("Lynox", "*Lyn?x"));
|
||||
CHECK_FALSE(Nz::MatchPattern("", "?"));
|
||||
CHECK_FALSE(Nz::MatchPattern("", "*"));
|
||||
|
||||
const char* pattern = "Naz?ra *gine";
|
||||
CHECK(Nz::MatchPattern("Nazara Engine", pattern));
|
||||
CHECK(Nz::MatchPattern("Nazora engine", pattern));
|
||||
CHECK(Nz::MatchPattern("Nazora Biggine", pattern));
|
||||
CHECK(Nz::MatchPattern("Nazora gine", pattern));
|
||||
|
||||
CHECK_FALSE(Nz::MatchPattern("Nazaragine", pattern));
|
||||
CHECK_FALSE(Nz::MatchPattern("Nazorra Engine", pattern));
|
||||
CHECK_FALSE(Nz::MatchPattern("Nazra Engine", pattern));
|
||||
CHECK_FALSE(Nz::MatchPattern("NazaraEngine", pattern));
|
||||
}
|
||||
|
||||
WHEN("Converting pointers to string")
|
||||
{
|
||||
CHECK(Nz::TrimRight(Nz::PointerToString(nullptr), '0') == "0x");
|
||||
|
||||
const void* ptr = reinterpret_cast<const void*>(static_cast<std::uintptr_t>(0xDEADBEEF));
|
||||
CHECK(Nz::MatchPattern(Nz::PointerToString(ptr), "0x*DEADBEEF"));
|
||||
}
|
||||
|
||||
WHEN("Replacing strings")
|
||||
{
|
||||
std::string str = "Nazara Engine";
|
||||
REQUIRE(Nz::ReplaceStr(str, "Nazara", "Unreal") == "Unreal Engine");
|
||||
REQUIRE(Nz::ReplaceStr(str, "Engine", "Reality") == "Unreal Reality");
|
||||
REQUIRE(Nz::ReplaceStr(str, "Unreal Reality", "Ungine") == "Ungine");
|
||||
}
|
||||
|
||||
WHEN("Checking if string starts with")
|
||||
{
|
||||
CHECK(Nz::StartsWith("Nazara Engine", "Nazara"));
|
||||
CHECK(Nz::StartsWith("NAZARA Engine", "NaZaRa", Nz::CaseIndependent{}));
|
||||
CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"l'\u00EEle", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
|
||||
}
|
||||
|
||||
WHEN("Converting between lower and upper")
|
||||
{
|
||||
CHECK(Nz::ToLower("Nazara Engine") == "nazara engine");
|
||||
CHECK(Nz::ToLower(u8"L'\u00CELE DE R\u00C9", Nz::UnicodeAware{}) == u8"l'\u00EEle de r\u00E9");
|
||||
CHECK(Nz::ToUpper("Nazara Engine") == "NAZARA ENGINE");
|
||||
CHECK(Nz::ToUpper(u8"l'\u00EEle de r\u00E9", Nz::UnicodeAware{}) == u8"L'\u00CELE DE R\u00C9");
|
||||
}
|
||||
|
||||
WHEN("Trimming strings")
|
||||
{
|
||||
CHECK(Nz::Trim(" \n Hello World\t") == "Hello World");
|
||||
CHECK(Nz::Trim("Nazara Engin", 'n') == "Nazara Engi");
|
||||
CHECK(Nz::Trim("Nazara Engin", 'n', Nz::CaseIndependent{}) == "azara Engi");
|
||||
CHECK(Nz::Trim(unicodeString, Nz::UnicodeAware{}) == unicodeString);
|
||||
CHECK(Nz::Trim("\n\t" + unicodeString + "\t ", Nz::UnicodeAware{}) == unicodeString);
|
||||
CHECK(Nz::Trim(unicodeString, U'\u46E1', Nz::UnicodeAware{}) == u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98");
|
||||
CHECK(Nz::Trim(unicodeString, Nz::Unicode::Category_Letter, Nz::UnicodeAware{}) == "");
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("StringStream", "[CORE][STRINGSTREAM]")
|
||||
{
|
||||
GIVEN("A string stream")
|
||||
{
|
||||
Nz::StringStream stringStream("default");
|
||||
|
||||
WHEN("We add bool and char")
|
||||
{
|
||||
stringStream << true;
|
||||
|
||||
char valueCharSigned = 64;
|
||||
stringStream << valueCharSigned;
|
||||
unsigned char valueCharUnsigned = 64;
|
||||
stringStream << valueCharUnsigned;
|
||||
|
||||
REQUIRE(stringStream.ToString() == "defaulttrue@@");
|
||||
}
|
||||
|
||||
AND_WHEN("We add short and int")
|
||||
{
|
||||
short valueShortSigned = -3;
|
||||
stringStream << valueShortSigned;
|
||||
unsigned short valueShortUnsigned = 3;
|
||||
stringStream << valueShortUnsigned;
|
||||
|
||||
int valueIntSigned = -3;
|
||||
stringStream << valueIntSigned;
|
||||
unsigned int valueIntUnsigned = 3;
|
||||
stringStream << valueIntUnsigned;
|
||||
|
||||
REQUIRE(stringStream.ToString() == "default-33-33");
|
||||
}
|
||||
|
||||
AND_WHEN("We add long and long long")
|
||||
{
|
||||
long valueLongSigned = -3;
|
||||
stringStream << valueLongSigned;
|
||||
unsigned long valueLongUnsigned = 3;
|
||||
stringStream << valueLongUnsigned;
|
||||
|
||||
long long valueLongLongSigned = -3;
|
||||
stringStream << valueLongLongSigned;
|
||||
unsigned long long valueLongLongUnsigned = 3;
|
||||
stringStream << valueLongLongUnsigned;
|
||||
|
||||
REQUIRE(stringStream.ToString() == "default-33-33");
|
||||
}
|
||||
|
||||
AND_WHEN("We add round floating points")
|
||||
{
|
||||
stringStream << 3.f;
|
||||
stringStream << 3.0;
|
||||
stringStream << 3.0L;
|
||||
|
||||
REQUIRE(stringStream.ToString() == "default3.0000003.0000003.000000");
|
||||
}
|
||||
|
||||
AND_WHEN("We add floating points")
|
||||
{
|
||||
stringStream << 3.5f << ' ';
|
||||
stringStream << 3.65 << ' ';
|
||||
stringStream << 3.6478L;
|
||||
|
||||
REQUIRE(stringStream.ToString() == "default3.500000 3.650000 3.647800");
|
||||
}
|
||||
|
||||
AND_WHEN("We add string and pointer")
|
||||
{
|
||||
stringStream << "3";
|
||||
stringStream << std::string("3");
|
||||
stringStream << Nz::String("3");
|
||||
stringStream << static_cast<void*>(nullptr);
|
||||
|
||||
REQUIRE(stringStream.ToString() == (Nz::String("default333") + Nz::String::Pointer(nullptr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user