-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
421 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}")}]"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.