Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SinoAHpx committed Oct 8, 2024
1 parent 7481e35 commit 63e6aa6
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Technetium.Runner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace Technetium.Runner;
using Technetium.Text.String;

namespace Technetium.Runner;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
List<int> i = [1, 2, 3, 4];
i.Output();
}

}

public static class Utils
{
public static void Output<T>(this IEnumerable<T> list)
{
Console.WriteLine($"[{list
.Select(x => x.ToString())
.Aggregate((c, n) => $"{c}, {n}")}]");
}
}
4 changes: 4 additions & 0 deletions Technetium.Test/Technetium.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@
<Using Include="NUnit.Framework" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Technetium\Technetium.csproj" />
</ItemGroup>

</Project>
151 changes: 151 additions & 0 deletions Technetium.Test/Text/String/FluentStringTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,159 @@
using System;
using Technetium.Text.String;

namespace Technetium.Test.Text.String;

public class FluentStringTest
{

[Test]
public void TestNullOrEmpty()
{
string? str = null;
Assert.IsTrue(str.IsNullOrEmpty());

str = "";
Assert.IsTrue(str.IsNullOrEmpty());

str = "Hello, World!";
Assert.IsFalse(str.IsNullOrEmpty());
}

[Test]
public void TestIsInt32()
{
Assert.IsTrue("123".IsInt32());
Assert.IsFalse("123.45".IsInt32());
Assert.IsFalse("abc".IsInt32());
Assert.IsFalse("".IsInt32());
Assert.IsFalse(((string?)null).IsInt32());
}

[Test]
public void TestIsInt64()
{
Assert.IsTrue("9223372036854775807".IsInt64());
Assert.IsFalse("9223372036854775808".IsInt64());
Assert.IsFalse("abc".IsInt64());
Assert.IsFalse("".IsInt64());
Assert.IsFalse(((string?)null).IsInt64());
}

[Test]
public void TestIsDouble()
{
Assert.IsTrue("123.45".IsDouble());
Assert.IsTrue("123".IsDouble());
Assert.IsFalse("abc".IsDouble());
Assert.IsFalse("".IsDouble());
Assert.IsFalse(((string?)null).IsDouble());
}

[Test]
public void TestIsFloat()
{
Assert.IsTrue("123.45".IsFloat());
Assert.IsTrue("123".IsFloat());
Assert.IsFalse("abc".IsFloat());
Assert.IsFalse("".IsFloat());
Assert.IsFalse(((string?)null).IsFloat());
}

[Test]
public void TestIsDecimal()
{
Assert.IsTrue("123.45".IsDecimal());
Assert.IsTrue("123".IsDecimal());
Assert.IsFalse("abc".IsDecimal());
Assert.IsFalse("".IsDecimal());
Assert.IsFalse(((string?)null).IsDecimal());
}

[Test]
public void TestToInt32()
{
Assert.That("123".ToInt32(), Is.EqualTo(123));
Assert.Throws<FormatException>(() => "abc".ToInt32());
}

[Test]
public void TestToInt64()
{
Assert.That("9223372036854775807".ToInt64(), Is.EqualTo(9223372036854775807));
Assert.Throws<FormatException>(() => "abc".ToInt64());
}

[Test]
public void TestToBool()
{
Assert.IsTrue("true".ToBool());
Assert.IsFalse("false".ToBool());
Assert.Throws<FormatException>(() => "abc".ToBool());
}

[Test]
public void TestRemoveInvalidPathChars()
{
Assert.That("Hello<>:\"/\\|?*World".RemoveInvalidPathChars(), Is.EqualTo("HelloWorld"));
}

[Test]
public void TestRemoveInvalidFileNameChars()
{
Assert.That("Hello<>:\"/\\|?*World".RemoveInvalidFileNameChars(), Is.EqualTo("HelloWorld"));
}

[Test]
public void TestCombinePath()
{
Assert.That("path".CombinePath("to", "file"), Is.EqualTo(Path.Combine("path", "to", "file")));
}

[Test]
public void TestJoinToString()
{
var list = new List<int> { 1, 2, 3 };
Assert.That(list.JoinToString(","), Is.EqualTo("1,2,3"));
}

[Test]
public void TestJoinToStringWithSelector()
{
var list = new List<int> { 1, 2, 3 };
Assert.That(list.JoinToString(",", x => (x * 2).ToString()), Is.EqualTo("2,4,6"));
}

[Test]
public void TestEmpty()
{
Assert.That("Hello World".Empty(" "), Is.EqualTo("HelloWorld"));
}

[Test]
public void TestSubstringBetween()
{
Assert.That("Hello World!".SubstringBetween("Hello ", "!"), Is.EqualTo("World"));
Assert.Throws<ArgumentException>(() => "Hello World".SubstringBetween("Foo", "Bar"));
}

[Test]
public void TestSubstringAfter()
{
Assert.That("Hello World!".SubstringAfter("Hello "), Is.EqualTo("World!"));
Assert.Throws<ArgumentException>(() => "Hello World".SubstringAfter("Foo"));
}

[Test]
public void TestInsertAfter()
{
Assert.That("Hello World!".InsertAfter("Hello", ","), Is.EqualTo("Hello, World!"));
Assert.That("Hello World!".InsertAfter("o", ",", true), Is.EqualTo("Hello, World,!"));
}

[Test]
public void TestInsertBefore()
{
Assert.That("Hello World!".InsertBefore("World", ", "), Is.EqualTo("Hello, World!"));
Assert.That("Hello World!".InsertBefore("o", ",", true), Is.EqualTo("Hello, Wo,rld!"));
}
}
6 changes: 6 additions & 0 deletions Technetium.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Technetium", "Technetium\Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Technetium.Test", "Technetium.Test\Technetium.Test.csproj", "{EE9E784A-31A4-41D9-85B9-1A562BCE19F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Technetium.Runner", "Technetium.Runner\Technetium.Runner.csproj", "{E463FED0-A48B-4F74-A720-E1C13F45C4CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{EE9E784A-31A4-41D9-85B9-1A562BCE19F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE9E784A-31A4-41D9-85B9-1A562BCE19F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE9E784A-31A4-41D9-85B9-1A562BCE19F2}.Release|Any CPU.Build.0 = Release|Any CPU
{E463FED0-A48B-4F74-A720-E1C13F45C4CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E463FED0-A48B-4F74-A720-E1C13F45C4CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E463FED0-A48B-4F74-A720-E1C13F45C4CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E463FED0-A48B-4F74-A720-E1C13F45C4CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Technetium/Technetium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>13</LangVersion>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 63e6aa6

Please sign in to comment.