001: package org.incava.javadoc;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006: import org.incava.text.Location;
007:
008: public class TestJavadocNode extends TestCase {
009: public TestJavadocNode(String name) {
010: super (name);
011: }
012:
013: public void testNone() {
014: String text = "";
015: JavadocNode jd = JavadocNode.parse(text, 1, 1);
016:
017: assertNull("no javadoc node for empty string", jd);
018: }
019:
020: public void testEmpty() {
021: JavadocNode jd;
022:
023: jd = JavadocNode.parse("/**/", 1, 1);
024: assertNotNull("javadoc node for empty javadoc comment", jd);
025: assertNull("javadoc description", jd.getDescription());
026: assertEquals("javadoc tagged comments", 0, jd
027: .getTaggedComments().length);
028:
029: jd = JavadocNode.parse("/** */", 1, 1);
030: assertNotNull(
031: "javadoc node for javadoc comment with one space", jd);
032: assertNull("javadoc description", jd.getDescription());
033: assertEquals("javadoc tagged comments", 0, jd
034: .getTaggedComments().length);
035:
036: jd = JavadocNode.parse("/** */", 1, 1);
037: assertNotNull(
038: "javadoc node for javadoc comment with multiple spaces",
039: jd);
040: assertNull("javadoc description", jd.getDescription());
041: assertEquals("javadoc tagged comments", 0, jd
042: .getTaggedComments().length);
043: }
044:
045: public void testDescribedSingleLine() {
046: String text = "/** This is a test. */";
047:
048: // starts at line 5, column 1:
049: JavadocNode jd = JavadocNode.parse(text, 5, 1);
050:
051: assertNotNull("javadoc node", jd);
052:
053: JavadocDescriptionNode desc = jd.getDescription();
054: assertNotNull("javadoc description", desc);
055: assertEquals("javadoc description text", "This is a test.",
056: desc.description);
057: assertEquals("javadoc start location", new Location(5, 5),
058: desc.start);
059: assertEquals("javadoc end location", new Location(5, 20),
060: desc.end);
061:
062: assertEquals("javadoc tagged comments", 0, jd
063: .getTaggedComments().length);
064: }
065:
066: public void testDescribedSeparateLine() {
067: String text = ("/** \n" + " * This is a test. \n" + " */");
068:
069: // starts at line 5, column 1:
070: JavadocNode jd = JavadocNode.parse(text, 5, 1);
071:
072: assertNotNull("javadoc node", jd);
073:
074: JavadocDescriptionNode desc = jd.getDescription();
075: assertNotNull("javadoc description", desc);
076: assertEquals("javadoc description text", "This is a test.",
077: desc.description);
078: assertEquals("javadoc start location", new Location(6, 4),
079: desc.start);
080: assertEquals("javadoc end location", new Location(6, 19),
081: desc.end);
082:
083: assertEquals("javadoc tagged comments", 0, jd
084: .getTaggedComments().length);
085: }
086:
087: public void testDescribedOneTagLine() {
088: String text = ("/** \n" + " * This is a test. \n"
089: + " * @tag And that's a tag.\n" + " */");
090:
091: // starts at line 5, column 1:
092: JavadocNode jd = JavadocNode.parse(text, 5, 1);
093:
094: assertNotNull("javadoc node", jd);
095:
096: JavadocDescriptionNode desc = jd.getDescription();
097: assertNotNull("javadoc description", desc);
098: assertEquals("javadoc description text", "This is a test. ",
099: desc.description);
100: assertEquals("javadoc start location", new Location(6, 4),
101: desc.start);
102: assertEquals("javadoc end location", new Location(6, 20),
103: desc.end);
104:
105: JavadocTaggedNode[] jtcs = jd.getTaggedComments();
106: assertEquals("javadoc tagged comments", 1, jtcs.length);
107: assertNotNull("javadoc tagged comment #0", jtcs[0]);
108: assertEquals("javadoc tagged comment description text",
109: "@tag And that's a tag.", jtcs[0].text);
110: assertEquals("javadoc tagged comment start location",
111: new Location(7, 4), jtcs[0].start);
112: assertEquals("javadoc tagged comment end location",
113: new Location(7, 26), jtcs[0].end);
114: assertNotNull("javadoc tagged comment #0 tag", jtcs[0].getTag());
115: assertEquals("javadoc tagged comment #0 tag text", "@tag",
116: jtcs[0].getTag().text);
117: assertEquals("javadoc tagged comment #0 tag start location",
118: new Location(7, 4), jtcs[0].getTag().start);
119: assertEquals("javadoc tagged comment #0 tag end location",
120: new Location(7, 7), jtcs[0].getTag().end);
121: }
122:
123: public void testDescribedTwoTagsMultiLines() {
124: String text = ("/** \n" + " * This is a test. \n"
125: + " * @tag0 And that's a tag,\n"
126: + " * which is described on multiple lines.\n"
127: + " * \n" + " * @tag1 And that's another tag,\n"
128: + " * also described on multiple lines.\n" + " */");
129:
130: // starts at line 5, column 1:
131: JavadocNode jd = JavadocNode.parse(text, 5, 1);
132:
133: assertNotNull("javadoc node", jd);
134:
135: JavadocDescriptionNode desc = jd.getDescription();
136: assertNotNull("javadoc description", desc);
137: assertEquals("javadoc description text", "This is a test. ",
138: desc.description);
139: assertEquals("javadoc start location", new Location(6, 4),
140: desc.start);
141: assertEquals("javadoc end location", new Location(6, 20),
142: desc.end);
143:
144: JavadocTaggedNode[] jtcs = jd.getTaggedComments();
145: assertEquals("javadoc tagged comments", 2, jtcs.length);
146:
147: assertNotNull("javadoc tagged comment #0", jtcs[0]);
148: assertEquals(
149: "javadoc tagged comment description text",
150: "@tag0 And that's a tag,\n * which is described on multiple lines.",
151: jtcs[0].text);
152: assertEquals("javadoc tagged comment start location",
153: new Location(7, 4), jtcs[0].start);
154: assertEquals("javadoc tagged comment end location",
155: new Location(8, 41), jtcs[0].end);
156:
157: assertNotNull("javadoc tagged comment #0 tag", jtcs[0].getTag());
158: assertEquals("javadoc tagged comment #0 tag text", "@tag0",
159: jtcs[0].getTag().text);
160: assertEquals("javadoc tagged comment #0 tag start location",
161: new Location(7, 4), jtcs[0].getTag().start);
162: assertEquals("javadoc tagged comment #0 tag end location",
163: new Location(7, 8), jtcs[0].getTag().end);
164:
165: assertNotNull("javadoc tagged comment #0 target", jtcs[0]
166: .getTarget());
167: assertEquals("javadoc tagged comment #0 target text", "And",
168: jtcs[0].getTarget().text);
169: assertEquals("javadoc tagged comment #0 target start location",
170: new Location(7, 10), jtcs[0].getTarget().start);
171: assertEquals("javadoc tagged comment #0 target end location",
172: new Location(7, 12), jtcs[0].getTarget().end);
173:
174: assertNotNull("javadoc tagged comment #1 tag", jtcs[1].getTag());
175: assertEquals("javadoc tagged comment #1 tag text", "@tag1",
176: jtcs[1].getTag().text);
177: assertEquals("javadoc tagged comment #1 tag start location",
178: new Location(10, 4), jtcs[1].getTag().start);
179: assertEquals("javadoc tagged comment #1 tag end location",
180: new Location(10, 8), jtcs[1].getTag().end);
181:
182: assertNotNull("javadoc tagged comment #1 target", jtcs[1]
183: .getTarget());
184: assertEquals("javadoc tagged comment #1 target text", "And",
185: jtcs[1].getTarget().text);
186: assertEquals("javadoc tagged comment #1 target start location",
187: new Location(10, 10), jtcs[1].getTarget().start);
188: assertEquals("javadoc tagged comment #1 target end location",
189: new Location(10, 12), jtcs[1].getTarget().end);
190: }
191:
192: }
|