001: package org.incava.javadoc;
002:
003: import java.awt.Point;
004: import java.util.List;
005: import junit.framework.TestCase;
006:
007: public class TestJavadocParser extends TestCase {
008: public TestJavadocParser(String name) {
009: super (name);
010: }
011:
012: public static List parse(String text) {
013: JavadocParser jp = new JavadocParser();
014: return jp.parse(text);
015: }
016:
017: public void testBasic() {
018: String text = ("/** This is a description.\n" + " */\n"
019: + "class Test {\n" + " /**\n"
020: + " * This is a description. \n"
021: + " * @@throws IOException \n" + " */\n"
022: + " int f(int i) throws IOException { return 1; }\n"
023: + "}\n");
024: List segments = parse(text);
025:
026: assertNotNull("results", segments);
027: }
028:
029: public void testNone() {
030: String text = "";
031: List segments = parse(text);
032:
033: assertNull("results", segments);
034: }
035:
036: public void testNotJavadoc() {
037: String text = ("/* This is a description,\n"
038: + " * not in Javadoc format. */\n");
039: List segments = parse(text);
040:
041: assertNull("results", segments);
042: }
043:
044: public void testEmpty() {
045: List segments = null;
046:
047: segments = parse("/**/");
048: assertEquals("size of results", 0, segments.size());
049:
050: segments = parse("/** */");
051: assertEquals("size of results", 0, segments.size());
052:
053: segments = parse("/** */");
054: assertEquals("size of results", 0, segments.size());
055: }
056:
057: public void testDescribedSingleLine() {
058: String text = "/** This is a test. */";
059: List segments = parse(text);
060:
061: assertEquals("size of results", 1, segments.size());
062: assertEquals("description", (new Point(4, 19)),
063: (Point) segments.get(0));
064: assertEquals("description text", "This is a test.", text
065: .substring(4, 19));
066: }
067:
068: public void testDescribedSeparateLine() {
069: String text = "/** \n * This is a test. \n */";
070: List segments = parse(text);
071:
072: assertEquals("size of results", 1, segments.size());
073: assertEquals("description", (new Point(8, 23)),
074: (Point) segments.get(0));
075: assertEquals("description text", "This is a test.", text
076: .substring(8, 23));
077: }
078:
079: public void testDescribedMultiLineOnSeparateLine() {
080: String text = "/** \n * This is a test.\n * There are many like it,\n but this one is mine. \n */";
081: List segments = parse(text);
082:
083: assertEquals("size of results", 1, segments.size());
084: assertEquals("description", (new Point(8, 75)),
085: (Point) segments.get(0));
086: assertEquals(
087: "description text",
088: "This is a test.\n * There are many like it,\n but this one is mine.",
089: text.substring(8, 75));
090: }
091:
092: public void testDescribedOneTag() {
093: String text = "/** \n * This is a test.\n * @tag description. \n */";
094: List segments = parse(text);
095:
096: assertEquals("size of results", 2, segments.size());
097: assertEquals("description", (new Point(8, 23)),
098: (Point) segments.get(0));
099: assertEquals("description text", "This is a test.", text
100: .substring(8, 23));
101: assertEquals("tag text", "@tag description.", text.substring(
102: 27, 44));
103: }
104:
105: public void testUndescribedOneTag() {
106: String text = "/** \n * @tag description. \n */";
107: List segments = parse(text);
108:
109: assertEquals("size of results", 2, segments.size());
110: assertNull("no description", segments.get(0));
111: assertEquals("tag", (new Point(8, 25)), (Point) segments.get(1));
112: assertEquals("tag text", "@tag description.", text.substring(8,
113: 25));
114: }
115:
116: public void testDescribedTwoTags() {
117: String text = "/** \n * This is a test.\n * @tag0 description. \n * @tag1 Another description, \n * this one on multiple lines.\n */";
118: List segments = parse(text);
119:
120: assertEquals("size of results", 3, segments.size());
121: assertEquals("description", (new Point(8, 23)),
122: (Point) segments.get(0));
123: assertEquals("description text", "This is a test.", text
124: .substring(8, 23));
125: assertEquals("tag", (new Point(27, 46)), (Point) segments
126: .get(1));
127: assertEquals("tag text", "@tag0 description. ", text.substring(
128: 27, 46));
129: assertEquals("tag", (new Point(50, 108)), (Point) segments
130: .get(2));
131: assertEquals(
132: "tag text",
133: "@tag1 Another description, \n * this one on multiple lines.",
134: text.substring(50, 108));
135: }
136:
137: public void testDescribedTwoTagsEndCommentOnSameLine() {
138: String text = "/** \n * This is a test.\n * @tag0 description. \n * @tag1 Another description, \n * this one on multiple lines. */";
139: List segments = parse(text);
140:
141: assertEquals("size of results", 3, segments.size());
142: assertEquals("description", (new Point(8, 23)),
143: (Point) segments.get(0));
144: assertEquals("description text", "This is a test.", text
145: .substring(8, 23));
146: assertEquals("tag", (new Point(27, 46)), (Point) segments
147: .get(1));
148: assertEquals("tag text", "@tag0 description. ", text.substring(
149: 27, 46));
150: assertEquals("tag", (new Point(50, 108)), (Point) segments
151: .get(2));
152: assertEquals(
153: "tag text",
154: "@tag1 Another description, \n * this one on multiple lines.",
155: text.substring(50, 108));
156: }
157:
158: public void testDescribedPreBlock() {
159: String text = "/** \n" + " * This is a test.\n"
160: + " * And here is its pre block: \n" + " * <pre> \n"
161: + " * blah\n" + " * blah\n" + " * blah\n"
162: + " * </pre> \n" + " */";
163: List segments = parse(text);
164:
165: assertEquals("size of results", 1, segments.size());
166: assertEquals("description", (new Point(8, 110)),
167: (Point) segments.get(0));
168: assertEquals("description text", "This is a test.\n"
169: + " * And here is its pre block: \n" + " * <pre> \n"
170: + " * blah\n" + " * blah\n" + " * blah\n"
171: + " * </pre>", text.substring(8, 110));
172: }
173:
174: public void testLineStartsWithLink() {
175: String text = ("/**\n"
176: + " * This is a description that makes a reference to \n"
177: + " * {@link SomeWhere#someThing(someType)} which should not\n"
178: + " * be treated as a comment/tag start.\n" + " */\n");
179:
180: List segments = parse(text);
181:
182: assertEquals("size of results", 1, segments.size());
183: assertEquals("description", (new Point(7, 151)),
184: (Point) segments.get(0));
185: }
186: }
|