public void Should_Have_Correct_Html_Nesting_And_Warning_Titles_When_Missing_Levels() { // From issue #177 // Arrange TocParser tocParser = new TocParser(); string html = "{TOC} <p>some text</p>"; html += "<h1>h1</h1>"; // deliberately removed //html += " <h2>h2</h2>"; // deliberately removed html += " <h3>h3a</h3>"; html += " <h4>h4a</h4>"; html += " <h4>h4b</h4>"; html += " <h3>h3b</h3>"; html += " <h4>h4c</h4>"; html += " <h5>h5a</h5>"; html += " <h5>h5b</h5>"; html += " <h3>h3c</h3>"; html += " <h4>h4d</h4>"; html += " <h2>h2b</h2>"; //html += " <h3>h3</h3>"; // deliberately removed //html += " <h4>h4</h4>"; // deliberately removed html += " <h5>h5c</h5>"; // Act string actual = tocParser.InsertToc(html); // Assert Assert.That(actual, Is.StringContaining("(Missing level 2 header)")); Assert.That(actual, Is.StringContaining("(Missing level 3 header)")); Assert.That(actual, Is.StringContaining("(Missing level 4 header)")); Assert.That(actual, Is.StringContaining("1.3 h3c")); Assert.That(actual, Is.StringContaining("1.3.1 h4d")); }
private string GetLatestGameVersion(string baseDir, IEnumerable <string> installedFolders) { var versions = new List <string>(); foreach (var dir in installedFolders) { var path = Path.Combine(baseDir, dir); var tocFile = FileUtilities.GetFiles(path, "*.toc").FirstOrDefault(); if (tocFile == null) { continue; } var gameVersion = new TocParser(tocFile).Interface; if (string.IsNullOrEmpty(gameVersion)) { continue; } versions.Add(gameVersion); } return(versions.OrderByDescending(ver => ver).FirstOrDefault() ?? string.Empty); }
public void Should_Have_Correct_Titles() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act tocParser.InsertToc(html); // Assert Item root = tocParser.Tree.Root; List<Item> allH2s = root.Children.ToList(); Item firstH2 = allH2s[0]; Item firstH3 = firstH2.GetChild(0); Item secondH2 = allH2s[1]; Item thirdH3 = secondH2.GetChild(1); Item firstH4 = thirdH3.GetChild(0); Assert.That(firstH2.Title, Is.EqualTo("First h2")); Assert.That(firstH3.Title, Is.EqualTo("First h3")); Assert.That(secondH2.Title, Is.EqualTo("Second h2")); Assert.That(thirdH3.Title, Is.EqualTo("Third h3")); Assert.That(firstH4.Title, Is.EqualTo("Lonely h4")); }
public void Should_Have_Correct_Titles() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act tocParser.InsertToc(html); // Assert Item root = tocParser.Tree.Root; List <Item> allH2s = root.Children.ToList(); Item firstH2 = allH2s[0]; Item firstH3 = firstH2.GetChild(0); Item secondH2 = allH2s[1]; Item thirdH3 = secondH2.GetChild(1); Item firstH4 = thirdH3.GetChild(0); Assert.That(firstH2.Title, Is.EqualTo("First h2")); Assert.That(firstH3.Title, Is.EqualTo("First h3")); Assert.That(secondH2.Title, Is.EqualTo("Second h2")); Assert.That(thirdH3.Title, Is.EqualTo("Third h3")); Assert.That(firstH4.Title, Is.EqualTo("Lonely h4")); }
public void TestParse() { var sut = new TocParser(); var actual = sut.MakeToc(content); var expected = @"Table of Content * [2. Configuration](#2-configuration) * [2.1 Stacked configuration principle](#21-stacked-configuration-principle) * [2.2 Simple changes](#22-simple-changes) * [2.3 Culture specific printing](#23-culture-specific-printing) * [2.4 Output as a single line](#24-output-as-a-single-line) * [2.5 Field harvesting](#25-field-harvesting) * [2.6 Simple value printing](#26-simple-value-printing) * [2.7 Output formatting](#27-output-formatting) * [Curly style](#curly-style) * [JSon style](#json-style) * [XML style](#xml-style) * [3. Unit testing](#3-unit-testing) * [3.1 Restricting fields harvested](#31-restricting-fields-harvested) * [4. License](#4-license) "; Create.Printer().Assert.IsSame(expected, actual); }
public void TestReplace() { var parser = new TocParser(); var replacer = new ContentReplacer(); var toc = parser.MakeToc(content); var expected = @"Table of Content * [1. Introduction](#1-introduction) * [2. Configuration](#2-configuration) * [2.1 Stacked configuration principle](#21-stacked-configuration-principle) * [2.2 Simple changes](#22-simple-changes)"; Create.Assert2().PrintIsSame(expected, toc); var newVersion = @""" ""Automatic `Asser.AreEqual()` and automatic `ToString()`."" Like a JSON serializer on drugs Table of Content * [1. Introduction](#1-introduction) * [2. Configuration](#2-configuration) * [2.1 Stacked configuration principle](#21-stacked-configuration-principle) * [2.2 Simple changes](#22-simple-changes) # 1. Introduction this is the intro and so forth # 2. Configuration StatePrinter is configurable. The configuration can be broken down to three parts each of which represents . * `IFieldHarvester` deals with how/which fields are harvested from types. E.g. only public fields are printed. Finally, culture specific printing of dates and numbers are supported. ## 2.1 Stacked configuration principle The Stateprinter has a configuration object that for the e use. This is due to the FILO tems in the reverse order they lues. ```C# public static Configuration GetStandardConfiguration() ## 2.2 Simple changes The `Configuration` class should be rather self-documenting. var cfg = Confi"""; Create.Assert().PrintIsSame(newVersion, replacer.TryReplaceToc(content, toc)); // parsing the result again must yield the same result Assert.AreEqual(newVersion, replacer.TryReplaceToc(newVersion, parser.MakeToc(newVersion))); }
public void Should_Have_Named_Anchors_Inserted_By_Headers_In_Html() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act string actual = tocParser.InsertToc(html); // Assert StringAssert.IsMatch(@"<h2><a name=\"".*?""></a>First h2</h2>", actual); }
public void should_have_named_anchors_inserted_by_headers_in_html() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act string actual = tocParser.InsertToc(html); // Assert StringAssert.IsMatch(@"<h2><a name=\"".*?""></a>First h2</h2>", actual); }
public void Should_Ignore_Multiple_Curlies() { // Arrange TocParser tocParser = new TocParser(); string html = "Give me a {{TOC}} and a {{{{TOC}}}} - the should not render a TOC"; string expected = html; // Act string actual = tocParser.InsertToc(html); // Assert Assert.That(actual, Is.EqualTo(expected)); }
void Handle(string path) { var content = File.ReadAllText(path); var toc = new TocParser().MakeToc(content); var newContent = new ContentReplacer().TryReplaceToc(content, toc); if (newContent != null && content != newContent) { Console.Write(" ... Updating"); File.WriteAllText(path, newContent, Encoding.UTF8); } Console.WriteLine(""); }
string Logic(string url) { if (!url.ToLower().EndsWith(".md")) { return(""); } reader = reader ?? new UrlReader(); var page = reader.ReadUrl(new Uri(url)); var parser = new TocParser(); var tocString = parser.MakeToc(page); return(tocString); }
public void Should_Have_Correct_Tree_Structure_From_Basic_Html() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act tocParser.InsertToc(html); // Assert Item root = tocParser.Tree.Root; Assert.That(root, Is.Not.Null); Assert.That(root.Level, Is.EqualTo(Tree.DEFAULT_LEVEL_ZERO_BASED)); List <Item> allH2s = root.Children.ToList(); Assert.That(allH2s.Count, Is.EqualTo(2)); // <h2>First h2</h2> Item firstH2 = allH2s[0]; Assert.That(firstH2.Children.Count(), Is.EqualTo(1)); Item firstH3 = firstH2.GetChild(0); Assert.That(firstH3.Children.Count(), Is.EqualTo(0)); // <h2>Second h2</h2> Item secondH2 = allH2s[1]; Assert.That(secondH2.Children.Count(), Is.EqualTo(2)); Item secondH3 = secondH2.GetChild(0); Assert.That(secondH3.Children.Count(), Is.EqualTo(0)); Item thirdH3 = secondH2.GetChild(1); Assert.That(thirdH3.Children.Count(), Is.EqualTo(1)); Item firstH4 = thirdH3.GetChild(0); Assert.That(firstH4.Children.Count(), Is.EqualTo(0)); }
public void Should_Have_Correct_Section_Numbering_For_Large_Lists() { // Arrnage TocParser tocParser = new TocParser(); string html = GetLotsOfHeaders(); // Act string actual = tocParser.InsertToc(html); // Assert // (really basic asserts, as the alternative is to just copy the HTML) Assert.That(actual, Is.Not.StringContaining("1 First h1")); Assert.That(actual, Is.StringContaining("1. First h2")); Assert.That(actual, Is.StringContaining("2. Second h2")); Assert.That(actual, Is.StringContaining("2.1 h3 number #0")); Assert.That(actual, Is.StringContaining("2.47 h3 number #46")); Assert.That(actual, Is.StringContaining("2.52 Yet Another h3")); Assert.That(actual, Is.StringContaining("2.52.1 Lonely h4")); }
public void Should_Have_Correct_Tree_Structure_From_Basic_Html() { // Arrange TocParser tocParser = new TocParser(); string html = GetHtml(); // Act tocParser.InsertToc(html); // Assert Item root = tocParser.Tree.Root; Assert.That(root, Is.Not.Null); Assert.That(root.Level, Is.EqualTo(Tree.DEFAULT_LEVEL_ZERO_BASED)); List<Item> allH2s = root.Children.ToList(); Assert.That(allH2s.Count, Is.EqualTo(2)); // <h2>First h2</h2> Item firstH2 = allH2s[0]; Assert.That(firstH2.Children.Count(), Is.EqualTo(1)); Item firstH3 = firstH2.GetChild(0); Assert.That(firstH3.Children.Count(), Is.EqualTo(0)); // <h2>Second h2</h2> Item secondH2 = allH2s[1]; Assert.That(secondH2.Children.Count(), Is.EqualTo(2)); Item secondH3 = secondH2.GetChild(0); Assert.That(secondH3.Children.Count(), Is.EqualTo(0)); Item thirdH3 = secondH2.GetChild(1); Assert.That(thirdH3.Children.Count(), Is.EqualTo(1)); Item firstH4 = thirdH3.GetChild(0); Assert.That(firstH4.Children.Count(), Is.EqualTo(0)); }