Skip to content

Commit 6434b20

Browse files
authored
Merge pull request #2720 from sharwell/allow-or-para
Update SA1629 to analyze the content of paragraphs
2 parents 3d945bc + 8b8b005 commit 6434b20

3 files changed

Lines changed: 409 additions & 35 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,315 @@ public interface ITest
449449
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
450450
}
451451

452+
[Fact]
453+
public async Task TestMultipleParagraphBlocksAsync()
454+
{
455+
var testCode = @"
456+
/// <summary>
457+
/// <para>Paragraph 1</para>
458+
/// <para>Paragraph 2</para>
459+
/// <para>Paragraph 3</para>
460+
/// </summary>
461+
public interface ITest
462+
{
463+
}
464+
";
465+
466+
var fixedTestCode = @"
467+
/// <summary>
468+
/// <para>Paragraph 1.</para>
469+
/// <para>Paragraph 2.</para>
470+
/// <para>Paragraph 3.</para>
471+
/// </summary>
472+
public interface ITest
473+
{
474+
}
475+
";
476+
477+
DiagnosticResult[] expected =
478+
{
479+
this.CSharpDiagnostic().WithLocation(3, 22),
480+
this.CSharpDiagnostic().WithLocation(4, 22),
481+
this.CSharpDiagnostic().WithLocation(5, 22),
482+
};
483+
484+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
485+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
486+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
487+
}
488+
489+
[Fact]
490+
public async Task TestMultipleParagraphBlocksWithColonsAsync()
491+
{
492+
var testCode = @"
493+
/// <summary>
494+
/// <para>Paragraph 1:</para>
495+
/// <para>Paragraph 2:</para>
496+
/// <para>Paragraph 3:</para>
497+
/// </summary>
498+
public interface ITest
499+
{
500+
}
501+
";
502+
503+
var fixedTestCode = @"
504+
/// <summary>
505+
/// <para>Paragraph 1:</para>
506+
/// <para>Paragraph 2:</para>
507+
/// <para>Paragraph 3:.</para>
508+
/// </summary>
509+
public interface ITest
510+
{
511+
}
512+
";
513+
514+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 23);
515+
516+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
517+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
518+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
519+
}
520+
521+
[Fact]
522+
public async Task TestMultipleParagraphInlinesAsync()
523+
{
524+
var testCode = @"
525+
/// <summary>
526+
/// Paragraph 1
527+
/// <para/>
528+
/// Paragraph 2
529+
/// <para/>
530+
/// Paragraph 3
531+
/// </summary>
532+
public interface ITest
533+
{
534+
}
535+
";
536+
537+
var fixedTestCode = @"
538+
/// <summary>
539+
/// Paragraph 1.
540+
/// <para/>
541+
/// Paragraph 2.
542+
/// <para/>
543+
/// Paragraph 3.
544+
/// </summary>
545+
public interface ITest
546+
{
547+
}
548+
";
549+
550+
DiagnosticResult[] expected =
551+
{
552+
this.CSharpDiagnostic().WithLocation(3, 16),
553+
this.CSharpDiagnostic().WithLocation(5, 16),
554+
this.CSharpDiagnostic().WithLocation(7, 16),
555+
};
556+
557+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
558+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
559+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
560+
}
561+
562+
[Fact]
563+
public async Task TestMultipleParagraphBlocksAfterFirstAsync()
564+
{
565+
var testCode = @"
566+
/// <summary>
567+
/// Paragraph 1
568+
/// <para>Paragraph 2</para>
569+
/// <para>Paragraph 3</para>
570+
/// </summary>
571+
public interface ITest
572+
{
573+
}
574+
";
575+
576+
var fixedTestCode = @"
577+
/// <summary>
578+
/// Paragraph 1.
579+
/// <para>Paragraph 2.</para>
580+
/// <para>Paragraph 3.</para>
581+
/// </summary>
582+
public interface ITest
583+
{
584+
}
585+
";
586+
587+
DiagnosticResult[] expected =
588+
{
589+
this.CSharpDiagnostic().WithLocation(3, 16),
590+
this.CSharpDiagnostic().WithLocation(4, 22),
591+
this.CSharpDiagnostic().WithLocation(5, 22),
592+
};
593+
594+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
595+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
596+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
597+
}
598+
599+
[Fact]
600+
public async Task TestMultipleParagraphBlocksAfterFirstInNoteAsync()
601+
{
602+
var testCode = @"
603+
/// <summary>
604+
/// Paragraph 0
605+
/// <note>
606+
/// Paragraph 1
607+
/// <para>Paragraph 2</para>
608+
/// <para>Paragraph 3</para>
609+
/// </note>
610+
/// </summary>
611+
public interface ITest
612+
{
613+
}
614+
";
615+
616+
var fixedTestCode = @"
617+
/// <summary>
618+
/// Paragraph 0.
619+
/// <note>
620+
/// Paragraph 1.
621+
/// <para>Paragraph 2.</para>
622+
/// <para>Paragraph 3.</para>
623+
/// </note>
624+
/// </summary>
625+
public interface ITest
626+
{
627+
}
628+
";
629+
630+
DiagnosticResult[] expected =
631+
{
632+
this.CSharpDiagnostic().WithLocation(3, 16),
633+
this.CSharpDiagnostic().WithLocation(5, 16),
634+
this.CSharpDiagnostic().WithLocation(6, 22),
635+
this.CSharpDiagnostic().WithLocation(7, 22),
636+
};
637+
638+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
639+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
640+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
641+
}
642+
643+
[Fact]
644+
public async Task TestCodeBetweenParagraphBlocksAsync()
645+
{
646+
var testCode = @"
647+
/// <summary>
648+
/// Paragraph 1
649+
/// <code>Code block</code>
650+
/// <para>Paragraph 2</para>
651+
/// </summary>
652+
public interface ITest
653+
{
654+
}
655+
";
656+
657+
var fixedTestCode = @"
658+
/// <summary>
659+
/// Paragraph 1.
660+
/// <code>Code block</code>
661+
/// <para>Paragraph 2.</para>
662+
/// </summary>
663+
public interface ITest
664+
{
665+
}
666+
";
667+
668+
DiagnosticResult[] expected =
669+
{
670+
this.CSharpDiagnostic().WithLocation(3, 16),
671+
this.CSharpDiagnostic().WithLocation(5, 22),
672+
};
673+
674+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
675+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
676+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
677+
}
678+
679+
[Fact]
680+
[WorkItem(2712, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2712")]
681+
public async Task TestExceptionElementsWithStandardFormAsync()
682+
{
683+
var testCode = @"
684+
using System;
685+
public interface ITest
686+
{
687+
/// <exception cref=""ArgumentNullException"">
688+
/// <para>If <paramref name=""name""/> is <see langword=""null""/></para>
689+
/// <para>-or-</para>
690+
/// <para>If <paramref name=""value""/> is <see langword=""null""/></para>
691+
/// </exception>
692+
void Method(string name, string value);
693+
}
694+
";
695+
696+
var fixedTestCode = @"
697+
using System;
698+
public interface ITest
699+
{
700+
/// <exception cref=""ArgumentNullException"">
701+
/// <para>If <paramref name=""name""/> is <see langword=""null""/>.</para>
702+
/// <para>-or-</para>
703+
/// <para>If <paramref name=""value""/> is <see langword=""null""/>.</para>
704+
/// </exception>
705+
void Method(string name, string value);
706+
}
707+
";
708+
709+
DiagnosticResult[] expected =
710+
{
711+
this.CSharpDiagnostic().WithLocation(6, 67),
712+
this.CSharpDiagnostic().WithLocation(8, 68),
713+
};
714+
715+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
716+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
717+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
718+
}
719+
720+
[Fact]
721+
[WorkItem(2712, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2712")]
722+
public async Task TestExceptionElementsWithAlternateFormAsync()
723+
{
724+
var testCode = @"
725+
using System;
726+
public interface ITest
727+
{
728+
/// <exception cref=""ArgumentNullException"">
729+
/// <para>If <paramref name=""name""/> is <see langword=""null""/></para>
730+
/// -or-
731+
/// <para>If <paramref name=""value""/> is <see langword=""null""/></para>
732+
/// </exception>
733+
void Method(string name, string value);
734+
}
735+
";
736+
737+
var fixedTestCode = @"
738+
using System;
739+
public interface ITest
740+
{
741+
/// <exception cref=""ArgumentNullException"">
742+
/// <para>If <paramref name=""name""/> is <see langword=""null""/>.</para>
743+
/// -or-
744+
/// <para>If <paramref name=""value""/> is <see langword=""null""/>.</para>
745+
/// </exception>
746+
void Method(string name, string value);
747+
}
748+
";
749+
750+
DiagnosticResult[] expected =
751+
{
752+
this.CSharpDiagnostic().WithLocation(6, 67),
753+
this.CSharpDiagnostic().WithLocation(8, 68),
754+
};
755+
756+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
757+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
758+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
759+
}
760+
452761
protected override Project ApplyCompilationOptions(Project project)
453762
{
454763
var resolver = new TestXmlReferenceResolver();

0 commit comments

Comments
 (0)