-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTextHelperTests.cs
60 lines (48 loc) · 1.71 KB
/
TextHelperTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace X.Extensions.Text.Tests;
public class TextHelperTests
{
[Theory]
[InlineData("This is a test string.", 10, "...", "This is...")]
[InlineData("Short", 10, "...", "Short")]
[InlineData("", 10, "...", "")]
public void Substring_WithEndPart_ReturnsCorrectSubstring(string input, int length, string endPart, string expected)
{
var result = TextHelper.Substring(input, length, endPart);
Assert.Equal(expected, result);
}
[Fact]
public void CleanCharacters_RemovesSystemCharacters()
{
var input = "Hello & World!";
var expected = "hello-world";
var result = TextHelper.CleanCharacters(input);
Assert.Equal(expected, result);
}
[Fact]
public void CleanCharacters_HandlesEmptyString()
{
var input = "";
var expected = "";
var result = TextHelper.CleanCharacters(input);
Assert.Equal(expected, result);
}
[Fact]
public void Replace_ReplacesCharacters()
{
var input = "Hello & World!";
var forReplace = new[] { "&", "!" };
var whichReplace = "";
var expected = "Hello World";
var result = TextHelper.Replace(input, forReplace, whichReplace);
Assert.Equal(expected, result);
}
[Theory]
[InlineData("<p>This is a test</p>", "This is a test")]
[InlineData("<div><p>This is a test</p></div>", "This is a test")]
[InlineData("<html><body>This is a test</body></html>", "This is a test")]
public void ToPlainText_ConvertsHtmlToPlainText(string input, string expected)
{
var result = TextHelper.ToPlainText(input);
Assert.Equal(expected, result);
}
}