001: package org.incava.analysis;
002:
003: import java.io.*;
004: import java.util.*;
005: import junit.framework.TestCase;
006: import org.incava.qualog.ANSIColor;
007:
008: public class TestContextReport extends TestCase {
009: private final static String EOLN = System
010: .getProperty("line.separator");
011:
012: public TestContextReport(String name) {
013: super (name);
014: }
015:
016: public void testReportOrder() {
017: StringWriter sw;
018: Report r;
019:
020: String content = ("As fast as thou shalt wane, so fast thou grow'st\n"
021: + "In one of thine, from that which thou departest;\n"
022: + "And that fresh blood which youngly thou bestow'st,\r\n"
023: + "Thou mayst call thine when thou from youth convertest.\n"
024: + "Herein lives wisdom, beauty, and increase;\n"
025: + "Without this folly, age, and cold decay:\r"
026: + "If all were minded so, the times should cease\r"
027: + "And threescore year would make the world away.\n"
028: + "Let those whom nature hath not made for store,\n"
029: + "Harsh, featureless, and rude, barrenly perish:\n"
030: + "Look whom she best endow'd, she gave the more;\n"
031: + "Which bounteous gift thou shouldst in bounty cherish:\n"
032: + "She carv'd thee for her seal, and meant thereby,\n"
033: + "Thou shouldst print more, not let that copy die.\n");
034:
035: sw = new StringWriter();
036: r = new ContextReport(sw, content);
037:
038: r.addViolation(new Violation("msg", 3, 5, 4, 6));
039: r.addViolation(new Violation("msg2", 5, 3, 6, 4));
040: assertEquals(2, r.getViolations().size());
041: r.flush();
042:
043: String str0 = sw.toString();
044: tr.Ace.log("str0: " + str0);
045:
046: sw = new StringWriter();
047: r = new ContextReport(sw, content);
048: r.addViolation(new Violation("msg2", 5, 3, 6, 4));
049: r.addViolation(new Violation("msg", 3, 5, 4, 6));
050: assertEquals(2, r.getViolations().size());
051: r.flush();
052:
053: String str1 = sw.toString();
054: tr.Ace.log("str1: " + str1);
055:
056: assertEquals("order of reported violations", str0, str1);
057: }
058:
059: public void testSinglePointOutput() {
060: String content = ("As fast as thou shalt wane, so fast thou grow'st\n"
061: + "In one of thine, from that which thou departest;\n"
062: + "And that fresh blood which youngly thou bestow'st,\r\n"
063: + "Thou mayst call thine when thou from youth convertest.\n"
064: + "Herein lives wisdom, beauty, and increase;\n"
065: + "Without this folly, age, and cold decay:\r"
066: + "If all were minded so, the times should cease\r"
067: + "And threescore year would make the world away.\n"
068: + "Let those whom nature hath not made for store,\n"
069: + "Harsh, featureless, and rude, barrenly perish:\n"
070: + "Look whom she best endow'd, she gave the more;\n"
071: + "Which bounteous gift thou shouldst in bounty cherish:\n"
072: + "She carv'd thee for her seal, and meant thereby,\n"
073: + "Thou shouldst print more, not let that copy die.\n");
074:
075: StringWriter sw = new StringWriter();
076: Report r = new ContextReport(sw, content);
077: r.addViolation(new Violation("msg", 5, 9, 5, 9));
078: assertEquals(1, r.getViolations().size());
079: r.flush();
080: String str = sw.toString();
081: tr.Ace.log("str: " + str);
082:
083: // end of line gets "fixed" to whatever is appropriate for this system.
084: assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-"
085: + ANSIColor.RESET + ":" + EOLN + EOLN
086: + " 5. Herein lives wisdom, beauty, and increase;"
087: + EOLN + " ^" + EOLN + "*** msg" + EOLN
088: + EOLN, str);
089: }
090:
091: public void testSingleLineOutput() {
092: String content = ("How heavy do I journey on the way,\n"
093: + "When what I seek, my weary travel's end,\n"
094: + "Doth teach that ease and that repose to say,\r"
095: + "'Thus far the miles are measured from thy friend!'\n"
096: + "The beast that bears me, tired with my woe,\r"
097: + "Plods dully on, to bear that weight in me,\r\n"
098: + "As if by some instinct the wretch did know\r"
099: + "His rider lov'd not speed being made from thee.\n"
100: + "The bloody spur cannot provoke him on,\n"
101: + "That sometimes anger thrusts into his hide,\n"
102: + "Which heavily he answers with a groan,\n"
103: + "More sharp to me than spurring to his side;\n"
104: + "For that same groan doth put this in my mind,\n"
105: + "My grief lies onward, and my joy behind.\n");
106:
107: StringWriter sw = new StringWriter();
108: Report r = new ContextReport(sw, content);
109: r.addViolation(new Violation("msg", 10, 16, 10, 20));
110: assertEquals(1, r.getViolations().size());
111: r.flush();
112: String str = sw.toString();
113: tr.Ace.log("str: " + str);
114:
115: // end of line gets "fixed" to whatever is appropriate for this system.
116: assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-"
117: + ANSIColor.RESET + ":" + EOLN + EOLN
118: + " 10. That sometimes anger thrusts into his hide,"
119: + EOLN + " <--->" + EOLN
120: + "*** msg" + EOLN + EOLN, str);
121: }
122:
123: public void testMultiLineOutput() {
124: String content = ("Against that time, if ever that time come,\n"
125: + "When I shall see thee frown on my defects,\r\n"
126: + "When as thy love hath cast his utmost sum,\n"
127: + "Called to that audit by advis'd respects;\r"
128: + "Against that time when thou shalt strangely pass,\n"
129: + "And scarcely greet me with that sun, thine eye,\n"
130: + "When love, converted from the thing it was,\n"
131: + "Shall reasons find of settled gravity;\n"
132: + "Against that time do I ensconce me here,\n"
133: + "Within the knowledge of mine own desert,\n"
134: + "And this my hand, against my self uprear,\n"
135: + "To guard the lawful reasons on thy part: \n"
136: + "To leave poor me thou hast the strength of laws,\n"
137: + "Since why to love I can allege no cause.\n");
138:
139: StringWriter sw = new StringWriter();
140: Report r = new ContextReport(sw, content);
141: r.addViolation(new Violation("msg", 2, 23, 8, 13));
142: assertEquals(1, r.getViolations().size());
143: r.flush();
144: String str = sw.toString();
145: tr.Ace.log("str: " + str);
146:
147: // end of line gets "fixed" to whatever is appropriate for this system.
148: assertEquals(
149: "In "
150: + ANSIColor.BOLD
151: + ANSIColor.REVERSE
152: + "-"
153: + ANSIColor.RESET
154: + ":"
155: + EOLN
156: + EOLN
157: + " <-------------------"
158: + EOLN
159: + " 2. When I shall see thee frown on my defects,"
160: + EOLN
161: + " 3. When as thy love hath cast his utmost sum,"
162: + EOLN
163: + " 4. Called to that audit by advis'd respects;"
164: + EOLN
165: + " 5. Against that time when thou shalt strangely pass,"
166: + EOLN
167: + " 6. And scarcely greet me with that sun, thine eye,"
168: + EOLN
169: + " 7. When love, converted from the thing it was,"
170: + EOLN
171: + " 8. Shall reasons find of settled gravity;"
172: + EOLN + " ------------>" + EOLN
173: + "*** msg" + EOLN + EOLN, str);
174: }
175:
176: public void testSingleLineWithTabs() {
177: String content = ("\tMine eye hath play'd the painter and hath steel'd,\n"
178: + "\tThy beauty's form in table of my heart;\n"
179: + "\tMy body is the frame wherein 'tis held,\n"
180: + "\tAnd perspective it is best painter's art.\r"
181: + "\tFor through the painter must you see his skill,\n"
182: + "\tTo find where your true image pictur'd lies,\n"
183: + "\tWhich in my bosom's shop is hanging still,\r"
184: + "\tThat hath his windows glazed with thine eyes.\n"
185: + "\tNow see what good turns eyes for eyes have done:\n"
186: + "\tMine eyes have drawn thy shape, and thine for me\r\n"
187: + "\tAre windows to my breast, where-through the sun\n"
188: + "\tDelights to peep, to gaze therein on thee; \n"
189: + "\tYet eyes this cunning want to grace their art,\n"
190: + "\tThey draw but what they see, know not the heart.\n");
191:
192: StringWriter sw = new StringWriter();
193: Report r = new ContextReport(sw, content);
194: r.addViolation(new Violation("msg", 2, 23, 2, 25));
195: assertEquals(1, r.getViolations().size());
196: r.flush();
197: String str = sw.toString();
198: tr.Ace.log("str: " + str);
199:
200: assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-"
201: + ANSIColor.RESET + ":" + EOLN + EOLN
202: + " 2. \tThy beauty's form in table of my heart;"
203: + EOLN + " <->" + EOLN
204: + "*** msg" + EOLN + EOLN, str);
205: }
206:
207: }
|