diff --git a/CodeBlocker.Test/DocCommentTests.cs b/CodeBlocker.Test/DocCommentTests.cs index f802433..9c535fa 100644 --- a/CodeBlocker.Test/DocCommentTests.cs +++ b/CodeBlocker.Test/DocCommentTests.cs @@ -204,6 +204,37 @@ public void ValidationReportsADuplicateTag() Assert.Contains("more than once", issues[0]); } + [TestMethod] + public void ValidationReportsADuplicateUndeclaredTagOnce() + { + DocComment documentation = new(); + documentation.Params.Add(new DocTag { Name = "y", Text = "First." }); + documentation.Params.Add(new DocTag { Name = "y", Text = "Again." }); + documentation.Params.Add(new DocTag { Name = "y", Text = "Third." }); + + IReadOnlyList issues = documentation.Validate(["x"], []); + + Assert.HasCount(4, issues); + Assert.AreEqual(" does not match any declared parameter.", issues[0]); + Assert.AreEqual(" is documented more than once.", issues[1]); + Assert.AreEqual(" is documented more than once.", issues[2]); + Assert.AreEqual("The parameter 'x' has no entry.", issues[3]); + } + + [TestMethod] + public void ValidationReportsADuplicateUndeclaredTypeParameterTagOnce() + { + DocComment documentation = new(); + documentation.TypeParams.Add(new DocTag { Name = "U", Text = "First." }); + documentation.TypeParams.Add(new DocTag { Name = "U", Text = "Again." }); + + IReadOnlyList issues = documentation.Validate([], []); + + Assert.HasCount(2, issues); + Assert.AreEqual(" does not match any declared type parameter.", issues[0]); + Assert.AreEqual(" is documented more than once.", issues[1]); + } + [TestMethod] public void ANamedTagWithEmptyTextIsStillWritten() { diff --git a/CodeBlocker/Templates/DocComment.cs b/CodeBlocker/Templates/DocComment.cs index d82f857..505c3e4 100644 --- a/CodeBlocker/Templates/DocComment.cs +++ b/CodeBlocker/Templates/DocComment.cs @@ -167,8 +167,7 @@ void Check(Collection tags, HashSet declared, string tagName, st { issues.Add($"<{tagName} name=\"{name}\"> is documented more than once."); } - - if (!declared.Contains(name)) + else if (!declared.Contains(name)) { issues.Add($"<{tagName} name=\"{name}\"> does not match any declared {what}."); }