View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.grammar.javadoc;
21  
22  import java.io.File;
23  import java.io.IOException;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractTreeTestSupport;
28  
29  public class JavadocCommentsAstRegressionTest extends AbstractTreeTestSupport {
30      @Override
31      protected String getPackageLocation() {
32          return "com/puppycrawl/tools/checkstyle/grammar/javadoc/";
33      }
34  
35      private String getInlineTagsPath(String filename) throws IOException {
36          return getPath("inlinetags" + File.separator + filename);
37      }
38  
39      private String getHtmlTagsPath(String filename) throws IOException {
40          return getPath("htmltags" + File.separator + filename);
41      }
42  
43      private String getBlockTagsPath(String filename) throws IOException {
44          return getPath("blockTags" + File.separator + filename);
45      }
46  
47      @Test
48      public void testEmptyJavadoc() throws Exception {
49          verifyJavadocTree(getPath("ExpectedEmptyJavadoc.txt"),
50                  getPath("InputEmptyJavadoc.javadoc"));
51      }
52  
53      @Test
54      public void testEmptyJavadocWithTabs() throws Exception {
55          verifyJavadocTree(getPath("ExpectedEmptyJavadocWithTabs.txt"),
56                  getPath("InputEmptyJavadocWithTabs.javadoc"));
57      }
58  
59      @Test
60      public void testEmptyJavadocStartsWithNewline() throws Exception {
61          verifyJavadocTree(getPath("ExpectedEmptyJavadocStartsWithNewline.txt"),
62                  getPath("InputEmptyJavadocStartsWithNewline.javadoc"));
63      }
64  
65      @Test
66      public void testSimpleJavadocWithText() throws Exception {
67          verifyJavadocTree(getPath("ExpectedSimpleJavadocWithText.txt"),
68                  getPath("InputSimpleJavadocWithText.javadoc"));
69      }
70  
71      @Test
72      public void testSimpleJavadocWithText2() throws Exception {
73          verifyJavadocTree(getPath("ExpectedSimpleJavadocWithText2.txt"),
74                  getPath("InputSimpleJavadocWithText2.javadoc"));
75      }
76  
77      @Test
78      public void testAuthorTag() throws Exception {
79          verifyJavadocTree(getBlockTagsPath("ExpectedAuthorTag.txt"),
80                  getBlockTagsPath("InputAuthorTags.javadoc"));
81      }
82  
83      @Test
84      public void testDeprecatedTag() throws Exception {
85          verifyJavadocTree(getBlockTagsPath("ExpectedDeprecatedTag.txt"),
86                  getBlockTagsPath("InputDeprecatedTag.javadoc"));
87      }
88  
89      @Test
90      public void testReturnTag() throws Exception {
91          verifyJavadocTree(getBlockTagsPath("ExpectedReturnTag.txt"),
92                  getBlockTagsPath("InputReturnTag.javadoc"));
93      }
94  
95      @Test
96      public void testParamTag() throws Exception {
97          verifyJavadocTree(getBlockTagsPath("ExpectedParamTag.txt"),
98                  getBlockTagsPath("InputParamTag.javadoc"));
99      }
100 
101     @Test
102     public void testThrowsAndExceptionTag() throws Exception {
103         verifyJavadocTree(getBlockTagsPath("ExpectedThrowsAndExceptionTag.txt"),
104                 getBlockTagsPath("InputThrowsAndExceptionTag.javadoc"));
105     }
106 
107     @Test
108     public void testSinceAndVersionTag() throws Exception {
109         verifyJavadocTree(getBlockTagsPath("ExpectedSinceAndVersionTag.txt"),
110                 getBlockTagsPath("InputSinceAndVersionTag.javadoc"));
111     }
112 
113     @Test
114     public void testSeeTag() throws Exception {
115         verifyJavadocTree(getBlockTagsPath("ExpectedSeeTag.txt"),
116                 getBlockTagsPath("InputSeeTag.javadoc"));
117     }
118 
119     @Test
120     public void testHiddenAndUsesAndProvidesTag() throws Exception {
121         verifyJavadocTree(getBlockTagsPath("ExpectedHiddenAndUsesAndProvidesTag.txt"),
122                 getBlockTagsPath("InputHiddenAndUsesAndProvidesTag.javadoc"));
123     }
124 
125     @Test
126     public void testSerialTags() throws Exception {
127         verifyJavadocTree(getBlockTagsPath("ExpectedSerialTags.txt"),
128                 getBlockTagsPath("InputSerialTags.javadoc"));
129     }
130 
131     @Test
132     public void testCustomBlockTag() throws Exception {
133         verifyJavadocTree(getBlockTagsPath("ExpectedCustomBlockTag.txt"),
134                 getBlockTagsPath("InputCustomBlockTag.javadoc"));
135     }
136 
137     @Test
138     public void testCodeInlineTag() throws Exception {
139         verifyJavadocTree(getInlineTagsPath("ExpectedCodeInlineTag.txt"),
140                 getInlineTagsPath("InputCodeInlineTag.javadoc"));
141     }
142 
143     @Test
144     public void testLinkInlineTag() throws Exception {
145         verifyJavadocTree(getInlineTagsPath("ExpectedLinkInlineTag.txt"),
146                 getInlineTagsPath("InputLinkInlineTag.javadoc"));
147     }
148 
149     @Test
150     public void testLinkInlineTag2() throws Exception {
151         verifyJavadocTree(getInlineTagsPath("ExpectedLinkInlineTag2.txt"),
152                 getInlineTagsPath("InputLinkInlineTag2.javadoc"));
153     }
154 
155     @Test
156     public void testLinkInlineTag3() throws Exception {
157         verifyJavadocTree(getInlineTagsPath("ExpectedLinkInlineTag3.txt"),
158                 getInlineTagsPath("InputLinkInlineTag3.javadoc"));
159     }
160 
161     @Test
162     public void testValueAndInheritDocInlineTag() throws Exception {
163         verifyJavadocTree(getInlineTagsPath("ExpectedValueAndInheritDocInlineTag.txt"),
164                 getInlineTagsPath("InputValueAndInheritDocInlineTag.javadoc"));
165     }
166 
167     @Test
168     public void testSystemPropertyInlineTag() throws Exception {
169         verifyJavadocTree(getInlineTagsPath("ExpectedSystemPropertyTag.txt"),
170                 getInlineTagsPath("InputSystemPropertyTag.javadoc"));
171     }
172 
173     @Test
174     public void testLiteralAndCustomInlineTag() throws Exception {
175         verifyJavadocTree(getInlineTagsPath("ExpectedLiteralAndCustomInline.txt"),
176                 getInlineTagsPath("InputLiteralAndCustomInline.javadoc"));
177     }
178 
179     @Test
180     public void testReturnAndIndexInlineTag() throws Exception {
181         verifyJavadocTree(getInlineTagsPath("ExpectedReturnAndIndexInlineTag.txt"),
182                 getInlineTagsPath("InputReturnAndIndexInlineTag.javadoc"));
183     }
184 
185     @Test
186     public void testSnippetAttributeInline() throws Exception {
187         verifyJavadocTree(getInlineTagsPath("ExpectedSnippetAttributeInlineTag.txt"),
188                 getInlineTagsPath("InputSnippetAttributeInlineTag.javadoc"));
189     }
190 
191     @Test
192     public void testSnippetAttributeInline2() throws Exception {
193         verifyJavadocTree(getInlineTagsPath("ExpectedSnippetAttributeInlineTag2.txt"),
194                 getInlineTagsPath("InputSnippetAttributeInlineTag2.javadoc"));
195     }
196 
197     @Test
198     public void testHtmlElements() throws Exception {
199         verifyJavadocTree(getHtmlTagsPath("ExpectedHtmlElements.txt"),
200                 getHtmlTagsPath("InputHtmlElements.javadoc"));
201     }
202 
203     @Test
204     public void testHtmlVoidTags() throws Exception {
205         verifyJavadocTree(getHtmlTagsPath("ExpectedHtmlVoidTags.txt"),
206                 getHtmlTagsPath("InputHtmlVoidTags.javadoc"));
207     }
208 
209     @Test
210     public void testEmptyHtmlContent() throws Exception {
211         verifyJavadocTree(getHtmlTagsPath("ExpectedEmptyHtmlContent.txt"),
212                 getHtmlTagsPath("InputEmptyHtmlContent.javadoc"));
213     }
214 
215     @Test
216     public void testNonTightTags1() throws Exception {
217         verifyJavadocTree(getHtmlTagsPath("ExpectedNonTightTags1.txt"),
218                 getHtmlTagsPath("InputNonTightTags1.javadoc"));
219     }
220 
221     @Test
222     public void testNonTightTags2() throws Exception {
223         verifyJavadocTree(getHtmlTagsPath("ExpectedNonTightTags2.txt"),
224                 getHtmlTagsPath("InputNonTightTags2.javadoc"));
225     }
226 
227     @Test
228     public void testNonTightTags3() throws Exception {
229         verifyJavadocTree(getHtmlTagsPath("ExpectedNonTightTags3.txt"),
230                 getHtmlTagsPath("InputNonTightTags3.javadoc"));
231     }
232 
233     @Test
234     public void testNonTightTags4() throws Exception {
235         verifyJavadocTree(getHtmlTagsPath("ExpectedNonTightTags4.txt"),
236                 getHtmlTagsPath("InputNonTightTags4.javadoc"));
237     }
238 
239     @Test
240     public void testJavadocWithoutLeadingAsterisks() throws Exception {
241         verifyJavadocTree(getPath("ExpectedJavadocWithoutLeadingAsterisk.txt"),
242                 getPath("InputJavadocWithoutLeadingAsterisk.javadoc"));
243     }
244 
245     @Test
246     public void testNewlinesInHtmlAttributes() throws Exception {
247         verifyJavadocTree(getHtmlTagsPath("ExpectedNewlinesInHtmlAttributes.txt"),
248                 getHtmlTagsPath("InputNewlinesInHtmlAttributes.javadoc"));
249     }
250 
251     @Test
252     public void testCrAsNewLine() throws Exception {
253         verifyJavadocTree(getPath("ExpectedCrAsNewline.txt"),
254                 getPath("InputCrAsNewline.javadoc"));
255     }
256 
257     @Test
258     public void testHtmlComments() throws Exception {
259         verifyJavadocTree(getHtmlTagsPath("ExpectedHtmlComment.txt"),
260                 getHtmlTagsPath("InputHtmlComment.javadoc"));
261     }
262 }