Skip to content

Commit

Permalink
Merge pull request CosmosOS#1240 from quajak/feature/moreStringImpl
Browse files Browse the repository at this point in the history
Add string tests and split Bcl test kernel
  • Loading branch information
quajak authored Dec 26, 2019
2 parents c31fc3e + a3faa61 commit da440ff
Show file tree
Hide file tree
Showing 28 changed files with 181 additions and 45 deletions.
33 changes: 13 additions & 20 deletions Test.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
# Visual Studio Version 16
VisualStudioVersion = 16.0.28922.388
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DAEF99B5-22F0-4885-B45B-9B600B857E1C}"
EndProject
Expand Down Expand Up @@ -162,6 +162,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.System.Tests", "Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Kernel.Tests.DiskManager", "Tests\Kernels\Cosmos.Kernel.Tests.DiskManager\Cosmos.Kernel.Tests.DiskManager.csproj", "{BB6A5306-4C7A-4973-A48E-9FE3E683EAEC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos.Compiler.Tests.BclSystem", "Tests\Kernels\Cosmos.Compiler.Tests.Bcl.System\Cosmos.Compiler.Tests.BclSystem.csproj", "{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -170,14 +172,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Debug|x86.ActiveCfg = Debug|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Debug|x86.Build.0 = Debug|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Release|Any CPU.Build.0 = Release|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Release|x86.ActiveCfg = Release|Any CPU
{0CDB3F6E-7971-426B-81F8-38B966A54C2B}.Release|x86.Build.0 = Release|Any CPU
{F74A4B2B-02DA-455A-89FB-803A442B5B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F74A4B2B-02DA-455A-89FB-803A442B5B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F74A4B2B-02DA-455A-89FB-803A442B5B2C}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -539,14 +533,6 @@ Global
{FF46829E-B612-4D36-80BE-ED04521AD91A}.Release|Any CPU.Build.0 = Release|Any CPU
{FF46829E-B612-4D36-80BE-ED04521AD91A}.Release|x86.ActiveCfg = Release|Any CPU
{FF46829E-B612-4D36-80BE-ED04521AD91A}.Release|x86.Build.0 = Release|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Debug|x86.ActiveCfg = Debug|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Debug|x86.Build.0 = Debug|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Release|Any CPU.Build.0 = Release|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Release|x86.ActiveCfg = Release|Any CPU
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67}.Release|x86.Build.0 = Release|Any CPU
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -635,12 +621,19 @@ Global
{BB6A5306-4C7A-4973-A48E-9FE3E683EAEC}.Release|Any CPU.Build.0 = Release|Any CPU
{BB6A5306-4C7A-4973-A48E-9FE3E683EAEC}.Release|x86.ActiveCfg = Release|Any CPU
{BB6A5306-4C7A-4973-A48E-9FE3E683EAEC}.Release|x86.Build.0 = Release|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Debug|x86.ActiveCfg = Debug|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Debug|x86.Build.0 = Debug|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Release|Any CPU.Build.0 = Release|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Release|x86.ActiveCfg = Release|Any CPU
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0CDB3F6E-7971-426B-81F8-38B966A54C2B} = {E9CD521E-C386-466D-B5F7-A5EB19A61625}
{F74A4B2B-02DA-455A-89FB-803A442B5B2C} = {DAEF99B5-22F0-4885-B45B-9B600B857E1C}
{4F903492-CCA6-4FD9-A1B6-5E4CC0CE7767} = {C286932C-3F6D-47F0-BEEF-26843D1BB11B}
{34AEEB7C-FD5D-4B15-A830-B429681844BD} = {C286932C-3F6D-47F0-BEEF-26843D1BB11B}
Expand Down Expand Up @@ -702,7 +695,6 @@ Global
{3DD192AF-2D72-449F-936C-ED8734225B18} = {C286932C-3F6D-47F0-BEEF-26843D1BB11B}
{929EE8ED-6AD3-4442-A0C1-EC70665F2DCF} = {99192440-2DD7-4E71-B730-D44A73F46533}
{FF46829E-B612-4D36-80BE-ED04521AD91A} = {E9CD521E-C386-466D-B5F7-A5EB19A61625}
{D0EABA08-88C9-4F7C-BCA9-361B58B20D67} = {E9CD521E-C386-466D-B5F7-A5EB19A61625}
{D21A7C6C-A696-4EC3-84EB-70700C1E3B34} = {ECEA7778-E786-4317-90B9-A2D4427CB91C}
{0DF97CAC-220B-4DAD-B397-42E394255763} = {ECEA7778-E786-4317-90B9-A2D4427CB91C}
{2992AA07-E126-4EE0-B31C-D0B2ADE3393A} = {0E67EFE8-5944-4F6C-8B47-C5E06D4C79F5}
Expand All @@ -714,6 +706,7 @@ Global
{99E24E61-0743-47FF-AB0A-55A36C5E184C} = {52D81759-C7CC-427F-8C96-89CA10C914B5}
{970C5E07-5D09-4882-949C-A8E876B22732} = {52D81759-C7CC-427F-8C96-89CA10C914B5}
{BB6A5306-4C7A-4973-A48E-9FE3E683EAEC} = {29EEC029-6A2B-478A-B6E5-D63A91388ABA}
{30D9FA9C-0B4D-40FF-8903-6B9E9C825729} = {ECEA7778-E786-4317-90B9-A2D4427CB91C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4418C803-277E-448F-A0A0-52788FA215AD}
Expand Down
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Full/Cosmos.TestRunner.Full.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ProjectReference Include="..\Kernels\BoxingTests\BoxingTests.csproj" />
<ProjectReference Include="..\Kernels\ConsoleTest\ConsoleTest.csproj" />
<ProjectReference Include="..\Kernels\Cosmos.Compiler.Tests.Bcl\Cosmos.Compiler.Tests.Bcl.csproj" />
<ProjectReference Include="..\Kernels\Cosmos.Compiler.Tests.Bcl.System\Cosmos.Compiler.Tests.BclSystem.csproj" />
<ProjectReference Include="..\Kernels\Cosmos.Compiler.Tests.Encryption\Cosmos.Compiler.Tests.Encryption.csproj" />
<ProjectReference Include="..\Kernels\Cosmos.Compiler.Tests.Exceptions\Cosmos.Compiler.Tests.Exceptions.csproj" />
<ProjectReference Include="..\Kernels\Cosmos.Compiler.Tests.Interfaces\Cosmos.Compiler.Tests.Interfaces.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Full/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static IEnumerable<Type> GetStableKernelTypes()
yield return typeof(BoxingTests.Kernel);
yield return typeof(Cosmos.Compiler.Tests.TypeSystem.Kernel);
yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
yield return typeof(Cosmos.Compiler.Tests.Bcl.System.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoWarn>CA2242;$(NoWarn)</NoWarn>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\source\Cosmos.Debug.Kernel\Cosmos.Debug.Kernel.csproj" />
<ProjectReference Include="..\..\..\source\Cosmos.System2\Cosmos.System2.csproj" />
<ProjectReference Include="..\..\Cosmos.TestRunner.TestController\Cosmos.TestRunner.TestController.csproj" />
<ProjectReference Include="..\Cosmos.Compiler.Tests.Bcl\Cosmos.Compiler.Tests.Bcl.csproj" />
</ItemGroup>


</Project>
59 changes: 59 additions & 0 deletions Tests/Kernels/Cosmos.Compiler.Tests.Bcl.System/Kernel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections;

using Cosmos.TestRunner;
using Sys = Cosmos.System;

using Cosmos.Compiler.Tests.Bcl.CSharp;

namespace Cosmos.Compiler.Tests.Bcl.System
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Starting BCL System tests now please wait...");
}

protected override void Run()
{
try
{
mDebugger.Send("Run");


// System
ObjectTests.Execute();
ArrayTests.Execute();
StringTest.Execute();
ByteTest.Execute();
SByteTest.Execute();
Int16Test.Execute();
UInt16Test.Execute();
Int32Test.Execute();
UInt32Test.Execute();
Int64Test.Execute();
UInt64Test.Execute();
CharTest.Execute();
BooleanTest.Execute();
SingleTest.Execute();
DoubleTest.Execute();
MathTest.Execute();
ConvertTests.Execute();
DateTimeTests.Execute();
TimeSpanTests.Execute();


TestController.Completed();
}
catch (Exception e)
{
mDebugger.Send("Exception occurred: " + e.Message);
mDebugger.Send(e.Message);
Console.WriteLine("Exception occurred");
Console.WriteLine(e.Message);
TestController.Failed();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,50 @@ public static void Execute()
Assert.IsTrue(test.EndsWith("string."), "string.EndsWith(string) is not reporting false even though the string actually does end with the substring.");
Assert.IsFalse(test.EndsWith("sentence."), "string.EndsWith(string) is not reporting true even though the string actually doesn't end with the substring.");

Assert.IsTrue(test.IndexOf(string.Empty, 10) == 10, "string.IndexOf currectly returns for empty string with start index");
Assert.IsTrue(test.IndexOf(string.Empty, 10, 10) == 10, "string.IndexOf currectly returns for empty string with start index and count");
Assert.IsTrue(test.IndexOf('T') == 0, "string.IndexOf finds the only occurance of a letter");
Assert.IsTrue(test.IndexOf('A') == -1, "string.IndexOf correctly returns when it does not find something");
Assert.IsTrue(test.IndexOf("ABCDE") == -1, "string.IndexOf correctly returns when it does not find something");
Assert.IsTrue(test.IndexOf('.') == test.Length - 1, "string.IndexOf finds the only occurance of a letter at the end of the string");
Assert.IsTrue(test.IndexOf('i') == 2, "string.IndexOf finds the first of multiple occurances of a letter");
Assert.IsTrue(test.IndexOf('i', 8) == 18, "string.IndexOf with start point finds the first of multiple occurances of a letter");
Assert.IsTrue(test.IndexOf("is") == 2, "string.IndexOf finds the first of multiple occurances of a string");
Assert.IsTrue(test.IndexOf("is", 3) == 5, "string.IndexOf with start point finds the first of multiple occurances of a string");
Assert.IsTrue(test.IndexOf("is", 3, 5) == 5, "string.IndexOf with start point and count finds the first of multiple occurances of a string");
Assert.IsTrue(test.IndexOf("is", 3, 1) == -1, "string.IndexOf with start point and count correctly returns if it does not find something");

Assert.IsTrue(test.IndexOfAny(new[] { 'T', 'h', 'i', 's' }) == 0, "string.IndexOfAny finds the first one");
Assert.IsTrue(test.IndexOfAny(new[] { 'A', 'B', 'C' }) == -1, "string.IndexOfAny finds none if none are present");

Assert.IsTrue(test.LastIndexOf(string.Empty, 100) == test.Length, "string.LastIndexOf handles empty correctly");
Assert.IsTrue(test.LastIndexOf('T') == 0, "string.LastIndexOf finds the only occurance of a letter");
Assert.IsTrue(test.LastIndexOf('.') == test.Length - 1, "string.LastIndexOf finds the only occurance of a letter at the end of the string");
Assert.IsTrue(test.LastIndexOf('i') == test.Length - 4, "string.IndexOf finds the last of multiple occurances of a letter");

Assert.IsTrue(test.LastIndexOfAny(new[] { 'T', 'h', 'i', 's' }) == 18, "string.LastIndexOfAny finds the first one");
Assert.IsTrue(test.LastIndexOfAny(new[] { 'A', 'B', 'C' }) == -1, "string.LastIndexOfAny finds none if none are present");


Assert.IsTrue(test.Insert(0, "A") != test, "string.Insert creates a new instance");
Assert.IsTrue(test.Insert(1, "A") == "TAhis is a test string.", "string.Insert correctly inserts a single character");
Assert.IsTrue(test.Insert(2, "ABCDE F") == "ThABCDE Fis is a test string.", "string.Insert correctly adds multiple characters");
Assert.IsTrue(test.Insert(test.Length, "END") == "This is a test string.END", "string.Insert correctly inserts at the end of the string");

Assert.IsTrue(test.Remove(1) == "T", "string.Remove correctly removes all other characters");
Assert.IsTrue(test.Remove(0) == "", "string.Remove correctly removes all characters");
Assert.IsTrue(test.Remove(0, 2) == "is is a test string.", "string.Remove works with count");

Assert.IsTrue(" a ".Trim() == "a", "string.Trim trims both front and back");
Assert.IsTrue("abababababa".Trim(new[] { 'a', 'b' }) == "", "string.Trim works with custom chars");
Assert.IsTrue("abCababababa".Trim(new[] { 'a', 'b' }) == "C", "string.Trim works with custom chars");
Assert.IsTrue("a".Trim() == "a", "string.Trim trims both front and back");
Assert.IsTrue(" a ".TrimStart() == "a ", "string.TrimStart trims front");
Assert.IsTrue("a".TrimStart() == "a", "string.Trim trims front");
Assert.IsTrue(" a ".TrimEnd() == " a", "string.TrimEnd trims back");
Assert.IsTrue("a".TrimEnd() == "a", "string.TrimEnd trims back");


string lower_expected = "this is a test string.";
string upper_expected = "THIS IS A TEST STRING.";
Assert.IsTrue((test.ToLower() == lower_expected), "string.ToLower() does not work.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cosmos.Compiler.Tests.Bcl
{
internal static class EqualityHelper
public static class EqualityHelper
{
public static bool SinglesAreEqual(float left, float right)
{
Expand Down
21 changes: 0 additions & 21 deletions Tests/Kernels/Cosmos.Compiler.Tests.Bcl/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ protected override void Run()
WhileLoopTests.Execute();
ForeachLoopTests.Execute();

// System
ObjectTests.Execute();
ArrayTests.Execute();
StringTest.Execute();
ByteTest.Execute();
SByteTest.Execute();
Int16Test.Execute();
UInt16Test.Execute();
Int32Test.Execute();
UInt32Test.Execute();
Int64Test.Execute();
UInt64Test.Execute();
CharTest.Execute();
BooleanTest.Execute();
SingleTest.Execute();
DoubleTest.Execute();
MathTest.Execute();
ConvertTests.Execute();
DateTimeTests.Execute();
TimeSpanTests.Execute();

//mDebugger.Send("Thread test start of 500 ms");
//ThreadTest.Execute();
//mDebugger.Send("Thread test end");
Expand Down
47 changes: 44 additions & 3 deletions source/Cosmos.Core_Plugs/System/StringImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,19 @@ private static int boyerMooreHorsepool(string pattern, string text)

public static int IndexOf(string aThis, string aSubstring, int aIdx, int aLength, StringComparison aComparison)
{
return boyerMooreHorsepool(aSubstring, aThis.Substring(aIdx, aLength));
if (aSubstring == String.Empty)
{
return aIdx;
}
int pos = boyerMooreHorsepool(aSubstring, aThis.Substring(aIdx, aLength));
if (pos == -1)
{
return pos;
}
else
{
return pos + aIdx; //To account for offset
}
}

public static bool Contains(string aThis, string value)
Expand Down Expand Up @@ -624,9 +636,38 @@ public static string Insert(string aThis, int aStartPos, string aValue)
return aThis.Substring(0, aStartPos) + aValue + aThis.Substring(aStartPos);
}

public static int LastIndexOf(string aThis, string aString, int aIndex)
{
return LastIndexOf(aThis, aString, aIndex, aThis.Length - aIndex);
}

public static int LastIndexOf(string aThis, string aString, int aIndex, int aCount)
{
if (aString == String.Empty)
{
if (aIndex > aThis.Length)
{
return aThis.Length;
}
return aIndex;
}

string curr = "";
char[] chars = aThis.ToCharArray();
for (int i = 0; i < aCount; i++)
{
curr = chars[aThis.Length - i - 1] + curr;
if (curr.StartsWith(aString))
{
return aThis.Length - i - 1;
}
}
return -1;
}

public static int LastIndexOf(string aThis, char aChar, int aStartIndex, int aCount)
{
return LastIndexOfAny(aThis, new[] { aChar }, aStartIndex, aCount);
return LastIndexOf(aThis, new string(aChar, 1), aStartIndex, aCount);
}

public static int LastIndexOfAny(string aThis, char[] aChars, int aStartIndex, int aCount)
Expand Down Expand Up @@ -976,7 +1017,7 @@ public static unsafe int CompareOrdinalHelper(string strA, int indexA, int count

/*
* This optimization is not taking effect yet in Cosmos as String.Intern() is not implemented
*/
*/
if (ReferenceEquals(strA, strB))
{
mDebugger.SendInternal($"strA ({strA}) is the same object of strB ({strB}) returning 0");
Expand Down

0 comments on commit da440ff

Please sign in to comment.