Skip to content

Commit 9cb2612

Browse files
committed
More string tests
1 parent 9ea5813 commit 9cb2612

File tree

1 file changed

+286
-0
lines changed

1 file changed

+286
-0
lines changed

tests/yup_core/yup_String.cpp

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,3 +1081,289 @@ TEST_F (StringTests, EdgeCasesAndBoundaryConditions)
10811081
EXPECT_GT (large_num.length(), 0);
10821082
EXPECT_EQ (large_num.getLargeIntValue(), std::numeric_limits<long long>::max());
10831083
}
1084+
1085+
TEST_F (StringTests, CharPointerUTF16ConstructorWithMaxChars)
1086+
{
1087+
String original ("Hello World Test String");
1088+
CharPointer_UTF16 ptr (original.toUTF16());
1089+
1090+
String s (ptr, 5);
1091+
EXPECT_EQ (s, "Hello");
1092+
}
1093+
1094+
TEST_F (StringTests, CharPointerUTF32ConstructorWithMaxChars)
1095+
{
1096+
String original ("Hello World Test String");
1097+
CharPointer_UTF32 ptr (original.toUTF32());
1098+
1099+
String s (ptr, 5);
1100+
EXPECT_EQ (s, "Hello");
1101+
}
1102+
1103+
TEST_F (StringTests, CharPointerUTF16ConstructorWithRange)
1104+
{
1105+
String original ("Hello World");
1106+
CharPointer_UTF16 start (original.toUTF16());
1107+
CharPointer_UTF16 end = start + 5;
1108+
1109+
String s (start, end);
1110+
EXPECT_EQ (s, "Hello");
1111+
}
1112+
1113+
TEST_F (StringTests, CharPointerUTF32ConstructorWithRange)
1114+
{
1115+
String original ("Hello World");
1116+
CharPointer_UTF32 start (original.toUTF32());
1117+
CharPointer_UTF32 end = start + 5;
1118+
1119+
String s (start, end);
1120+
EXPECT_EQ (s, "Hello");
1121+
}
1122+
1123+
TEST_F (StringTests, UnsignedShortConstructor)
1124+
{
1125+
unsigned short num = 12345;
1126+
String s (num);
1127+
EXPECT_EQ (s, "12345");
1128+
EXPECT_EQ (s.getIntValue(), 12345);
1129+
}
1130+
1131+
TEST_F (StringTests, FloatConstructorWithDecimalPlaces)
1132+
{
1133+
String s1 (3.14159f, 2, false);
1134+
EXPECT_TRUE (s1.startsWith ("3.14"));
1135+
1136+
String s2 (1234.5678f, 3, false);
1137+
EXPECT_TRUE (s2.contains ("1234"));
1138+
EXPECT_TRUE (s2.contains ("."));
1139+
}
1140+
1141+
TEST_F (StringTests, FloatConstructorWithScientificNotation)
1142+
{
1143+
String s (0.00012345f, 2, true);
1144+
EXPECT_TRUE (s.containsIgnoreCase ("e"));
1145+
}
1146+
1147+
TEST_F (StringTests, ComparisonWithWideCharPointer)
1148+
{
1149+
String s1 (L"test");
1150+
const wchar_t* s2 = L"test";
1151+
const wchar_t* s3 = L"different";
1152+
1153+
EXPECT_TRUE (s1 == s2);
1154+
EXPECT_FALSE (s1 == s3);
1155+
EXPECT_FALSE (s1 != s2);
1156+
EXPECT_TRUE (s1 != s3);
1157+
}
1158+
1159+
TEST_F (StringTests, ComparisonWithCharPointerUTF8)
1160+
{
1161+
String s1 ("hello");
1162+
CharPointer_UTF8 s2 ("hello");
1163+
CharPointer_UTF8 s3 ("world");
1164+
1165+
EXPECT_TRUE (s1 == s2);
1166+
EXPECT_FALSE (s1 == s3);
1167+
EXPECT_FALSE (s1 != s2);
1168+
EXPECT_TRUE (s1 != s3);
1169+
}
1170+
1171+
TEST_F (StringTests, ComparisonWithCharPointerUTF16)
1172+
{
1173+
String s1 ("hello");
1174+
String s2Str ("hello");
1175+
String s3Str ("world");
1176+
CharPointer_UTF16 s2 (s2Str.toUTF16());
1177+
CharPointer_UTF16 s3 (s3Str.toUTF16());
1178+
1179+
EXPECT_TRUE (s1 == s2);
1180+
EXPECT_FALSE (s1 == s3);
1181+
EXPECT_FALSE (s1 != s2);
1182+
EXPECT_TRUE (s1 != s3);
1183+
}
1184+
1185+
TEST_F (StringTests, ComparisonWithCharPointerUTF32)
1186+
{
1187+
String s1 ("hello");
1188+
String s2Str ("hello");
1189+
String s3Str ("world");
1190+
CharPointer_UTF32 s2 (s2Str.toUTF32());
1191+
CharPointer_UTF32 s3 (s3Str.toUTF32());
1192+
1193+
EXPECT_TRUE (s1 == s2);
1194+
EXPECT_FALSE (s1 == s3);
1195+
EXPECT_FALSE (s1 != s2);
1196+
EXPECT_TRUE (s1 != s3);
1197+
}
1198+
1199+
TEST_F (StringTests, EqualsIgnoreCaseWithWideChar)
1200+
{
1201+
String s1 (L"Hello");
1202+
const wchar_t* s2 = L"HELLO";
1203+
const wchar_t* s3 = L"world";
1204+
1205+
EXPECT_TRUE (s1.equalsIgnoreCase (s2));
1206+
EXPECT_FALSE (s1.equalsIgnoreCase (s3));
1207+
}
1208+
1209+
TEST_F (StringTests, AppendLongNumber)
1210+
{
1211+
String s ("Value: ");
1212+
long num = 123456789L;
1213+
s += num;
1214+
1215+
EXPECT_TRUE (s.contains ("123456789"));
1216+
}
1217+
1218+
TEST_F (StringTests, AppendUInt64Number)
1219+
{
1220+
String s ("Value: ");
1221+
uint64 num = 9876543210ULL;
1222+
s += num;
1223+
1224+
EXPECT_TRUE (s.contains ("9876543210"));
1225+
}
1226+
1227+
TEST_F (StringTests, AddWideCharPointerToString)
1228+
{
1229+
const wchar_t* s1 = L"Hello ";
1230+
String s2 ("World");
1231+
String result = s1 + s2;
1232+
1233+
EXPECT_EQ (result, "Hello World");
1234+
}
1235+
1236+
TEST_F (StringTests, AddCharToString)
1237+
{
1238+
char c = 'X';
1239+
String s ("Test");
1240+
String result = c + s;
1241+
1242+
EXPECT_TRUE (result.startsWith ("X"));
1243+
EXPECT_TRUE (result.endsWith ("Test"));
1244+
}
1245+
1246+
TEST_F (StringTests, AddWideCharToString)
1247+
{
1248+
wchar_t c = L'Y';
1249+
String s ("Test");
1250+
String result = c + s;
1251+
1252+
EXPECT_TRUE (result.startsWith ("Y"));
1253+
EXPECT_TRUE (result.endsWith ("Test"));
1254+
}
1255+
1256+
TEST_F (StringTests, AddStdStringToString)
1257+
{
1258+
String s1 ("Hello ");
1259+
std::string s2 = "World";
1260+
String result = s1 + s2;
1261+
1262+
EXPECT_EQ (result, "Hello World");
1263+
}
1264+
1265+
TEST_F (StringTests, StreamWideCharToString)
1266+
{
1267+
String s;
1268+
wchar_t c = L'A';
1269+
s << c;
1270+
1271+
EXPECT_EQ (s, "A");
1272+
}
1273+
1274+
TEST_F (StringTests, StreamLongToString)
1275+
{
1276+
String s ("Value: ");
1277+
long num = 42L;
1278+
s << num;
1279+
1280+
EXPECT_TRUE (s.endsWith ("42"));
1281+
}
1282+
1283+
TEST_F (StringTests, StreamDoubleToString)
1284+
{
1285+
String s ("Pi: ");
1286+
double num = 3.14;
1287+
s << num;
1288+
1289+
EXPECT_TRUE (s.contains ("3.14"));
1290+
}
1291+
1292+
TEST_F (StringTests, QuotedWithEmptyString)
1293+
{
1294+
String s;
1295+
String quoted = s.quoted ('"');
1296+
1297+
EXPECT_EQ (quoted, "\"\"");
1298+
}
1299+
1300+
TEST_F (StringTests, RetainCharactersEmpty)
1301+
{
1302+
String s;
1303+
String result = s.retainCharacters ("abc");
1304+
1305+
EXPECT_TRUE (result.isEmpty());
1306+
}
1307+
1308+
TEST_F (StringTests, RemoveCharactersEmpty)
1309+
{
1310+
String s;
1311+
String result = s.removeCharacters ("abc");
1312+
1313+
EXPECT_TRUE (result.isEmpty());
1314+
}
1315+
1316+
TEST_F (StringTests, ContainsAnyOfReturnsFalse)
1317+
{
1318+
String s ("hello");
1319+
EXPECT_FALSE (s.containsAnyOf ("xyz"));
1320+
}
1321+
1322+
TEST_F (StringTests, FormattedRawBasic)
1323+
{
1324+
String result = String::formatted ("Test %d %s", 42, "hello");
1325+
1326+
EXPECT_TRUE (result.contains ("42"));
1327+
EXPECT_TRUE (result.contains ("hello"));
1328+
}
1329+
1330+
TEST_F (StringTests, ToHexStringWithZeroSize)
1331+
{
1332+
const char data[] = "test";
1333+
String hex = String::toHexString (data, 0, 0);
1334+
1335+
EXPECT_TRUE (hex.isEmpty());
1336+
}
1337+
1338+
TEST_F (StringTests, ToHexStringWithNegativeSize)
1339+
{
1340+
const char data[] = "test";
1341+
String hex = String::toHexString (data, -5, 0);
1342+
1343+
EXPECT_TRUE (hex.isEmpty());
1344+
}
1345+
1346+
TEST_F (StringTests, IndentLinesEmpty)
1347+
{
1348+
String s;
1349+
String indented = s.indentLines (" ", false);
1350+
1351+
EXPECT_TRUE (indented.isEmpty());
1352+
}
1353+
1354+
TEST_F (StringTests, DedentLinesEmpty)
1355+
{
1356+
String s;
1357+
String dedented = s.dedentLines();
1358+
1359+
EXPECT_TRUE (dedented.isEmpty());
1360+
}
1361+
1362+
TEST_F (StringTests, CompareNaturalWithLeadingZeros)
1363+
{
1364+
String s1 ("file001");
1365+
String s2 ("file002");
1366+
1367+
EXPECT_LT (s1.compareNatural (s2, true), 0);
1368+
EXPECT_GT (s2.compareNatural (s1, true), 0);
1369+
}

0 commit comments

Comments
 (0)