Skip to content

Commit

Permalink
ags3: add a few utf-8 string tests
Browse files Browse the repository at this point in the history
adds tests for AppendChar, CompareTo, EndsWith, IndexOf, LowerCase, Replace and ReplaceCharAt
  • Loading branch information
ericoporto committed Aug 16, 2024
1 parent 42902ec commit 7a9d490
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions ags3/auto-test/test-string.asc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test String Module Script
int GetTestStringCount()
{
return 23;
return 31;
}

void TestString()
Expand All @@ -12,6 +12,11 @@ void TestString()
String mytext = "Hello";
mytext = mytext.Append("World");
tap.is(mytext, "HelloWorld", "String.Append test");

// UTF-8 specific test
String utfText = "Hell";
utfText = utfText.AppendChar('ä'); // Append a UTF-8 character
tap.is(utfText, "Hellä", "String.AppendChar UTF-8 test");
}

// String.AppendChar
Expand All @@ -26,6 +31,11 @@ void TestString()
String mytext = "Hello";
tap.ok(mytext.CompareTo("hello",eCaseInsensitive) == 0, "String.CompareTo sensitivity off");
tap.ok(mytext.CompareTo("hello",eCaseSensitive) != 0, "String.CompareTo sensitivity on");

// UTF-8 specific test
String utfText = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪÜ";
tap.ok(utfText.CompareTo("àáâãäåçèéêëìíîïðñòóôõöøùúûüýþāăąćĉċčďđēĕėęěĝğġģĥħĩīü", eCaseInsensitive) == 0, "String.CompareTo UTF-8 sensitivity off");
tap.ok(utfText.CompareTo("àáâãäåçèéêëìíîïðñòóôõöøùúûüýþāăąćĉċčďđēĕėęěĝğġģĥħĩīü", eCaseSensitive) != 0, "String.CompareTo UTF-8 sensitivity on");
}

// String.Copy
Expand All @@ -39,6 +49,10 @@ void TestString()
{
String myString = "Hello from the script!";
tap.ok(myString.EndsWith("script!"), "String.EndsWith test");

// UTF-8 specific test
String utfString = "Grüße von MÜNCHEN!";
tap.ok(utfString.EndsWith("münchen!", eCaseInsensitive), "String.EndsWith UTF-8 test");
}

// String.Format
Expand All @@ -55,6 +69,11 @@ void TestString()
String haystack = "The haystack had a needle in it somewhere.";
int result = haystack.IndexOf("a needle");
tap.is_int(result, 17, "String.IndexOf test");

// UTF-8 specific test
String utfHaystack = "The haystack had a ĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨ and a needle in it somewhere..";
int utfResult = utfHaystack.IndexOf("a needle");
tap.is_int(utfResult, 43, "String.IndexOf UTF-8 test");
}

// String.IsNullOrEmpty
Expand All @@ -72,20 +91,35 @@ void TestString()
String mystring = "THIS is a test string";
String lowercased = mystring.LowerCase();
tap.is(lowercased, "this is a test string", "String.LowerCase test");

// UTF-8 specific test
String utfString = "FUßGÄNGERÜBERGÄNGE";
String utfLowercased = utfString.LowerCase();
tap.is(utfLowercased, "fußgängerübergänge", "String.LowerCase UTF-8 test");
}

// String.Replace
{
String original = "Hello from the script!";
String changed = original.Replace("hello", "goodbye");
tap.is(changed, "goodbye from the script!", "String.Replace test");

// UTF-8 specific test
String utfOriginal = "Grüße vom München!";
String utfChanged = utfOriginal.Replace("München", "Berlin");
tap.is(utfChanged, "Grüße vom Berlin!", "String.Replace UTF-8 test");
}

// String.ReplaceCharAt
{
String mystring = "Hello";
String changed = mystring.ReplaceCharAt(2, 'm');
tap.is(changed, "Hemlo", "String.ReplaceCharAt test");
tap.is(changed, "Hemlo", "String.ReplaceCharAt test");

// UTF-8 specific test
String utfString = "ĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨ";
String utfChanged = utfString.ReplaceCharAt(3, 's'); // Replacing 'Ċ' with 's'
tap.is(utfChanged, "ĄĆĈsČĎĐĒĔĖĘĚĜĞĠĢĤĦĨ", "String.ReplaceCharAt UTF-8 test");
}

// String.StartsWith
Expand Down

0 comments on commit 7a9d490

Please sign in to comment.