Skip to content

Commit 284ed7e

Browse files
committed
Fix xref data-throw-if-not-resolved too
1 parent 1835795 commit 284ed7e

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

src/PortToDocs/src/libraries/XmlHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ internal class XmlHelper
6161
{ @"\<(see|seealso){1} cref\=""object""[ ]*\/\>", "<see cref=\"T:System.Object\" />" },
6262
{ @"\<(see|seealso){1} cref\=""dynamic""[ ]*\/\>", "<see langword=\"dynamic\" />" },
6363
{ @"\<(see|seealso){1} cref\=""string""[ ]*\/\>", "<see cref=\"T:System.String\" />" },
64-
{ "<code data-dev-comment-type=\"(?<elementName>[a-zA-Z0-9_]+)\">(?<elementValue>[a-zA-Z0-9_]+)</code>", "<see ${elementName}=\"${elementValue}\" />" },
64+
{ @"<code data-dev-comment-type=""(?<elementName>[a-zA-Z0-9_]+)"">(?<elementValue>[a-zA-Z0-9_]+)</code>", "<see ${elementName}=\"${elementValue}\" />" },
65+
{ @"<xref data-throw-if-not-resolved=""[a-zA-Z0-9_]+"" uid=""(?<docId>.+)""><\/xref>", "<see cref=\"T:${docId}\" />" },
6566
};
6667

6768
private static readonly Dictionary<string, string> _replaceableMarkdownPatterns = new Dictionary<string, string> {
@@ -121,7 +122,8 @@ internal class XmlHelper
121122
// Params, typeparams, langwords
122123
{ @"\<(typeparamref|paramref){1} name\=""(?'refNameContents'[a-zA-Z0-9_\-]+)""[ ]*\/\>", @"`${refNameContents}`" },
123124
{ @"\<see langword\=""(?'seeLangwordContents'[a-zA-Z0-9_\-]+)""[ ]*\/\>", @"`${seeLangwordContents}`" },
124-
{ "<code data-dev-comment-type=\"[a-zA-Z0-9_]+\">(?<elementValue>[a-zA-Z0-9_]+)</code>", "`${elementValue}`" },
125+
{ @"<code data-dev-comment-type=""[a-zA-Z0-9_]+"">(?<elementValue>[a-zA-Z0-9_]+)</code>", "`${elementValue}`" },
126+
{ @"<xref data-throw-if-not-resolved=""[a-zA-Z0-9_]+"" uid=""(?<docId>.+)""><\/xref>", "<xref:${docId}>" },
125127
};
126128

127129
private static readonly string[] _splittingSeparators = new string[] { "\r", "\n", "\r\n" };

src/PortToDocs/tests/PortToDocs.Strings.Tests.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2467,7 +2467,7 @@ I am paragraph number three.</summary>
24672467
}
24682468

24692469
[Fact]
2470-
public void Convert_DataDevCommentType_To_ExpectedElementNames()
2470+
public void Convert_CodeDataDevCommentType_To_ExpectedElementNames()
24712471
{
24722472
// The compiled xml files sometimes generate langwords, paramrefs and typeparamrefs with the format
24732473
// <code data-dev-comment-type="...">...</code>, so we need to convert them to the expected element type.
@@ -2526,6 +2526,66 @@ public void Convert_DataDevCommentType_To_ExpectedElementNames()
25262526
TestWithStrings(originalIntellisense, originalDocs, expectedDocs, configuration);
25272527
}
25282528

2529+
[Fact]
2530+
public void Convert_XrefDataThrowIfNotResolved_To_ExpectedElementNames()
2531+
{
2532+
// The compiled xml files sometimes generate type references with the format
2533+
// <xref data-throw-if-not-resolved="{bool}" uid="{DocId}"></xref>, so we need to convert them to the expected element type.
2534+
2535+
string originalIntellisense = @"<?xml version=""1.0""?>
2536+
<doc>
2537+
<assembly>
2538+
<name>MyAssembly</name>
2539+
</assembly>
2540+
<members>
2541+
<member name=""T:MyNamespace.MyType"">
2542+
<summary>Type: <xref data-throw-if-not-resolved=""true"" uid=""MyNamespace.MyType""></xref>.</summary>
2543+
<remarks>Type: <xref data-throw-if-not-resolved=""true"" uid=""MyNamespace.MyType""></xref>.</remarks>
2544+
</member>
2545+
</members>
2546+
</doc>";
2547+
2548+
string originalDocs = @"<Type Name=""MyType"" FullName=""MyNamespace.MyType"">
2549+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyType"" />
2550+
<AssemblyInfo>
2551+
<AssemblyName>MyAssembly</AssemblyName>
2552+
</AssemblyInfo>
2553+
<Docs>
2554+
<summary>To be added.</summary>
2555+
<remarks>To be added.</remarks>
2556+
</Docs>
2557+
<Members></Members>
2558+
</Type>";
2559+
2560+
string expectedDocs = @"<Type Name=""MyType"" FullName=""MyNamespace.MyType"">
2561+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyType"" />
2562+
<AssemblyInfo>
2563+
<AssemblyName>MyAssembly</AssemblyName>
2564+
</AssemblyInfo>
2565+
<Docs>
2566+
<summary>Type: <see cref=""T:MyNamespace.MyType"" />.</summary>
2567+
<remarks>
2568+
<format type=""text/markdown""><![CDATA[
2569+
2570+
## Remarks
2571+
2572+
Type: <xref:MyNamespace.MyType>.
2573+
2574+
]]></format>
2575+
</remarks>
2576+
</Docs>
2577+
<Members></Members>
2578+
</Type>";
2579+
2580+
Configuration configuration = new()
2581+
{
2582+
MarkdownRemarks = true
2583+
};
2584+
configuration.IncludedAssemblies.Add(FileTestData.TestAssembly);
2585+
2586+
TestWithStrings(originalIntellisense, originalDocs, expectedDocs, configuration);
2587+
}
2588+
25292589
private static void TestWithStrings(string intellisenseFile, string originalDocsFile, string expectedDocsFile, Configuration configuration) =>
25302590
TestWithStrings(intellisenseFile, new List<StringTestData>() { new StringTestData(originalDocsFile, expectedDocsFile) }, configuration);
25312591

0 commit comments

Comments
 (0)