diff --git a/src/Noted/Core/Models/EpubXPathLocation.cs b/src/Noted/Core/Models/EpubXPathLocation.cs index 920b405..4e4b31e 100644 --- a/src/Noted/Core/Models/EpubXPathLocation.cs +++ b/src/Noted/Core/Models/EpubXPathLocation.cs @@ -6,7 +6,7 @@ namespace Noted.Core.Models; using System; using System.Text.RegularExpressions; -public struct EpubXPathLocation(string pos0, string pos1) : IComparable +public readonly struct EpubXPathLocation(string pos0, string pos1) : IComparable { public EpubLocation Start { get; init; } = EpubLocation.FromString(pos0); @@ -18,9 +18,9 @@ public static EpubXPathLocation FromString(string location) return new EpubXPathLocation(range[0], range[1]); } - public override string ToString() => $"epubxpath://{this.Start}-{this.End}"; + public override readonly string ToString() => $"epubxpath://{this.Start}-{this.End}"; - public int CompareTo(object? obj) + public readonly int CompareTo(object? obj) { if (obj is not EpubXPathLocation other) { diff --git a/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs b/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs index 5fda9ef..dcf1f18 100644 --- a/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs +++ b/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs @@ -3,17 +3,17 @@ namespace Noted.Tests.Extensions.Readers.Common { - using System.IO; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Noted.Extensions.Readers.Common; + using System.IO; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Noted.Extensions.Readers.Common; - [TestClass] - public class HtmlSectionParserTests - { - private const string TocFragment = @" + [TestClass] + public class HtmlSectionParserTests + { + private const string TocFragment = @"

Table of Contents @@ -59,44 +59,44 @@ public class HtmlSectionParserTests "; - private readonly HtmlSectionParser parser; + private readonly HtmlSectionParser parser; - public HtmlSectionParserTests() - { - this.parser = new HtmlSectionParser(); - } + public HtmlSectionParserTests() + { + this.parser = new HtmlSectionParser(); + } - [TestMethod] - public async Task ParseShouldReturnTableOfContentWithDepth() - { - await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment)); - var toc = await HtmlSectionParser.Parse(stream).ToListAsync(); + [TestMethod] + public async Task ParseShouldReturnTableOfContentWithDepth() + { + await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment)); + var toc = await HtmlSectionParser.Parse(stream).ToListAsync(); - Assert.AreEqual(11, toc.Count); - Assert.AreEqual("Preface", toc[0].Title); - Assert.AreEqual(1, toc[0].Level); - Assert.AreEqual(3859, toc[0].Location); - Assert.AreEqual("Section 1.1", toc[4].Title); - Assert.AreEqual(2, toc[4].Level); - Assert.AreEqual(21076, toc[4].Location); - Assert.AreEqual("Section 1.1.1", toc[5].Title); - Assert.AreEqual(3, toc[5].Level); - Assert.AreEqual("Section 1.2", toc[6].Title); - Assert.AreEqual(2, toc[6].Level); - } + Assert.AreEqual(11, toc.Count); + Assert.AreEqual("Preface", toc[0].Title); + Assert.AreEqual(1, toc[0].Level); + Assert.AreEqual(3859, toc[0].Location); + Assert.AreEqual("Section 1.1", toc[4].Title); + Assert.AreEqual(2, toc[4].Level); + Assert.AreEqual(21076, toc[4].Location); + Assert.AreEqual("Section 1.1.1", toc[5].Title); + Assert.AreEqual(3, toc[5].Level); + Assert.AreEqual("Section 1.2", toc[6].Title); + Assert.AreEqual(2, toc[6].Level); + } - [TestMethod] - public async Task ParseShouldCreateDocumentSectionRelationships() - { - await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment)); - var toc = await HtmlSectionParser.Parse(stream).ToListAsync(); + [TestMethod] + public async Task ParseShouldCreateDocumentSectionRelationships() + { + await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment)); + var toc = await HtmlSectionParser.Parse(stream).ToListAsync(); - Assert.AreEqual(null, toc[3].Parent); // 1 -> null - Assert.AreEqual("Section 1.1", toc[4].Title); - Assert.AreEqual(toc[3], toc[4].Parent); // 1.1 -> 1 - Assert.AreEqual(toc[4], toc[5].Parent); // 1.1.1 -> 1.1 - Assert.AreEqual(toc[3], toc[6].Parent); // 1.2 -> 1 - Assert.AreEqual(null, toc[7].Parent); // 2 -> null + Assert.AreEqual(null, toc[3].Parent); // 1 -> null + Assert.AreEqual("Section 1.1", toc[4].Title); + Assert.AreEqual(toc[3], toc[4].Parent); // 1.1 -> 1 + Assert.AreEqual(toc[4], toc[5].Parent); // 1.1.1 -> 1.1 + Assert.AreEqual(toc[3], toc[6].Parent); // 1.2 -> 1 + Assert.AreEqual(null, toc[7].Parent); // 2 -> null + } } - } } \ No newline at end of file