]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/winterwell.markdown/src/winterwell/markdown/pagemodel/MarkdownFormatterTest.java
Tycho compilation changes for SVN version also.
[simantics/platform.git] / bundles / winterwell.markdown / src / winterwell / markdown / pagemodel / MarkdownFormatterTest.java
1 //package winterwell.markdown.pagemodel;
2 //
3 //import java.util.Arrays;
4 //import java.util.List;
5 //
6 //import junit.framework.TestCase;
7 //// import winterwell.utils.MarkdownFormatter;
8 //
9 ///**
10 // * Test methods in the StringMethods utility class.
11 // */
12 //public class MarkdownFormatterTest extends TestCase
13 //{
14 //  /**
15 //   * The local line-end string. \n on unix, \r\n on windows.
16 //   * I really want to run through all of these tests with both styles.
17 //   * We'll come back to that sort of a trick.
18 //   */
19 //  // public String LINEEND = System.getProperty("line.separator");
20 //  public static final String LINEEND = "\r\n";
21 //
22 //  /**
23 //   * Test default word wrapping of a long line of normal text.
24 //   */
25 //  public void testFormatStringInt ()
26 //  {
27 //    final String LONG_LINE = 
28 //      "Now is the time for all good " +
29 //      "chickens to come to the aid of " +
30 //      "their coopertino lattes, and " +
31 //      "begin the process of singing.";
32 //    final String EXPECTED = 
33 //      "Now is the time for all good" + LINEEND +
34 //      "chickens to come to the aid of" + LINEEND + // This line is 30 characters
35 //      "their coopertino lattes, and" + LINEEND +
36 //      "begin the process of singing.";
37 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 30, LINEEND));
38 //  }
39 //
40 //  /**
41 //   * If the initial part of the line contains some spaces, we use that as
42 //   * the "indentation" for every other line.
43 //   * @throws Exception
44 //   */
45 //  public void testIndentOfSpaces () throws Exception
46 //  {
47 //    final String LONG_LINE = 
48 //      "    Now is the time for all good " +
49 //      "chickens to come to the aid of " +
50 //      "their coopertino lattes, and " +
51 //      "begin the process of singing.";
52 //    final String EXPECTED = 
53 //      "    Now is the time for all good" + LINEEND +
54 //      "    chickens to come to the aid of" + LINEEND +
55 //      "    their coopertino lattes, and" + LINEEND +
56 //      "    begin the process of singing.";
57 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
58 //  }
59 //  
60 //  /**
61 //   * Can we maintain the format of text that is already formatted?
62 //   * @throws Exception
63 //   */
64 //  public void testAlreadyFormatted () throws Exception
65 //  {
66 //    final String LONG_LINE = 
67 //      "    Now is the time for all good" + LINEEND +
68 //      "    chickens to come to the aid of" + LINEEND +
69 //      "    their coopertino lattes, and" + LINEEND +
70 //      "    begin the process of singing.";
71 //    assertEquals (LONG_LINE, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
72 //  }
73 //
74 //  /**
75 //   * Formatting a single line is all fine and dandy, but what about
76 //   * formatting multiple paragraphs, that is, blank lines.
77 //   * @throws Exception
78 //   */
79 //  public void testMultipleParagraphs () throws Exception
80 //  {
81 //    final String LONG_LINE = 
82 //      "    Now is the time for all good " +
83 //      "chickens to come to their aid." + LINEEND + LINEEND +
84 //      "  And drink coopertino lattes, and " +
85 //      "begin the process of singing.";
86 //    final String EXPECTED = 
87 //      "    Now is the time for all good" + LINEEND +
88 //      "    chickens to come to their aid." + LINEEND + LINEEND +
89 //      "  And drink coopertino lattes," + LINEEND +
90 //      "  and begin the process of" + LINEEND + "  singing.";
91 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
92 //  }
93 //  
94 //  /**
95 //   * What if the section we are formatting, begins with line feeds?
96 //   * Do we keep 'em? Might as well. :-)
97 //   * @throws Exception
98 //   */
99 //  public void testInitialLineFeeds () throws Exception
100 //  {
101 //    final String LONG_LINE = LINEEND + LINEEND + LINEEND +
102 //      "    Now is the time for all good" + LINEEND +
103 //      "    chickens to come to the aid of" + LINEEND +
104 //      "    their coopertino lattes, and" + LINEEND +
105 //      "    begin the process of singing.";
106 //    assertEquals (LONG_LINE, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
107 //  }
108 //  
109 //  /**
110 //   * We need to be able to format bulleted lists appropriately.
111 //   * @throws Exception
112 //   */
113 //  public void testSingleBulletedList () throws Exception
114 //  {
115 //    final String LONG_LINE = 
116 //      "  * Now is the time for all good " +
117 //      "chickens to come to the aid of " + LINEEND +
118 //      "their coopertino lattes, and " +
119 //      "begin the process of singing.";
120 //    final String EXPECTED = 
121 //      "  * Now is the time for all good" + LINEEND +
122 //      "    chickens to come to the aid of" + LINEEND +
123 //      "    their coopertino lattes, and" + LINEEND +
124 //      "    begin the process of singing.";
125 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
126 //  }
127 //  
128 //  /**
129 //   * What about dealing with multiple bulleted lists.
130 //   * @throws Exception
131 //   */
132 //  public void testMultipleBulletedList () throws Exception
133 //  {
134 //    final String LONG_LINE = 
135 //      "Now is the time for all good " +
136 //      "chickens to:" + LINEEND + LINEEND +
137 //      " * Cluck" + LINEEND + 
138 //      " * Sing" + LINEEND + 
139 //      " * Drink coopertino lattes.";
140 //    final String EXPECTED = 
141 //      "Now is the time for all good" + LINEEND +
142 //      "chickens to:" + LINEEND + LINEEND +
143 //      " * Cluck" + LINEEND + 
144 //      " * Sing" + LINEEND + 
145 //      " * Drink coopertino lattes.";
146 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
147 //  }
148 //  
149 //  /**
150 //   * What about dealing with multiple bulleted lists.
151 //   * @throws Exception
152 //   */
153 //  public void testMultipleDashedBulletedList () throws Exception
154 //  {
155 //    final String LONG_LINE = 
156 //      "Now is the time for all good " +
157 //      "chickens to:" + LINEEND + LINEEND +
158 //      " - Cluck" + LINEEND + 
159 //      " - Sing" + LINEEND + 
160 //      " - Drink coopertino lattes.";
161 //    final String EXPECTED = 
162 //      "Now is the time for all good" + LINEEND +
163 //      "chickens to:" + LINEEND + LINEEND +
164 //      " - Cluck" + LINEEND + 
165 //      " - Sing" + LINEEND + 
166 //      " - Drink coopertino lattes.";
167 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
168 //  }
169 //  
170 //  /**
171 //   * Tests whether we can have nested bulleted lists.
172 //   * @throws Exception
173 //   */
174 //  public void testSubindentedBulletedLists () throws Exception
175 //  {
176 //    final String LONG_LINE = 
177 //      "Now is the time for all good " +
178 //      "chickens to:" + LINEEND + LINEEND +
179 //      " * Cluck, cluck, cluck till their little feets hurt:" + LINEEND +
180 //      "   * Do it again and again and again and again." + LINEEND + 
181 //      "   * And maybe again and again if their mommy's say so." + LINEEND +
182 //      "     * We can indent really, really, deep with three levels of subitems." + LINEEND +
183 //      "     * But we aren't sure if this is getting ridiculous or just plain expected." + LINEEND +
184 //      " * Sing, sing, sing till their little voices break:" + LINEEND +
185 //      "   * Do it again and again and again and again." + LINEEND + 
186 //      "   * And maybe again and again if their mommy's say so." + LINEEND +
187 //      " * Drink coopertino lattes.";
188 //    final String EXPECTED = 
189 //      "Now is the time for all good" + LINEEND +
190 //      "chickens to:" + LINEEND + LINEEND +
191 //      " * Cluck, cluck, cluck till their" + LINEEND + 
192 //      "   little feets hurt:" + LINEEND +
193 //      "   * Do it again and again and" + LINEEND +
194 //      "     again and again." + LINEEND + 
195 //      "   * And maybe again and again if" + LINEEND + 
196 //      "     their mommy's say so." + LINEEND +
197 //      "     * We can indent really," + LINEEND +
198 //      "       really, deep with three" + LINEEND +
199 //      "       levels of subitems." + LINEEND +
200 //      "     * But we aren't sure if this" + LINEEND +
201 //      "       is getting ridiculous or " + LINEEND + 
202 //      "       just plain expected." + LINEEND +
203 //      " * Sing, sing, sing till their" + LINEEND +
204 //      "   little voices break:" + LINEEND +
205 //      "   * Do it again and again and" + LINEEND +
206 //      "     again and again." + LINEEND + 
207 //      "   * And maybe again and again if" + LINEEND + 
208 //      "     their mommy's say so." + LINEEND +
209 //      " * Drink coopertino lattes.";
210 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
211 //  }
212 //  
213 //  /**
214 //   * Tests whether we can have nested bulleted lists.
215 //   * @throws Exception
216 //   */
217 //  public void testSubindentedBulletedLists2 () throws Exception
218 //  {
219 //    final String LONG_LINE = 
220 //      "Now is the time for all good " +
221 //      "chickens to:" + LINEEND + LINEEND +
222 //      " * Cluck, cluck, cluck till their little feets hurt:" + LINEEND + LINEEND +
223 //      "   * Do it again and again and again and again." + LINEEND +  LINEEND +
224 //      "   * And maybe again and again if their mommy's say so." + LINEEND + LINEEND +
225 //      "     * We can indent really, really, deep with three levels of subitems." + LINEEND + LINEEND +
226 //      "     * But we aren't sure if this is getting ridiculous or just plain expected." + LINEEND + LINEEND +
227 //      " * Sing, sing, sing till their little voices break:" + LINEEND + LINEEND +
228 //      "   * Do it again and again and again and again." + LINEEND +  LINEEND +
229 //      "   * And maybe again and again if their mommy's say so." + LINEEND + LINEEND +
230 //      " * Drink coopertino lattes.";
231 //    final String EXPECTED = 
232 //      "Now is the time for all good" + LINEEND +
233 //      "chickens to:" + LINEEND + LINEEND +
234 //      " * Cluck, cluck, cluck till their" + LINEEND + 
235 //      "   little feets hurt:" + LINEEND + LINEEND +
236 //      "   * Do it again and again and" + LINEEND +
237 //      "     again and again." + LINEEND +  LINEEND +
238 //      "   * And maybe again and again if" + LINEEND + 
239 //      "     their mommy's say so." + LINEEND + LINEEND +
240 //      "     * We can indent really," + LINEEND +
241 //      "       really, deep with three" + LINEEND +
242 //      "       levels of subitems." + LINEEND + LINEEND +
243 //      "     * But we aren't sure if this" + LINEEND +
244 //      "       is getting ridiculous or" + LINEEND + 
245 //      "       just plain expected." + LINEEND + LINEEND +
246 //      " * Sing, sing, sing till their" + LINEEND +
247 //      "   little voices break:" + LINEEND + LINEEND +
248 //      "   * Do it again and again and" + LINEEND +
249 //      "     again and again." + LINEEND +  LINEEND +
250 //      "   * And maybe again and again if" + LINEEND + 
251 //      "     their mommy's say so." + LINEEND + LINEEND +
252 //      " * Drink coopertino lattes.";
253 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
254 //  }
255 //  
256 //  /**
257 //   * What about dealing with a numeric list?
258 //   * @throws Exception
259 //   */
260 //  public void testSingleNumericList () throws Exception
261 //  {
262 //    final String LONG_LINE = 
263 //      " 2. Now is the time for all good " +
264 //      "chickens to come to the aid of " +
265 //      "their coopertino lattes, and " +
266 //      "begin the process of singing.";
267 //    final String EXPECTED = 
268 //      " 2. Now is the time for all good" + LINEEND +
269 //      "    chickens to come to the aid of" + LINEEND +
270 //      "    their coopertino lattes, and" + LINEEND +
271 //      "    begin the process of singing.";
272 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
273 //  }
274 //
275 //  /**
276 //   * What about dealing with multiple bulleted lists.
277 //   * @throws Exception
278 //   */
279 //  public void testMultipleNumericList () throws Exception
280 //  {
281 //    final String LONG_LINE = 
282 //      "Now is the time for all good " +
283 //      "chickens to:" + LINEEND + LINEEND +
284 //      " 1. Cluck" + LINEEND + 
285 //      " 2. Sing" + LINEEND + 
286 //      " 3. Drink coopertino lattes.";
287 //    final String EXPECTED = 
288 //      "Now is the time for all good" + LINEEND +
289 //      "chickens to:" + LINEEND + LINEEND +
290 //      " 1. Cluck" + LINEEND + 
291 //      " 2. Sing" + LINEEND + 
292 //      " 3. Drink coopertino lattes.";
293 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
294 //  }
295 //  
296 //  /**
297 //   * What about dealing with sections that should not be word wrapped, like
298 //   * the text between brackets (since they are hyperlinks).
299 //   * @throws Exception
300 //   */
301 //  public void testNoWordWrapBracket() throws Exception
302 //  {
303 //    final String LONG_LINE = 
304 //      "Now is the time for all good " +
305 //      "chickens to come to [the spurious and costly][3] " +
306 //      "aid of their coopertino cups, " +
307 //      "and begin sing.";
308 //    final String EXPECTED = 
309 //      "Now is the time for all good" + LINEEND +
310 //      "chickens to come to [the spurious and costly][3]" + LINEEND +
311 //      "aid of their coopertino cups, and" + LINEEND +
312 //      "begin sing.";
313 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
314 //  }
315 //  /**
316 //   * What about dealing with bracketed sections with no extra white space
317 //   * @throws Exception
318 //   */
319 //  public void testNoWordWrapBracket2() throws Exception
320 //  {
321 //    final String LONG_LINE = 
322 //      "Now is the time for all good " +
323 //      "chickens to come to[the spurious and costly][3] " +
324 //      "aid of their coopertino cups, " +
325 //      "and begin sing.";
326 //    final String EXPECTED = 
327 //      "Now is the time for all good" + LINEEND +
328 //      "chickens to come to[the spurious and costly][3]" + LINEEND +
329 //      "aid of their coopertino cups, and" + LINEEND +
330 //      "begin sing.";
331 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
332 //  }
333 //  
334 //  /**
335 //   * What about dealing with bold sections that should not be word wrapped.
336 //   * @throws Exception
337 //   */
338 //  public void testNoWordWrapDoubleAsterix() throws Exception
339 //  {
340 //    final String LONG_LINE = 
341 //      "Now is the time for all good " +
342 //      "chickens to come to **the spurious and costly** " +
343 //      "aid of their coopertino cups, " +
344 //      "and begin sing.";
345 //    final String EXPECTED = 
346 //      "Now is the time for all good" + LINEEND +
347 //      "chickens to come to **the spurious and costly**" + LINEEND +
348 //      "aid of their coopertino cups, and" + LINEEND +
349 //      "begin sing.";
350 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
351 //  }
352 //
353 //  /**
354 //   * What about dealing with italic sections that should not be word wrapped
355 //   * @throws Exception
356 //   */
357 //  public void testNoWordWrapSingleAsterix() throws Exception
358 //  {
359 //    final String LONG_LINE = 
360 //      "Now is the time for all good " +
361 //      "chickens to come to *the spurious and costly* " +
362 //      "aid of their coopertino cups, " +
363 //      "and begin sing.";
364 //    final String EXPECTED = 
365 //      "Now is the time for all good" + LINEEND +
366 //      "chickens to come to *the spurious and costly*" + LINEEND +
367 //      "aid of their coopertino cups, and" + LINEEND +
368 //      "begin sing.";
369 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
370 //  }
371 //
372 //  /**
373 //   * What about dealing with sections that are code should not be broken.
374 //   * @throws Exception
375 //   */
376 //  public void testNoWordWrapCode() throws Exception
377 //  {
378 //    final String LONG_LINE = 
379 //      "Now is the time for all good " +
380 //      "chickens to come to `the spurious and costly` " +
381 //      "aid of their coopertino cups, " +
382 //      "and begin sing.";
383 //    final String EXPECTED = 
384 //      "Now is the time for all good" + LINEEND +
385 //      "chickens to come to `the spurious and costly`" + LINEEND +
386 //      "aid of their coopertino cups, and" + LINEEND +
387 //      "begin sing.";
388 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
389 //  }
390 //
391 //  /**
392 //   * What about dealing with double parenthesis sections ... these shouldn't
393 //   * be broken up.
394 //   * @throws Exception
395 //   */
396 //  public void testNoWordWrapDoubleParens() throws Exception
397 //  {
398 //    final String LONG_LINE = 
399 //      "Now is the time for all good " +
400 //      "chickens to come to ((the spurious and costly)) " +
401 //      "aid of their coopertino cups, " +
402 //      "and begin sing.";
403 //    final String EXPECTED = 
404 //      "Now is the time for all good" + LINEEND +
405 //      "chickens to come to ((the spurious and costly))" + LINEEND +
406 //      "aid of their coopertino cups, and" + LINEEND +
407 //      "begin sing.";
408 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 34, LINEEND));
409 //  }
410 //
411 //
412 //  /**
413 //   * If a line, embedded in a paragraph has two spaces at the end of the line,
414 //   * these need to be honored and maintained.
415 //   * @throws Exception
416 //   */
417 //  public void testLineBreaksHonored () throws Exception
418 //  {
419 //    final String LONG_LINE = 
420 //      "Now is the time for all good " +
421 //      "chickens to come    " + LINEEND + 
422 //      "to the aid of their coopertino lattes, and " +
423 //      "begin the process of singing.";
424 //    final String EXPECTED = 
425 //      "Now is the time for all good" + LINEEND +
426 //      "chickens to come  " + LINEEND +
427 //      "to the aid of their coopertino" + LINEEND + 
428 //      "lattes, and begin the process of" + LINEEND +
429 //      "singing.";
430 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 33, LINEEND));
431 //  }
432 //  
433 //  /**
434 //   * A "blockquote" in Markdown can accept > characters at the beginning
435 //   * of all of the lines. 
436 //   * @throws Exception
437 //   */
438 //  public void testBlockQuoteSimple () throws Exception
439 //  {
440 //    final String LONG_LINE = 
441 //      " > Now is the time for all good " +
442 //      "chickens to come to the aid of " +
443 //      "their coopertino <lattes>, and " +
444 //      "begin the process of singing.";
445 //    final String EXPECTED = 
446 //      " > Now is the time for all good" + LINEEND +
447 //      " > chickens to come to the aid of" + LINEEND +
448 //      " > their coopertino <lattes>, and" + LINEEND +
449 //      " > begin the process of singing.";
450 //    assertEquals (EXPECTED, MarkdownFormatter.format (LONG_LINE, 33, LINEEND));
451 //  }
452 //
453 //  /**
454 //   * A "blockquote" in Markdown can accept > characters at the beginning
455 //   * of all of the lines. Can we accept a version that is already formatted?
456 //   * @throws Exception
457 //   */
458 //  public void testBlockQuoteAlreadyFormatted () throws Exception
459 //  {
460 //    final String EXPECTED = 
461 //      " > Now is the time for all good" + LINEEND +
462 //      " > chickens to come to the aid of" + LINEEND +
463 //      " > their coopertino <lattes>, and" + LINEEND +
464 //      " > begin the process of singing.";
465 //    assertEquals (EXPECTED, MarkdownFormatter.format (EXPECTED, 33, LINEEND));
466 //  }
467 //  
468 //  /**
469 //   * Tests that the "list" interface works if each string does not have
470 //   * carriage returns.
471 //   * @throws Exception
472 //   */
473 //  public void testListWithoutLinefeeds () throws Exception
474 //  {
475 //    final String lineend = System.getProperty("line.separator");
476 //
477 //    final List<String> lines = Arrays.asList ( new String[] { 
478 //      "Now is the time for all good",
479 //      "chickens to come to the aid of",
480 //      "their coopertino lattes, and",
481 //      "begin the process of singing."
482 //    } );
483 //    final String EXPECTED = 
484 //      "Now is the time for all good" + lineend +
485 //      "chickens to come to the aid of" + lineend + // This line is 30 characters
486 //      "their coopertino lattes, and" + lineend +
487 //      "begin the process of singing.";
488 //    
489 //    final String RESULTS = MarkdownFormatter.format (lines, 30);
490 //    assertEquals (EXPECTED, RESULTS);
491 //  }
492 //
493 //  /**
494 //   * Tests that the "list" interface works if each string has carriage returns.
495 //   * @throws Exception
496 //   */
497 //  public void testListWithLinefeeds () throws Exception
498 //  {
499 //    final List<String> lines = Arrays.asList ( new String[] { 
500 //      "Now is the time for all good chickens to come" + LINEEND,
501 //      "to the aid of" + LINEEND,
502 //      "their coopertino lattes, and" + LINEEND,
503 //      "begin the process of singing."
504 //    } );
505 //    final String EXPECTED = 
506 //      "Now is the time for all good" + LINEEND +
507 //      "chickens to come to the aid of" + LINEEND + // This line is 30 characters
508 //      "their coopertino lattes, and" + LINEEND +
509 //      "begin the process of singing.";
510 //    
511 //    final String RESULTS = MarkdownFormatter.format (lines, 30);
512 //    assertEquals (EXPECTED, RESULTS);
513 //  }
514 //
515 //  /**
516 //   * Tests that we don't break up image tags.
517 //   * @throws Exception
518 //   */
519 //  public void testImageTags () throws Exception
520 //  {
521 //    final List<String> lines = Arrays.asList ( new String[] { 
522 //      "Now is the time for all good chickens to come " +
523 //      "to the aid ![Some text description](http://www.google.com/images/logo.gif)" + LINEEND,
524 //      "their coopertino lattes, and" + LINEEND,
525 //      "begin the process of singing."
526 //    } );
527 //    final String EXPECTED = 
528 //      "Now is the time for all good" + LINEEND +
529 //      "chickens to come to the aid " + // This line is 30 characters
530 //      "![Some text description](http://www.google.com/images/logo.gif)" + LINEEND +
531 //      "their coopertino lattes, and" + LINEEND +
532 //      "begin the process of singing.";
533 //    
534 //    final String RESULTS = MarkdownFormatter.format (lines, 30);
535 //    assertEquals (EXPECTED, RESULTS);
536 //  }
537 //}