forked from reinforced/Reinforced.Typings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add DocumentationRemarks as a target for the XmlParser to store…
… the <remarks /> section from the XmlDoc. Include tests which also document the need for a <summary /> or <inheritdoc /> section to access it via GetDocumentationMember(). This is mainly to keep backward compatibility with the currently emitted code. reinforced#290
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.RemarksDocs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Reinforced.Typings.Fluent; | ||
using Xunit; | ||
|
||
namespace Reinforced.Typings.Tests.SpecificCases | ||
{ | ||
public partial class SpecificTestCases | ||
{ | ||
/// <summary> | ||
/// dummy | ||
/// </summary> | ||
/// <remarks> | ||
/// Class remark. | ||
/// </remarks> | ||
public class SomeClassWithRemarks | ||
{ | ||
/// <summary> | ||
/// dummy | ||
/// </summary> | ||
/// <remarks> | ||
/// Ctor remark. | ||
/// </remarks> | ||
public SomeClassWithRemarks() { } | ||
|
||
/// <inheritdoc cref="SomeClassWithDocs"/> | ||
/// <remarks> | ||
/// Property remark. | ||
/// </remarks> | ||
public string ClassProp { get; set; } | ||
|
||
/// <inheritdoc cref="SomeClassWithDocs"/> | ||
/// <remarks> | ||
/// Method remark. | ||
/// </remarks> | ||
public void Method() { } | ||
} | ||
|
||
[Fact] | ||
public void RemarksParsedFromDocs() | ||
{ | ||
const string result = @" | ||
module Reinforced.Typings.Tests.SpecificCases { | ||
/** dummy */ | ||
export class SomeClassWithRemarks | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public ClassProp: string; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public Method() : void { } | ||
} | ||
}"; | ||
AssertConfiguration( | ||
s => | ||
{ | ||
s.TryLookupDocumentationForAssembly(typeof(SpecificTestCases).Assembly); | ||
s.ExportAsClass<SomeClassWithRemarks>() | ||
.WithPublicProperties() | ||
.WithPublicMethods(); | ||
}, | ||
result, | ||
expAction => | ||
{ | ||
// Currently the <remarks /> are just parsed into the DocumentationMember | ||
// but not used in the generated typings. Hence we use the action on | ||
// the ExportContext to perform the actual test. | ||
// To avoid surprises like empty docs <remarks /> are currently only valid | ||
// if there is a <summar /> or <inheritdoc /> tag. | ||
|
||
var type = typeof(SomeClassWithRemarks); | ||
|
||
var classDoc = expAction.Context.Documentation.GetDocumentationMember(type); | ||
Assert.NotNull(classDoc); | ||
Assert.Equal("Class remark.", classDoc.Remarks.Text); | ||
|
||
var memberDoc = expAction.Context.Documentation.GetDocumentationMember(type.GetProperty(nameof(SomeClassWithRemarks.ClassProp))); | ||
Assert.NotNull(memberDoc); | ||
Assert.Equal("Property remark.", memberDoc.Remarks.Text); | ||
|
||
var methodeDoc = expAction.Context.Documentation.GetDocumentationMember(type.GetMethod(nameof(SomeClassWithRemarks.Method))); | ||
Assert.NotNull(methodeDoc); | ||
Assert.Equal("Method remark.", methodeDoc.Remarks.Text); | ||
|
||
var ctorRemark = expAction.Context.Documentation.GetDocumentationMember(type.GetConstructor(Array.Empty<Type>())); | ||
Assert.NotNull(ctorRemark); | ||
Assert.Equal("Ctor remark.", ctorRemark.Remarks.Text); | ||
} | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters