-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHtmlConverterTests.cs
50 lines (41 loc) · 1.59 KB
/
HtmlConverterTests.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
using Xunit;
namespace X.Extensions.Text.Tests;
public class HtmlConverterTests
{
[Theory]
[InlineData("<br>This is a test", "This is a test")]
[InlineData("<p>This is a test</p>", "This is a test<br />")]
[InlineData("<P>This is a test</P>", "This is a test<br />")]
[InlineData("Hello<br>World", "Hello<br />World")]
[InlineData("Hello<br/><br/>World", "Hello<br />World")]
[InlineData("<p>Hello<br/><br/>World", "Hello<br />World")]
public void ToPlainText_WithPreserveLineBreaks_ShouldConvertHtmlToPlainText_WithLineBreaks(string input, string expected)
{
// Act
var result = TextHelper.ToPlainText(input, preserveLineBreaks: true);
// Assert
Assert.Equal(expected, result);
}
[Theory]
[InlineData("<br>This is a test", "This is a test")]
[InlineData("<p>This is a test</p>", "This is a test")]
[InlineData("Hello<br>World", "HelloWorld")]
public void ToPlainText_WithoutPreserveLineBreaks_ShouldConvertHtmlToPlainText_WithoutLineBreaks(string input, string expected)
{
// Act
var result = TextHelper.ToPlainText(input, preserveLineBreaks: false);
// Assert
Assert.Equal(expected, result);
}
[Fact]
public void ToPlainText_WithMultipleConsecutiveLineBreaks_ShouldCollapseIntoSingleBreak()
{
// Arrange
var input = "<br><br><br>This is a test<p></p>";
// Act
var result = TextHelper.ToPlainText(input, preserveLineBreaks: true);
// Assert
var expected = "This is a test<br />";
Assert.Equal(expected, result);
}
}