mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-12-04 20:52:43 +01:00
FillMissingTags is driven against a real MetadataItems built from a hand-rolled ilst box: empty, as a Widevine download arrives, and pre-populated, as an .aaxc download arrives. Reverting any of the three fixes fails a test with the exact value from the issue report. MockLibraryBook.CreateBook gains a copyright knob to match UpdateBookDetails. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using AssertionHelper;
|
|
using DataLayer;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace FileLiberator.Tests;
|
|
|
|
[TestClass]
|
|
public class HtmlToPlainTextTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow(null, "")]
|
|
[DataRow("", "")]
|
|
[DataRow(" ", "")]
|
|
[DataRow("Already plain text.", "Already plain text.")]
|
|
[DataRow(" Padded plain text. ", "Padded plain text.")]
|
|
[DataRow("<p>One paragraph.</p>", "One paragraph.")]
|
|
[DataRow("<p>First.</p> <p>Second.</p>", "First.\nSecond.")]
|
|
[DataRow("<p>First.</p><p>Second.</p>", "First.\nSecond.")]
|
|
[DataRow("<p><b>Bold</b> and <i>italic</i>.</p>", "Bold and italic.")]
|
|
[DataRow("Line one.<br>Line two.", "Line one.\nLine two.")]
|
|
[DataRow("Line one.<br />Line two.", "Line one.\nLine two.")]
|
|
[DataRow("<ul><li>One</li><li>Two</li></ul>", "One\nTwo")]
|
|
[DataRow("<p>Tom & Jerry</p>", "Tom & Jerry")]
|
|
[DataRow("<p>©2024 Someone</p>", "\u00a92024 Someone")]
|
|
[DataRow("<p>Blank</p><p></p><p>lines dropped</p>", "Blank\nlines dropped")]
|
|
public void Flattens(string? html, string expected)
|
|
=> EntityExtensions.HtmlToPlainText(html).Should().Be(expected);
|
|
|
|
[TestMethod]
|
|
public void SeparatorIsConfigurable()
|
|
=> EntityExtensions.HtmlToPlainText("<p>First.</p> <p>Second.</p>", paragraphSeparator: "\r\n\r\n")
|
|
.Should().Be("First.\r\n\r\nSecond.");
|
|
|
|
/// <summary>
|
|
/// Unmarked descriptions skip the parser, so a stray angle bracket cannot swallow the sentence
|
|
/// after it. Entities are still decoded, since Audible writes those into plain text too.
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TextWithoutTagsIsNotParsed()
|
|
{
|
|
EntityExtensions.HtmlToPlainText("5 > 3 and 2 < 4").Should().Be("5 > 3 and 2 < 4");
|
|
EntityExtensions.HtmlToPlainText("Tom & Jerry").Should().Be("Tom & Jerry");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ReadsTheBooksDescription()
|
|
{
|
|
var libraryBook = MockLibraryBook.CreateBook(description: "<p>Hello.</p> <p>World.</p>");
|
|
|
|
libraryBook.Book.DescriptionAsPlainText().Should().Be("Hello.\nWorld.");
|
|
}
|
|
}
|