Skip to content

Commit 471d98c

Browse files
committed
test: WronglyCommentCompoundClass (wip)
1 parent b9fcdb2 commit 471d98c

File tree

9 files changed

+82
-10
lines changed

9 files changed

+82
-10
lines changed

src/M31.FluentApi.Generator/SourceGenerators/SymbolInfoCreator.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,23 @@ private static Comments GetFluentSymbolComments(ISymbol symbol)
210210
SyntaxNode syntaxNode = syntaxRef.GetSyntax();
211211
SyntaxTriviaList leadingTrivia = syntaxNode.GetLeadingTrivia();
212212

213-
string[] commentLines = leadingTrivia
214-
.Where(t => t.IsKind(SyntaxKind.SingleLineCommentTrivia) ||
215-
t.IsKind(SyntaxKind.MultiLineCommentTrivia))
216-
.Select(t => t.ToString().TrimStart('/', ' '))
217-
.ToArray();
213+
List<string> commentLines = new List<string>();
214+
215+
foreach (SyntaxTrivia syntaxTrivia in leadingTrivia)
216+
{
217+
if (!syntaxTrivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
218+
{
219+
continue;
220+
}
221+
222+
string str = syntaxTrivia.ToString();
223+
if (!str.Trim().StartsWith("////")) // todo: regex
224+
{
225+
continue;
226+
}
227+
228+
commentLines.Add(str.TrimStart('/', ' '));
229+
}
218230

219231
string comments = string.Join(Environment.NewLine, commentLines);
220232
return FluentCommentsParser.Parse(comments);

src/M31.FluentApi.Tests/CodeGeneration/TestClasses/Abstract/FluentApiComments/CommentedPropertiesClass/Student.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public class Student
2424
[FluentMember(0)]
2525
public string FirstName { get; set; }
2626

27-
// <fluentSummary method="WithLastName">
28-
// Sets the student's last name.
29-
// </fluentSummary>
30-
// <fluentParam method="WithLastName" name="lastName">The student's last name.</fluentParam>
27+
//// <fluentSummary method="WithLastName">
28+
//// Sets the student's last name.
29+
//// </fluentSummary>
30+
//// <fluentParam method="WithLastName" name="lastName">The student's last name.</fluentParam>
3131
[FluentMember(1)]
3232
public string LastName { get; set; }
3333

src/M31.FluentApi.Tests/CodeGeneration/TestClasses/Abstract/FluentApiComments/WronglyCommentedClass/CreateStudent.expected.txt

Whitespace-only changes.

src/M31.FluentApi.Tests/CodeGeneration/TestClasses/Abstract/FluentApiComments/WronglyCommentedClass/CreateStudent.g.cs

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Non-nullable member is uninitialized
2+
#pragma warning disable CS8618
3+
// ReSharper disable All
4+
5+
using M31.FluentApi.Attributes;
6+
7+
namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.FluentApiComments.
8+
WronglyCommentedClass;
9+
10+
[FluentApi]
11+
public class Student
12+
{
13+
// <fluentSummary>
14+
// Sets the student's city.
15+
// </fluentSummary>
16+
// <fluentParam name="city">The student's city.</fluentParam>
17+
//
18+
// <fluentSummary>
19+
// Set's the student's city to Boston.
20+
// </fluentSummary>
21+
//
22+
// <fluentSummary>
23+
// Set's the student's city to null.
24+
// </fluentSummary>
25+
[FluentMember(0, "LivingIn")]
26+
[FluentDefault("LivingInBoston")]
27+
[FluentNullable("InUnknownCity")]
28+
public string? City { get; set; } = "Boston";
29+
}

src/M31.FluentApi.Tests/CodeGeneration/TestClasses/Abstract/FluentApiComments/WronglyCommentedClass2/CreateStudent.expected.txt

Whitespace-only changes.

src/M31.FluentApi.Tests/CodeGeneration/TestClasses/Abstract/FluentApiComments/WronglyCommentedClass2/CreateStudent.g.cs

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Non-nullable member is uninitialized
2+
#pragma warning disable CS8618
3+
// ReSharper disable All
4+
5+
using M31.FluentApi.Attributes;
6+
7+
namespace M31.FluentApi.Tests.CodeGeneration.TestClasses.Abstract.FluentApiComments.
8+
WronglyCommentedClass2;
9+
10+
[FluentApi]
11+
public class Student
12+
{
13+
///// <fluentSummary>
14+
///// Sets the student's city.
15+
///// </fluentSummary>
16+
///// <fluentParam name="city">The student's city.</fluentParam>
17+
/////
18+
///// <fluentSummary>
19+
///// Set's the student's city to Boston.
20+
///// </fluentSummary>
21+
/////
22+
///// <fluentSummary>
23+
///// Set's the student's city to null.
24+
///// </fluentSummary>
25+
[FluentMember(0, "LivingIn")]
26+
[FluentDefault("LivingInBoston")]
27+
[FluentNullable("InUnknownCity")]
28+
public string? City { get; set; } = "Boston";
29+
}

src/M31.FluentApi.Tests/CodeGeneration/TestDataProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ internal class TestDataProvider : IEnumerable<object[]>
2626
new object[] { "Abstract", "FluentApiComments", "CommentedMethodsClass", "Student" },
2727
new object[] { "Abstract", "FluentApiComments", "CommentedPropertiesClass", "Student" },
2828
new object[] { "Abstract", "FluentApiComments", "CommentedPropertiesClassAdvanced", "Student" },
29-
new object[] { "Abstract", "FluentApiComments", "RedundantCommentCompoundClass", "Student" },
3029
new object[] { "Abstract", "FluentApiComments", "IncompletelyCommentedPropertyClass", "Student"},
30+
new object[] { "Abstract", "FluentApiComments", "RedundantCommentCompoundClass", "Student" },
31+
new object[] { "Abstract", "FluentApiComments", "WronglyCommentCompoundClass", "Student" },
32+
new object[] { "Abstract", "FluentApiComments", "WronglyCommentCompoundClass2", "Student" },
3133
new object[] { "Abstract", "EmptyClass", "Student" },
3234
new object[] { "Abstract", "FluentDefaultMemberClass", "Student" },
3335
new object[] { "Abstract", "FluentLambdaClass", "Student|Address" },

0 commit comments

Comments
 (0)