View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.checks.javadoc;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocRegexpCheck.MSG_JAVADOC_REGEXP;
23  
24  import org.junit.jupiter.api.Test;
25  
26  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
27  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
28  
29  public class JavadocRegexpCheckTest extends AbstractModuleTestSupport {
30  
31      @Override
32      public String getPackageLocation() {
33          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocregexp";
34      }
35  
36      @Test
37      public void testDefault() throws Exception {
38          verifyWithInlineConfigParser(
39                  getPath("InputJavadocRegexpDefault.java"), CommonUtil.EMPTY_STRING_ARRAY);
40      }
41  
42      @Test
43      public void testIgnoreMarkupTrue() throws Exception {
44          final String format = "(^|\\W)(aka|input|e\\.g\\.|viz\\.)(\\W|$)";
45          final String[] expected = {
46              "22: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
47              "29: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
48              "36: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
49          };
50  
51          verifyWithInlineConfigParser(
52                  getPath("InputJavadocRegexpIgnoreMarkupTrue.java"), expected);
53      }
54  
55      @Test
56      public void testBlockTag() throws Exception {
57          final String format = "legacy|external";
58          final String[] expected = {
59              "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
60              "25: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
61          };
62  
63          verifyWithInlineConfigParser(
64                  getPath("InputJavadocRegexpBlockTag.java"), expected);
65      }
66  
67      @Test
68      public void testInlineTag() throws Exception {
69          final String format = "temporary|beta";
70          final String[] expected = {
71              "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
72              "23: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
73          };
74  
75          verifyWithInlineConfigParser(
76                  getPath("InputJavadocRegexpInlineTag.java"), expected);
77      }
78  
79      @Test
80      public void testSnippetTag() throws Exception {
81          final String format = "lang=\"e\\.g\\.\"|forbidden\\s*=";
82          final String[] expected = {
83              "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
84              "25: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
85          };
86  
87          verifyWithInlineConfigParser(
88                  getPath("InputJavadocRegexpSnippetTag.java"), expected);
89      }
90  
91      @Test
92      public void testIgnoreMarkupFalse() throws Exception {
93          final String format = "<br\\s*[/]?>|aka";
94          final String[] expected = {
95              "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
96              "23: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
97          };
98  
99          verifyWithInlineConfigParser(
100                 getPath("InputJavadocRegexpIgnoreMarkupFalse.java"), expected);
101     }
102 
103     @Test
104     public void testIgnoreCaseFalse() throws Exception {
105         verifyWithInlineConfigParser(
106                 getPath("InputJavadocRegexpIgnoreCaseFalse.java"), CommonUtil.EMPTY_STRING_ARRAY);
107     }
108 
109     @Test
110     public void testIgnoreCaseTrue() throws Exception {
111         final String format = "AKA";
112         final String[] expected = {
113             "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
114         };
115 
116         verifyWithInlineConfigParser(
117                 getPath("InputJavadocRegexpIgnoreCaseTrue.java"), expected);
118     }
119 
120     @Test
121     public void testTextSplitAcrossLines() throws Exception {
122         final String format = "^first second";
123         final String[] expected = {
124             "16: " + getCheckMessage(MSG_JAVADOC_REGEXP, format),
125         };
126 
127         verifyWithInlineConfigParser(
128                 getPath("InputJavadocRegexpTextSplitAcrossLines.java"), expected);
129     }
130 
131 }