@@ -40,57 +40,90 @@ public void testFindWrapPos() throws Exception
4040 HelpFormatter hf = new HelpFormatter ();
4141
4242 String text = "This is a test." ;
43- //text width should be max 8; the wrap position is 7
43+ // text width should be max 8; the wrap position is 7
4444 assertEquals ("wrap position" , 7 , hf .findWrapPos (text , 8 , 0 ));
45- //starting from 8 must give -1 - the wrap pos is after end
45+
46+ // starting from 8 must give -1 - the wrap pos is after end
4647 assertEquals ("wrap position 2" , -1 , hf .findWrapPos (text , 8 , 8 ));
47- //if there is no a good position before width to make a wrapping look for the next one
48+
49+ // if there is no a good position before width to make a wrapping look for the next one
4850 text = "aaaa aa" ;
4951 assertEquals ("wrap position 3" , 4 , hf .findWrapPos (text , 3 , 0 ));
5052 }
5153
52- public void testPrintWrapped () throws Exception
54+ public void testRenderWrappedTextSingleLine ()
5355 {
54- StringBuffer sb = new StringBuffer ();
55- HelpFormatter hf = new HelpFormatter () ;
56-
56+ // single line text
57+ int width = 12 ;
58+ int padding = 0 ;
5759 String text = "This is a test." ;
58-
59- String expected = "This is a" + hf .getNewLine () + "test." ;
60- hf .renderWrappedText (sb , 12 , 0 , text );
60+ String expected = "This is a" + EOL +
61+ "test." ;
62+
63+ StringBuffer sb = new StringBuffer ();
64+ new HelpFormatter ().renderWrappedText (sb , width , padding , text );
6165 assertEquals ("single line text" , expected , sb .toString ());
66+ }
6267
63- sb .setLength (0 );
64- expected = "This is a" + hf .getNewLine () + " test." ;
65- hf .renderWrappedText (sb , 12 , 4 , text );
68+ public void testRenderWrappedTextSingleLinePadded ()
69+ {
70+ // single line padded text
71+ int width = 12 ;
72+ int padding = 4 ;
73+ String text = "This is a test." ;
74+ String expected = "This is a" + EOL +
75+ " test." ;
76+
77+ StringBuffer sb = new StringBuffer ();
78+ new HelpFormatter ().renderWrappedText (sb , width , padding , text );
6679 assertEquals ("single line padded text" , expected , sb .toString ());
80+ }
6781
68- text = " -p,--period <PERIOD> PERIOD is time duration of form " +
69- "DATE[-DATE] where DATE has form YYYY[MM[DD]]" ;
70-
71- sb .setLength (0 );
72- expected = " -p,--period <PERIOD> PERIOD is time duration of" +
73- hf .getNewLine () +
74- " form DATE[-DATE] where DATE" +
75- hf .getNewLine () +
76- " has form YYYY[MM[DD]]" ;
77- hf .renderWrappedText (sb , 53 , 24 , text );
82+ public void testRenderWrappedTextSingleLinePadded2 ()
83+ {
84+ // single line padded text 2
85+ int width = 53 ;
86+ int padding = 24 ;
87+ String text = " -p,--period <PERIOD> PERIOD is time duration of form " +
88+ "DATE[-DATE] where DATE has form YYYY[MM[DD]]" ;
89+ String expected = " -p,--period <PERIOD> PERIOD is time duration of" + EOL +
90+ " form DATE[-DATE] where DATE" + EOL +
91+ " has form YYYY[MM[DD]]" ;
92+
93+ StringBuffer sb = new StringBuffer ();
94+ new HelpFormatter ().renderWrappedText (sb , width , padding , text );
7895 assertEquals ("single line padded text 2" , expected , sb .toString ());
96+ }
7997
80- text = "aaaa aaaa aaaa" + hf .getNewLine () +
81- "aaaaaa" + hf .getNewLine () +
82- "aaaaa" ;
83-
84- expected = text ;
85- sb .setLength (0 );
86- hf .renderWrappedText (sb , 16 , 0 , text );
98+ public void testRenderWrappedTextMultiLine ()
99+ {
100+ // multi line text
101+ int width = 16 ;
102+ int padding = 0 ;
103+ String text = "aaaa aaaa aaaa" + EOL +
104+ "aaaaaa" + EOL +
105+ "aaaaa" ;
106+ String expected = text ;
107+
108+ StringBuffer sb = new StringBuffer ();
109+ new HelpFormatter ().renderWrappedText (sb , width , padding , text );
87110 assertEquals ("multi line text" , expected , sb .toString ());
111+ }
88112
89- expected = "aaaa aaaa aaaa" + hf .getNewLine () +
90- " aaaaaa" + hf .getNewLine () +
91- " aaaaa" ;
92- sb .setLength (0 );
93- hf .renderWrappedText (sb , 16 , 4 , text );
113+ public void testRenderWrappedTextMultiLinePadded ()
114+ {
115+ // multi-line padded text
116+ int width = 16 ;
117+ int padding = 4 ;
118+ String text = "aaaa aaaa aaaa" + EOL +
119+ "aaaaaa" + EOL +
120+ "aaaaa" ;
121+ String expected = "aaaa aaaa aaaa" + EOL +
122+ " aaaaaa" + EOL +
123+ " aaaaa" ;
124+
125+ StringBuffer sb = new StringBuffer ();
126+ new HelpFormatter ().renderWrappedText (sb , width , padding , text );
94127 assertEquals ("multi-line padded text" , expected , sb .toString ());
95128 }
96129
@@ -111,7 +144,7 @@ public void testPrintOptions() throws Exception
111144 assertEquals ("simple non-wrapped option" , expected , sb .toString ());
112145
113146 int nextLineTabStop = leftPad + descPad + "-a" .length ();
114- expected = lpad + "-a" + dpad + "aaaa aaaa aaaa" + hf . getNewLine () +
147+ expected = lpad + "-a" + dpad + "aaaa aaaa aaaa" + EOL +
115148 hf .createPadding (nextLineTabStop ) + "aaaa aaaa" ;
116149 sb .setLength (0 );
117150 hf .renderOptions (sb , nextLineTabStop + 17 , options , leftPad , descPad );
@@ -125,7 +158,7 @@ public void testPrintOptions() throws Exception
125158 assertEquals ("long non-wrapped option" , expected , sb .toString ());
126159
127160 nextLineTabStop = leftPad + descPad + "-a,--aaa" .length ();
128- expected = lpad + "-a,--aaa" + dpad + "dddd dddd" + hf . getNewLine () +
161+ expected = lpad + "-a,--aaa" + dpad + "dddd dddd" + EOL +
129162 hf .createPadding (nextLineTabStop ) + "dddd dddd" ;
130163 sb .setLength (0 );
131164 hf .renderOptions (sb , 25 , options , leftPad , descPad );
@@ -134,9 +167,9 @@ public void testPrintOptions() throws Exception
134167 options = new Options ().
135168 addOption ("a" , "aaa" , false , "dddd dddd dddd dddd" ).
136169 addOption ("b" , false , "feeee eeee eeee eeee" );
137- expected = lpad + "-a,--aaa" + dpad + "dddd dddd" + hf . getNewLine () +
138- hf .createPadding (nextLineTabStop ) + "dddd dddd" + hf . getNewLine () +
139- lpad + "-b " + dpad + "feeee eeee" + hf . getNewLine () +
170+ expected = lpad + "-a,--aaa" + dpad + "dddd dddd" + EOL +
171+ hf .createPadding (nextLineTabStop ) + "dddd dddd" + EOL +
172+ lpad + "-b " + dpad + "feeee eeee" + EOL +
140173 hf .createPadding (nextLineTabStop ) + "eeee eeee" ;
141174 sb .setLength (0 );
142175 hf .renderOptions (sb , 25 , options , leftPad , descPad );
0 commit comments