Skip to content

Commit

Permalink
Added Multi line documentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
FaustVX committed May 18, 2024
1 parent 3e828bb commit a8ef852
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 6 deletions.
18 changes: 12 additions & 6 deletions PrimaryParameter.SG/Parameter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text;

namespace PrimaryParameter.SG;

record Parameter(string Namespace, ParentClass TypeName, string ParamName, string ParamType, IGeneratedMember[] FieldNames);
Expand All @@ -11,12 +13,16 @@ interface IGeneratedMember
record GenerateSummary(IGeneratedMember Generator, string Summary) : IGeneratedMember
{
string IGeneratedMember.Name => Generator.Name;
string IGeneratedMember.GenerateMember(Parameter param) => $"""
/// <summary>
/// {Summary}
/// </summary>
{Generator.GenerateMember(param)}
""";
string IGeneratedMember.GenerateMember(Parameter param)
{
var sb = new StringBuilder()
.AppendLine("/// <summary>");
foreach (var line in Summary.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries).Select(static text => $"/// {text}"))
sb.AppendLine(line);
return sb.AppendLine("/// </summary>")
.AppendLine(Generator.GenerateMember(param))
.ToString();
}
}

record GenerateField(string Name, bool IsReadonly, string Scope, string AssignFormat, string? Type) : IGeneratedMember
Expand Down
13 changes: 13 additions & 0 deletions PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,17 @@ public class C([Property(Summary = "Documentation")] int i);
// Pass the source code to our helper and snapshot test the output
return TestHelper.Verify(source);
}

[Fact]
public Task GenerateMultiLineDocumentation()
{
// The source code to test
var source = """
using PrimaryParameter.SG;
public class C([Property(Summary = "Documentation\nNew Line")] int i);
""";

// Pass the source code to our helper and snapshot test the output
return TestHelper.Verify(source);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//HintName: DoNotUseAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)]
sealed class DoNotUseAttribute : Attribute
{
public bool AllowInMemberInit { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//HintName: FaustVX.PrimaryParameter.SG.g.cs
#pragma warning disable
// <auto-generated/>
partial class C
{
/// <summary>
/// Documentation
/// New Line
/// </summary>
public int I { get; init; } = i;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//HintName: FieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
sealed class FieldAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public bool IsReadonly { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//HintName: PropertyAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
sealed class PropertyAttribute : Attribute
{
public string Name { get; init; }
public string AssignFormat { get; init; }
public Type Type { get; init; }
public string Setter { get; init; }
public string Scope { get; init; }
public string Summary { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//HintName: RefFieldAttribute.g.cs
#pragma warning disable
// <auto-generated/>
using global::System;
namespace PrimaryParameter.SG
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)]
sealed class RefFieldAttribute : Attribute
{
public string Name { get; init; }
public string Scope { get; init; }
public bool IsReadonlyRef { get; init; }
public bool IsRefReadonly { get; init; }
public string Summary { get; init; }
}
}

0 comments on commit a8ef852

Please sign in to comment.