Skip to content

Commit 356ce4d

Browse files
test: adapt wiki page test to markdown links
1 parent 8cfe72b commit 356ce4d

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

test/Serilog.Sinks.HttpTests/Support/Fixtures/GitHubWikiFixture.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class GitHubWikiFixture
1010
private const string WikiUrl = "https://raw.githubusercontent.com/wiki/FantasticFiasco/serilog-sinks-http/{0}";
1111
private const string DescriptionRegexFormat = "- `{0}` - (?<description>.*)$";
1212

13+
private static readonly Regex LinkRegex = new Regex(@"\[(?<link>[\w\s.]+)\]\((?<url>[\w.:/]+)\)");
14+
1315
private string pageContent;
1416

1517
public async Task LoadAsync(string wikiPage)
@@ -27,8 +29,29 @@ public string GetDescription(string parameterName)
2729
var match = descriptionRegex.Match(pageContent);
2830
if (!match.Success) throw new Exception($"GitHub wiki does not contain a description of parameter \"{parameterName}\"");
2931

30-
return match.Groups["description"].Value
31-
.Replace("`", string.Empty); // Remove code indicator
32+
return
33+
RemoveLinks(
34+
RemoveCodeIndicator(
35+
match.Groups["description"].Value));
36+
}
37+
38+
private static string RemoveCodeIndicator(string description)
39+
{
40+
return description.Replace("`", string.Empty);
41+
}
42+
43+
private static string RemoveLinks(string description)
44+
{
45+
var matches = LinkRegex.Matches(description);
46+
47+
foreach (Match match in matches)
48+
{
49+
description = description.Replace(
50+
match.Groups[0].Value,
51+
match.Groups["link"].Value);
52+
}
53+
54+
return description;
3255
}
3356
}
3457
}

test/Serilog.Sinks.HttpTests/Support/Fixtures/XmlDocumentationFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ public class XmlDocumentationFixture
1111
private readonly XDocument document;
1212
private readonly Regex seeClassRegex;
1313
private readonly Regex seeEnumRegex;
14+
private readonly Regex seeHrefRegex;
1415
private readonly Regex paramRefRegex;
1516

1617
public XmlDocumentationFixture()
1718
{
1819
document = XDocument.Load("Serilog.Sinks.Http.xml");
1920
seeClassRegex = new Regex(@"<see cref=""T:(?<fullName>[\w.]+)""\s*/>");
2021
seeEnumRegex = new Regex(@"<see cref=""F:(?<fullName>[\w.]+)""\s*/>");
22+
seeHrefRegex = new Regex(@"<see href=""(?<url>[\w.:/]+)""\s*>(?<link>[\w\s.]+)</see>");
2123
paramRefRegex = new Regex(@"<paramref name=""(?<parameterName>\w+)""\s*/>");
2224
}
2325

@@ -37,6 +39,7 @@ public string GetDescription(string extensionName, string parameterName)
3739
.Where(row => row.Length > 0)
3840
.Select(RemoveSeeClassLinks)
3941
.Select(RemoveSeeEnumLinks)
42+
.Select(RemoveSeeHrefLinks)
4043
.Select(RemoveParamRefLinks);
4144

4245
return string.Join(" ", description);
@@ -89,6 +92,20 @@ private string RemoveSeeEnumLinks(string description)
8992
return description;
9093
}
9194

95+
private string RemoveSeeHrefLinks(string description)
96+
{
97+
var matches = seeHrefRegex.Matches(description);
98+
99+
foreach (Match match in matches)
100+
{
101+
description = description.Replace(
102+
match.Groups[0].Value,
103+
match.Groups["link"].Value);
104+
}
105+
106+
return description;
107+
}
108+
92109
private string RemoveParamRefLinks(string description)
93110
{
94111
var matches = paramRefRegex.Matches(description);

0 commit comments

Comments
 (0)