View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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.grammars.javadoc;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  import org.junit.Test;
25  
26  /**
27   * GeneratedJavadocTokenTypesTest.
28   * @noinspection ClassIndependentOfModule
29   */
30  public class GeneratedJavadocTokenTypesTest {
31  
32      private static final String MSG = "Ensure that token numbers generated for the elements"
33              + "present in JavadocParser are consistent with what the tests assert.";
34  
35      /**
36       * This method checks that the numbers generated for tokens in <tt>JavadocLexer.g4</tt> don't
37       * change with the lexer grammar itself.
38       * <br>ANTLR maps all the lexer elements to compile time constants used internally by ANTLR.
39       * Compatibility damage is incurred <i>(with respect to the previous checkstyle versions)
40       * </i> if these compile time constants keep changing with the grammar.
41       *
42       * @see "https://github.com/checkstyle/checkstyle/issues/5139"
43       * @see "https://github.com/checkstyle/checkstyle/issues/5186"
44       */
45      @Test
46      public void testTokenNumbers() {
47          assertEquals(MSG, 1, JavadocParser.LEADING_ASTERISK);
48          assertEquals(MSG, 2, JavadocParser.HTML_COMMENT_START);
49          assertEquals(MSG, 3, JavadocParser.CDATA);
50          assertEquals(MSG, 4, JavadocParser.WS);
51          assertEquals(MSG, 5, JavadocParser.START);
52          assertEquals(MSG, 6, JavadocParser.NEWLINE);
53          assertEquals(MSG, 7, JavadocParser.AUTHOR_LITERAL);
54          assertEquals(MSG, 8, JavadocParser.DEPRECATED_LITERAL);
55          assertEquals(MSG, 9, JavadocParser.EXCEPTION_LITERAL);
56          assertEquals(MSG, 10, JavadocParser.PARAM_LITERAL);
57          assertEquals(MSG, 11, JavadocParser.RETURN_LITERAL);
58          assertEquals(MSG, 12, JavadocParser.SEE_LITERAL);
59          assertEquals(MSG, 13, JavadocParser.SERIAL_LITERAL);
60          assertEquals(MSG, 14, JavadocParser.SERIAL_FIELD_LITERAL);
61          assertEquals(MSG, 15, JavadocParser.SERIAL_DATA_LITERAL);
62          assertEquals(MSG, 16, JavadocParser.SINCE_LITERAL);
63          assertEquals(MSG, 17, JavadocParser.THROWS_LITERAL);
64          assertEquals(MSG, 18, JavadocParser.VERSION_LITERAL);
65          assertEquals(MSG, 19, JavadocParser.JAVADOC_INLINE_TAG_START);
66          assertEquals(MSG, 20, JavadocParser.JAVADOC_INLINE_TAG_END);
67          assertEquals(MSG, 21, JavadocParser.CUSTOM_NAME);
68          assertEquals(MSG, 22, JavadocParser.LITERAL_INCLUDE);
69          assertEquals(MSG, 23, JavadocParser.LITERAL_EXCLUDE);
70          assertEquals(MSG, 24, JavadocParser.CHAR);
71          assertEquals(MSG, 25, JavadocParser.PARAMETER_NAME);
72          assertEquals(MSG, 26, JavadocParser.Char1);
73          assertEquals(MSG, 27, JavadocParser.STRING);
74          assertEquals(MSG, 28, JavadocParser.PACKAGE_CLASS);
75          assertEquals(MSG, 29, JavadocParser.DOT);
76          assertEquals(MSG, 30, JavadocParser.HASH);
77          assertEquals(MSG, 31, JavadocParser.CLASS);
78          assertEquals(MSG, 32, JavadocParser.Char2);
79          assertEquals(MSG, 33, JavadocParser.MEMBER);
80          assertEquals(MSG, 34, JavadocParser.LEFT_BRACE);
81          assertEquals(MSG, 35, JavadocParser.RIGHT_BRACE);
82          assertEquals(MSG, 36, JavadocParser.ARGUMENT);
83          assertEquals(MSG, 37, JavadocParser.COMMA);
84          assertEquals(MSG, 38, JavadocParser.Char20);
85          assertEquals(MSG, 39, JavadocParser.FIELD_NAME);
86          assertEquals(MSG, 40, JavadocParser.Char3);
87          assertEquals(MSG, 41, JavadocParser.FIELD_TYPE);
88          assertEquals(MSG, 42, JavadocParser.Char4);
89          assertEquals(MSG, 43, JavadocParser.CLASS_NAME);
90          assertEquals(MSG, 44, JavadocParser.Char5);
91          assertEquals(MSG, 45, JavadocParser.CODE_LITERAL);
92          assertEquals(MSG, 46, JavadocParser.DOC_ROOT_LITERAL);
93          assertEquals(MSG, 47, JavadocParser.INHERIT_DOC_LITERAL);
94          assertEquals(MSG, 48, JavadocParser.LINK_LITERAL);
95          assertEquals(MSG, 49, JavadocParser.LINKPLAIN_LITERAL);
96          assertEquals(MSG, 50, JavadocParser.LITERAL_LITERAL);
97          assertEquals(MSG, 51, JavadocParser.VALUE_LITERAL);
98          assertEquals(MSG, 52, JavadocParser.Char7);
99          assertEquals(MSG, 53, JavadocParser.Char8);
100         assertEquals(MSG, 54, JavadocParser.Char10);
101         assertEquals(MSG, 55, JavadocParser.END);
102         assertEquals(MSG, 56, JavadocParser.SLASH_END);
103         assertEquals(MSG, 57, JavadocParser.SLASH);
104         assertEquals(MSG, 58, JavadocParser.EQUALS);
105         assertEquals(MSG, 59, JavadocParser.P_HTML_TAG_NAME);
106         assertEquals(MSG, 60, JavadocParser.LI_HTML_TAG_NAME);
107         assertEquals(MSG, 61, JavadocParser.TR_HTML_TAG_NAME);
108         assertEquals(MSG, 62, JavadocParser.TD_HTML_TAG_NAME);
109         assertEquals(MSG, 63, JavadocParser.TH_HTML_TAG_NAME);
110         assertEquals(MSG, 64, JavadocParser.BODY_HTML_TAG_NAME);
111         assertEquals(MSG, 65, JavadocParser.COLGROUP_HTML_TAG_NAME);
112         assertEquals(MSG, 66, JavadocParser.DD_HTML_TAG_NAME);
113         assertEquals(MSG, 67, JavadocParser.DT_HTML_TAG_NAME);
114         assertEquals(MSG, 68, JavadocParser.HEAD_HTML_TAG_NAME);
115         assertEquals(MSG, 69, JavadocParser.HTML_HTML_TAG_NAME);
116         assertEquals(MSG, 70, JavadocParser.OPTION_HTML_TAG_NAME);
117         assertEquals(MSG, 71, JavadocParser.TBODY_HTML_TAG_NAME);
118         assertEquals(MSG, 72, JavadocParser.TFOOT_HTML_TAG_NAME);
119         assertEquals(MSG, 73, JavadocParser.THEAD_HTML_TAG_NAME);
120         assertEquals(MSG, 74, JavadocParser.AREA_HTML_TAG_NAME);
121         assertEquals(MSG, 75, JavadocParser.BASE_HTML_TAG_NAME);
122         assertEquals(MSG, 76, JavadocParser.BASEFONT_HTML_TAG_NAME);
123         assertEquals(MSG, 77, JavadocParser.BR_HTML_TAG_NAME);
124         assertEquals(MSG, 78, JavadocParser.COL_HTML_TAG_NAME);
125         assertEquals(MSG, 79, JavadocParser.FRAME_HTML_TAG_NAME);
126         assertEquals(MSG, 80, JavadocParser.HR_HTML_TAG_NAME);
127         assertEquals(MSG, 81, JavadocParser.IMG_HTML_TAG_NAME);
128         assertEquals(MSG, 82, JavadocParser.INPUT_HTML_TAG_NAME);
129         assertEquals(MSG, 83, JavadocParser.ISINDEX_HTML_TAG_NAME);
130         assertEquals(MSG, 84, JavadocParser.LINK_HTML_TAG_NAME);
131         assertEquals(MSG, 85, JavadocParser.META_HTML_TAG_NAME);
132         assertEquals(MSG, 86, JavadocParser.PARAM_HTML_TAG_NAME);
133         assertEquals(MSG, 87, JavadocParser.EMBED_HTML_TAG_NAME);
134         assertEquals(MSG, 88, JavadocParser.KEYGEN_HTML_TAG_NAME);
135         assertEquals(MSG, 92, JavadocParser.SOURCE_HTML_TAG_NAME);
136         assertEquals(MSG, 93, JavadocParser.TRACK_HTML_TAG_NAME);
137         assertEquals(MSG, 94, JavadocParser.WBR_HTML_TAG_NAME);
138         assertEquals(MSG, 95, JavadocParser.HTML_TAG_NAME);
139         assertEquals(MSG, 96, JavadocParser.Char11);
140         assertEquals(MSG, 89, JavadocParser.ATTR_VALUE);
141         assertEquals(MSG, 90, JavadocParser.Char12);
142         assertEquals(MSG, 91, JavadocParser.HTML_COMMENT_END);
143     }
144 
145     /**
146      * This method checks that the numbers generated for rules in <tt>JavadocParser.g4</tt> don't
147      * change with the Parser grammar itself.
148      * <br>ANTLR maps all the parser rules to compile time constants used internally by ANTLR.
149      * Compatibility damage is incurred <i>(with respect to the previous checkstyle versions)
150      * </i> if these compile time constants keep changing with the grammar.
151      *
152      * @see "https://github.com/checkstyle/checkstyle/issues/5139"
153      * @see "https://github.com/checkstyle/checkstyle/issues/5186"
154      */
155     @Test
156     public void testRuleNumbers() {
157         assertEquals(MSG, 0, JavadocParser.RULE_javadoc);
158         assertEquals(MSG, 1, JavadocParser.RULE_htmlElement);
159         assertEquals(MSG, 2, JavadocParser.RULE_htmlElementStart);
160         assertEquals(MSG, 3, JavadocParser.RULE_htmlElementEnd);
161         assertEquals(MSG, 4, JavadocParser.RULE_attribute);
162         assertEquals(MSG, 5, JavadocParser.RULE_htmlTag);
163         assertEquals(MSG, 6, JavadocParser.RULE_pTagStart);
164         assertEquals(MSG, 7, JavadocParser.RULE_pTagEnd);
165         assertEquals(MSG, 8, JavadocParser.RULE_paragraph);
166         assertEquals(MSG, 9, JavadocParser.RULE_liTagStart);
167         assertEquals(MSG, 10, JavadocParser.RULE_liTagEnd);
168         assertEquals(MSG, 11, JavadocParser.RULE_li);
169         assertEquals(MSG, 12, JavadocParser.RULE_trTagStart);
170         assertEquals(MSG, 13, JavadocParser.RULE_trTagEnd);
171         assertEquals(MSG, 14, JavadocParser.RULE_tr);
172         assertEquals(MSG, 15, JavadocParser.RULE_tdTagStart);
173         assertEquals(MSG, 16, JavadocParser.RULE_tdTagEnd);
174         assertEquals(MSG, 17, JavadocParser.RULE_td);
175         assertEquals(MSG, 18, JavadocParser.RULE_thTagStart);
176         assertEquals(MSG, 19, JavadocParser.RULE_thTagEnd);
177         assertEquals(MSG, 20, JavadocParser.RULE_th);
178         assertEquals(MSG, 21, JavadocParser.RULE_bodyTagStart);
179         assertEquals(MSG, 22, JavadocParser.RULE_bodyTagEnd);
180         assertEquals(MSG, 23, JavadocParser.RULE_body);
181         assertEquals(MSG, 24, JavadocParser.RULE_colgroupTagStart);
182         assertEquals(MSG, 25, JavadocParser.RULE_colgroupTagEnd);
183         assertEquals(MSG, 26, JavadocParser.RULE_colgroup);
184         assertEquals(MSG, 27, JavadocParser.RULE_ddTagStart);
185         assertEquals(MSG, 28, JavadocParser.RULE_ddTagEnd);
186         assertEquals(MSG, 29, JavadocParser.RULE_dd);
187         assertEquals(MSG, 30, JavadocParser.RULE_dtTagStart);
188         assertEquals(MSG, 31, JavadocParser.RULE_dtTagEnd);
189         assertEquals(MSG, 32, JavadocParser.RULE_dt);
190         assertEquals(MSG, 33, JavadocParser.RULE_headTagStart);
191         assertEquals(MSG, 34, JavadocParser.RULE_headTagEnd);
192         assertEquals(MSG, 35, JavadocParser.RULE_head);
193         assertEquals(MSG, 36, JavadocParser.RULE_htmlTagStart);
194         assertEquals(MSG, 37, JavadocParser.RULE_htmlTagEnd);
195         assertEquals(MSG, 38, JavadocParser.RULE_html);
196         assertEquals(MSG, 39, JavadocParser.RULE_optionTagStart);
197         assertEquals(MSG, 40, JavadocParser.RULE_optionTagEnd);
198         assertEquals(MSG, 41, JavadocParser.RULE_option);
199         assertEquals(MSG, 42, JavadocParser.RULE_tbodyTagStart);
200         assertEquals(MSG, 43, JavadocParser.RULE_tbodyTagEnd);
201         assertEquals(MSG, 44, JavadocParser.RULE_tbody);
202         assertEquals(MSG, 45, JavadocParser.RULE_tfootTagStart);
203         assertEquals(MSG, 46, JavadocParser.RULE_tfootTagEnd);
204         assertEquals(MSG, 47, JavadocParser.RULE_tfoot);
205         assertEquals(MSG, 48, JavadocParser.RULE_theadTagStart);
206         assertEquals(MSG, 49, JavadocParser.RULE_theadTagEnd);
207         assertEquals(MSG, 50, JavadocParser.RULE_thead);
208         assertEquals(MSG, 51, JavadocParser.RULE_singletonElement);
209         assertEquals(MSG, 52, JavadocParser.RULE_emptyTag);
210         assertEquals(MSG, 53, JavadocParser.RULE_areaTag);
211         assertEquals(MSG, 54, JavadocParser.RULE_baseTag);
212         assertEquals(MSG, 55, JavadocParser.RULE_basefontTag);
213         assertEquals(MSG, 56, JavadocParser.RULE_brTag);
214         assertEquals(MSG, 57, JavadocParser.RULE_colTag);
215         assertEquals(MSG, 58, JavadocParser.RULE_frameTag);
216         assertEquals(MSG, 59, JavadocParser.RULE_hrTag);
217         assertEquals(MSG, 60, JavadocParser.RULE_imgTag);
218         assertEquals(MSG, 61, JavadocParser.RULE_inputTag);
219         assertEquals(MSG, 62, JavadocParser.RULE_isindexTag);
220         assertEquals(MSG, 63, JavadocParser.RULE_linkTag);
221         assertEquals(MSG, 64, JavadocParser.RULE_metaTag);
222         assertEquals(MSG, 65, JavadocParser.RULE_paramTag);
223         assertEquals(MSG, 66, JavadocParser.RULE_wrongSinletonTag);
224         assertEquals(MSG, 67, JavadocParser.RULE_singletonTagName);
225         assertEquals(MSG, 68, JavadocParser.RULE_description);
226         assertEquals(MSG, 69, JavadocParser.RULE_reference);
227         assertEquals(MSG, 70, JavadocParser.RULE_parameters);
228         assertEquals(MSG, 71, JavadocParser.RULE_javadocTag);
229         assertEquals(MSG, 72, JavadocParser.RULE_javadocInlineTag);
230         assertEquals(MSG, 73, JavadocParser.RULE_htmlComment);
231         assertEquals(MSG, 74, JavadocParser.RULE_text);
232         assertEquals(MSG, 75, JavadocParser.RULE_embedTag);
233         assertEquals(MSG, 76, JavadocParser.RULE_keygenTag);
234         assertEquals(MSG, 77, JavadocParser.RULE_sourceTag);
235         assertEquals(MSG, 78, JavadocParser.RULE_trackTag);
236         assertEquals(MSG, 79, JavadocParser.RULE_wbrTag);
237     }
238 }