KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > javadoc > TestJavadocTaggedNode


1 package org.incava.javadoc;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6 import org.incava.text.Location;
7
8
9 public class TestJavadocTaggedNode extends TestCase
10 {
11     public TestJavadocTaggedNode(String JavaDoc name)
12     {
13         super(name);
14     }
15
16     public void testTagOnly()
17     {
18         String JavaDoc text = "@tag";
19
20         // starts at line 11, column 4:
21
Location start = new Location(11, 4);
22         Location end = new Location(11, 4 + text.length() - 1);
23         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
24
25         assertNotNull("javadoc tagged node", jtn);
26         assertEquals("javadoc tagged comment description text", "@tag", jtn.text);
27         assertEquals("javadoc tagged comment start location", new Location(11, 4), jtn.start);
28         assertEquals("javadoc tagged comment end location", new Location(11, 7), jtn.end);
29         
30         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
31         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
32         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 4), jtn.getTag().start);
33         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 7), jtn.getTag().end);
34
35         assertNull("javadoc tagged comment #0 description", jtn.getDescription());
36     }
37
38     public void testTagNoFollowingText()
39     {
40         String JavaDoc text = "@tag ";
41
42         // starts at line 11, column 4:
43
Location start = new Location(11, 4);
44         Location end = new Location(11, 4 + text.length() - 1);
45         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
46
47         assertNotNull("javadoc tagged node", jtn);
48         assertEquals("javadoc tagged comment description text", "@tag ", jtn.text);
49         assertEquals("javadoc tagged comment start location", new Location(11, 4), jtn.start);
50         assertEquals("javadoc tagged comment end location", new Location(11, 8), jtn.end);
51         
52         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
53         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
54         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 4), jtn.getTag().start);
55         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 7), jtn.getTag().end);
56
57         assertNull("javadoc tagged comment #0 description", jtn.getDescription());
58     }
59
60     public void testOneLetter()
61     {
62         String JavaDoc text = "@tag X";
63
64         // starts at line 11, column 4:
65
Location start = new Location(11, 4);
66         Location end = new Location(11, 4 + text.length() - 1);
67         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
68
69         assertNotNull("javadoc tagged node", jtn);
70         assertEquals("javadoc tagged comment description text", "@tag X", jtn.text);
71         assertEquals("javadoc tagged comment start location", new Location(11, 4), jtn.start);
72         assertEquals("javadoc tagged comment end location", new Location(11, 9), jtn.end);
73         
74         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
75         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
76         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 4), jtn.getTag().start);
77         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 7), jtn.getTag().end);
78
79         assertNotNull("javadoc tagged comment #0 description", jtn.getDescription());
80         assertEquals("javadoc tagged comment #0 description text", "X", jtn.getDescription().text);
81         assertEquals("javadoc tagged comment #0 description start location", new Location(11, 9), jtn.getDescription().start);
82         assertEquals("javadoc tagged comment #0 description end location", new Location(11, 9), jtn.getDescription().end);
83     }
84
85     public void testOneLine()
86     {
87         String JavaDoc text = "@tag And that's a tag.";
88
89         // starts at line 11, column 4:
90
Location start = new Location(11, 4);
91         Location end = new Location(11, 4 + text.length() - 1);
92         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
93
94         assertNotNull("javadoc tagged node", jtn);
95         assertEquals("javadoc tagged comment description text", "@tag And that's a tag.", jtn.text);
96         assertEquals("javadoc tagged comment start location", new Location(11, 4), jtn.start);
97         assertEquals("javadoc tagged comment end location", new Location(11, 25), jtn.end);
98         
99         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
100         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
101         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 4), jtn.getTag().start);
102         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 7), jtn.getTag().end);
103     }
104
105     public void testOneWord()
106     {
107         String JavaDoc text = "@tag And";
108
109         // starts at line 11, column 4:
110
Location start = new Location(11, 4);
111         Location end = new Location(11, 4 + text.length() - 1);
112         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
113
114         assertNotNull("javadoc tagged node", jtn);
115         assertEquals("javadoc tagged comment description text", "@tag And", jtn.text);
116         assertEquals("javadoc tagged comment start location", new Location(11, 4), jtn.start);
117         assertEquals("javadoc tagged comment end location", new Location(11, 11), jtn.end);
118         
119         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
120         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
121         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 4), jtn.getTag().start);
122         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 7), jtn.getTag().end);
123
124         assertNotNull("javadoc tagged comment #0 description", jtn.getDescription());
125         assertEquals("javadoc tagged comment #0 description text", "And", jtn.getDescription().text);
126         assertEquals("javadoc tagged comment #0 description start location", new Location(11, 9), jtn.getDescription().start);
127         assertEquals("javadoc tagged comment #0 description end location", new Location(11, 11), jtn.getDescription().end);
128     }
129
130     public void testWordTarget()
131     {
132         String JavaDoc text = "@tag And that's a tag.";
133
134         // starts at line 11, column 8:
135
Location start = new Location(11, 8);
136         Location end = new Location(11, 8 + text.length() - 1);
137         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
138
139         assertNotNull("javadoc tagged node", jtn);
140         assertEquals("javadoc tagged comment description text", "@tag And that's a tag.", jtn.text);
141         assertEquals("javadoc tagged comment start location", new Location(11, 8), jtn.start);
142         assertEquals("javadoc tagged comment end location", new Location(11, 29), jtn.end);
143
144         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
145         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
146         assertEquals("javadoc tagged comment #0 tag start location", new Location(11, 8), jtn.getTag().start);
147         assertEquals("javadoc tagged comment #0 tag end location", new Location(11, 11), jtn.getTag().end);
148
149         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
150         assertEquals("javadoc tagged comment #0 target text", "And", jtn.getTarget().text);
151         assertEquals("javadoc tagged comment #0 target start location", new Location(11, 13), jtn.getTarget().start);
152         assertEquals("javadoc tagged comment #0 target end location", new Location(11, 15), jtn.getTarget().end);
153     }
154
155     public void testHTMLTarget()
156     {
157         String JavaDoc text = "@tag <a HREF=\"www.somewhere.tld/something/something\">this</a> See that thing for more.";
158
159         // starts at line 11, column 8:
160
Location start = new Location(8, 3);
161         Location end = new Location(8, 3 + text.length() - 1);
162         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
163
164         assertNotNull("javadoc tagged node", jtn);
165         assertEquals("javadoc tagged comment description text", text, jtn.text);
166         assertEquals("javadoc tagged comment start location", new Location(8, 3), jtn.start);
167         assertEquals("javadoc tagged comment end location", new Location(8, 88), jtn.end);
168
169         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
170         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
171         assertEquals("javadoc tagged comment #0 tag start location", new Location(8, 3), jtn.getTag().start);
172         assertEquals("javadoc tagged comment #0 tag end location", new Location(8, 6), jtn.getTag().end);
173
174         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
175         assertEquals("javadoc tagged comment #0 target text", "<a HREF=\"www.somewhere.tld/something/something\">this</a>", jtn.getTarget().text);
176         assertEquals("javadoc tagged comment #0 target start location", new Location(8, 8), jtn.getTarget().start);
177         assertEquals("javadoc tagged comment #0 target end location", new Location(8, 63), jtn.getTarget().end);
178
179         assertNotNull("javadoc tagged comment #0 nontarget desc", jtn.getDescriptionNonTarget());
180         assertEquals("javadoc tagged comment #0 nontarget desc text", "See that thing for more.", jtn.getDescriptionNonTarget().text);
181         assertEquals("javadoc tagged comment #0 nontarget desc start location", new Location(8, 65), jtn.getDescriptionNonTarget().start);
182         assertEquals("javadoc tagged comment #0 nontarget desc end location", new Location(8, 88), jtn.getDescriptionNonTarget().end);
183     }
184
185     public void testHTMLTargetUppercase()
186     {
187         String JavaDoc text = "@tag <A HREF=\"www.somewhere.tld/something/something\">this</A> See that thing for more.";
188
189         // starts at line 11, column 8:
190
Location start = new Location(8, 3);
191         Location end = new Location(8, 3 + text.length() - 1);
192         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
193
194         assertNotNull("javadoc tagged node", jtn);
195         assertEquals("javadoc tagged comment description text", text, jtn.text);
196         assertEquals("javadoc tagged comment start location", new Location(8, 3), jtn.start);
197         assertEquals("javadoc tagged comment end location", new Location(8, 88), jtn.end);
198
199         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
200         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
201         assertEquals("javadoc tagged comment #0 tag start location", new Location(8, 3), jtn.getTag().start);
202         assertEquals("javadoc tagged comment #0 tag end location", new Location(8, 6), jtn.getTag().end);
203
204         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
205         assertEquals("javadoc tagged comment #0 target text", "<A HREF=\"www.somewhere.tld/something/something\">this</A>", jtn.getTarget().text);
206         assertEquals("javadoc tagged comment #0 target start location", new Location(8, 8), jtn.getTarget().start);
207         assertEquals("javadoc tagged comment #0 target end location", new Location(8, 63), jtn.getTarget().end);
208     }
209
210     public void testHTMLTargetNoEnd()
211     {
212         String JavaDoc text = "@tag <A HREF=\"www.somewhere.tld/something/something\">this";
213
214         // starts at line 11, column 8:
215
Location start = new Location(8, 3);
216         Location end = new Location(8, 3 + text.length() - 1);
217         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
218
219         assertNotNull("javadoc tagged node", jtn);
220         assertEquals("javadoc tagged comment description text", text, jtn.text);
221         assertEquals("javadoc tagged comment start location", new Location(8, 3), jtn.start);
222         assertEquals("javadoc tagged comment end location", new Location(8, 59), jtn.end);
223
224         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
225         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
226         assertEquals("javadoc tagged comment #0 tag start location", new Location(8, 3), jtn.getTag().start);
227         assertEquals("javadoc tagged comment #0 tag end location", new Location(8, 6), jtn.getTag().end);
228
229         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
230         assertEquals("javadoc tagged comment #0 target text", "<A HREF=\"www.somewhere.tld/something/something\">this", jtn.getTarget().text);
231         assertEquals("javadoc tagged comment #0 target start location", new Location(8, 8), jtn.getTarget().start);
232         assertEquals("javadoc tagged comment #0 target end location", new Location(8, 59), jtn.getTarget().end);
233     }
234
235     public void testQuotedTarget()
236     {
237         String JavaDoc text = "@tag Something#foo(int, double, float)";
238
239         // starts at line 11, column 8:
240
Location start = new Location(8, 3);
241         Location end = new Location(8, 3 + text.length() - 1);
242         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
243
244         assertNotNull("javadoc tagged node", jtn);
245         assertEquals("javadoc tagged comment description text", text, jtn.text);
246         assertEquals("javadoc tagged comment start location", start, jtn.start);
247         assertEquals("javadoc tagged comment end location", end, jtn.end);
248
249         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
250         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
251         assertEquals("javadoc tagged comment #0 tag start location", start, jtn.getTag().start);
252         assertEquals("javadoc tagged comment #0 tag end location", new Location(start.line, start.column + 3), jtn.getTag().end);
253
254         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
255         assertEquals("javadoc tagged comment #0 target text", "Something#foo(int, double, float)", jtn.getTarget().text);
256         assertEquals("javadoc tagged comment #0 target start location", new Location(start.line, start.column + 5), jtn.getTarget().start);
257         assertEquals("javadoc tagged comment #0 target end location", new Location(start.line, start.column + 5 + 32), jtn.getTarget().end);
258     }
259
260     public void testQuotedTargetNoEnd()
261     {
262         String JavaDoc text = "@tag Something#foo(int, double";
263
264         // starts at line 11, column 8:
265
Location start = new Location(8, 3);
266         Location end = new Location(8, 3 + text.length() - 1);
267         JavadocTaggedNode jtn = new JavadocTaggedNode(text, start, end);
268
269         assertNotNull("javadoc tagged node", jtn);
270         assertEquals("javadoc tagged comment description text", text, jtn.text);
271         assertEquals("javadoc tagged comment start location", start, jtn.start);
272         assertEquals("javadoc tagged comment end location", end, jtn.end);
273
274         assertNotNull("javadoc tagged comment #0 tag", jtn.getTag());
275         assertEquals("javadoc tagged comment #0 tag text", "@tag", jtn.getTag().text);
276         assertEquals("javadoc tagged comment #0 tag start location", start, jtn.getTag().start);
277         assertEquals("javadoc tagged comment #0 tag end location", new Location(start.line, start.column + 3), jtn.getTag().end);
278
279         assertNotNull("javadoc tagged comment #0 target", jtn.getTarget());
280         assertEquals("javadoc tagged comment #0 target text", "Something#foo(int, double", jtn.getTarget().text);
281         assertEquals("javadoc tagged comment #0 target start location", new Location(start.line, start.column + 5), jtn.getTarget().start);
282         assertEquals("javadoc tagged comment #0 target end location", new Location(start.line, start.column + 5 + 24), jtn.getTarget().end);
283     }
284
285 }
286
Popular Tags