PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/atlassian/uwc/converters/dokuwiki/ListConverterTest.java

https://bitbucket.org/appfusions/universal-wiki-converter
Java | 267 lines | 254 code | 13 blank | 0 comment | 0 complexity | c2c819bbd497c6acf1d70d7b5c82085b MD5 | raw file
  1. package com.atlassian.uwc.converters.dokuwiki;
  2. import junit.framework.TestCase;
  3. import org.apache.log4j.Logger;
  4. import org.apache.log4j.PropertyConfigurator;
  5. public class ListConverterTest extends TestCase {
  6. Logger log = Logger.getLogger(this.getClass());
  7. ListConverter tester = null;
  8. protected void setUp() throws Exception {
  9. tester = new ListConverter();
  10. PropertyConfigurator.configure("log4j.properties");
  11. }
  12. public void testUnorderedList() {
  13. String input, expected, actual;
  14. input = "Unordered Lists\n" +
  15. " * list item 1\n" +
  16. " * list item 2\n" +
  17. " * list item a\n" +
  18. " * list item b\n" +
  19. " * list item 3\n" +
  20. " * list item c\n" +
  21. " * foo\n" +
  22. " * bar\n" +
  23. " * foo2\n" +
  24. " * list item d\n" +
  25. "";
  26. expected = "Unordered Lists\n" +
  27. "* list item 1\n" +
  28. "* list item 2\n" +
  29. "** list item a\n" +
  30. "** list item b\n" +
  31. "* list item 3\n" +
  32. "** list item c\n" +
  33. "*** foo\n" +
  34. "**** bar\n" +
  35. "*** foo2\n" +
  36. "** list item d\n" +
  37. "";
  38. actual = tester.convertList(input);
  39. assertNotNull(actual);
  40. assertEquals(expected, actual);
  41. }
  42. public void testOrderedList() {
  43. String input, expected, actual;
  44. input = "Ordered Lists\n" +
  45. " - list item 1\n" +
  46. " - list item 2\n" +
  47. " - list item a\n" +
  48. " - list item b\n" +
  49. " - list item 3\n" +
  50. " - list item c\n" +
  51. " - foo\n" +
  52. " - bar\n" +
  53. " - foo2\n" +
  54. " - list item d\n" +
  55. "";
  56. expected = "Ordered Lists\n" +
  57. "# list item 1\n" +
  58. "# list item 2\n" +
  59. "## list item a\n" +
  60. "## list item b\n" +
  61. "# list item 3\n" +
  62. "## list item c\n" +
  63. "### foo\n" +
  64. "#### bar\n" +
  65. "### foo2\n" +
  66. "## list item d\n";
  67. actual = tester.convertList(input);
  68. assertNotNull(actual);
  69. assertEquals(expected, actual);
  70. }
  71. public void testMixedList() {
  72. String input, expected, actual;
  73. input = "Mixed Lists\n" +
  74. " * list item 1\n" +
  75. " * list item 2\n" +
  76. " - list item a\n" +
  77. " - list item b\n" +
  78. " * list item 3\n" +
  79. " - list item c\n" +
  80. " * foo\n" +
  81. " - bar\n" +
  82. " * foo2\n" +
  83. " - list item d\n" +
  84. "";
  85. expected = "Mixed Lists\n" +
  86. "* list item 1\n" +
  87. "* list item 2\n" +
  88. "*# list item a\n" +
  89. "*# list item b\n" +
  90. "* list item 3\n" +
  91. "*# list item c\n" +
  92. "*#* foo\n" +
  93. "*#*# bar\n" +
  94. "*#* foo2\n" +
  95. "*# list item d\n";
  96. actual = tester.convertList(input);
  97. assertNotNull(actual);
  98. assertEquals(expected, actual);
  99. }
  100. public void testBadWS() {
  101. String input, expected, actual;
  102. input = " *nows\n" +
  103. " -nows";
  104. expected = "* nows\n" +
  105. "# nows";
  106. actual = tester.convertList(input);
  107. assertNotNull(actual);
  108. assertEquals(expected, actual);
  109. }
  110. public void testSkipDepth() { //dokuwiki syntax says sets of two, but sometimes users ignore that
  111. String input, expected, actual;
  112. input = " * foo\n" +
  113. " * bar\n" +
  114. " * meh\n" +
  115. " * foo2\n" +
  116. "";
  117. expected = "* foo\n" +
  118. "** bar\n" +
  119. "*** meh\n" +
  120. "* foo2\n" +
  121. "";
  122. actual = tester.convertList(input);
  123. assertNotNull(actual);
  124. assertEquals(expected, actual);
  125. }
  126. public void testNotSetsOfTwo() { //dokuwiki syntax says sets of two, but sometimes users ignore that
  127. String input, expected, actual;
  128. input = " * foo\n" +
  129. " * bar\n" +
  130. " * bar2\n" +
  131. " * meh\n" +
  132. " * meh2\n" +
  133. " * meh3\n" +
  134. "\n" +
  135. "NEW LIST:\n" +
  136. " * FOO!\n" +
  137. "";
  138. expected = "* foo\n" +
  139. "** bar\n" +
  140. "** bar2\n" +
  141. "*** meh\n" +
  142. "*** meh2\n" +
  143. "*** meh3\n" +
  144. "\n" +
  145. "NEW LIST:\n" +
  146. "* FOO!\n" +
  147. "";
  148. actual = tester.convertList(input);
  149. assertNotNull(actual);
  150. assertEquals(expected, actual);
  151. }
  152. public void testTwoListsNotSetsOfTwo() {
  153. String input, expected, actual;
  154. input = " * three\n" +
  155. " - six\n" +
  156. " * eight\n" +
  157. "Not a list\n" +
  158. " * two\n" +
  159. " * four\n" +
  160. " - six\n" +
  161. " * eight\n" +
  162. " - six\n" +
  163. "Not a list";
  164. expected = "* three\n" +
  165. "*# six\n" +
  166. "*#* eight\n" +
  167. "Not a list\n" +
  168. "* two\n" +
  169. "** four\n" +
  170. "**# six\n" +
  171. "**#* eight\n" +
  172. "**# six\n" +
  173. "Not a list";
  174. actual = tester.convertList(input);
  175. assertNotNull(actual);
  176. assertEquals(expected, actual);
  177. }
  178. public void testManyLists() {
  179. String input, expected, actual;
  180. input = "Unordered Lists\n" +
  181. " * list item 1\n" +
  182. " * list item 2\n" +
  183. " * list item a\n" +
  184. " * list item b\n" +
  185. " * list item 3\n" +
  186. " * list item c\n" +
  187. " * foo\n" +
  188. " * bar\n" +
  189. " * foo2\n" +
  190. " * list item d\n" +
  191. "\n" +
  192. "Ordered Lists\n" +
  193. " - list item 1\n" +
  194. " - list item 2\n" +
  195. " - list item a\n" +
  196. " - list item b\n" +
  197. " - list item 3\n" +
  198. " - list item c\n" +
  199. " - foo\n" +
  200. " - bar\n" +
  201. " - foo2\n" +
  202. " - list item d\n" +
  203. "\n" +
  204. "Mixed Lists\n" +
  205. " * list item 1\n" +
  206. " * list item 2\n" +
  207. " - list item a\n" +
  208. " - list item b\n" +
  209. " * list item 3\n" +
  210. " - list item c\n" +
  211. " * foo\n" +
  212. " - bar\n" +
  213. " * foo2\n" +
  214. " - list item d";
  215. expected = "Unordered Lists\n" +
  216. "* list item 1\n" +
  217. "* list item 2\n" +
  218. "** list item a\n" +
  219. "** list item b\n" +
  220. "* list item 3\n" +
  221. "** list item c\n" +
  222. "*** foo\n" +
  223. "**** bar\n" +
  224. "*** foo2\n" +
  225. "** list item d\n" +
  226. "\n" +
  227. "Ordered Lists\n" +
  228. "# list item 1\n" +
  229. "# list item 2\n" +
  230. "## list item a\n" +
  231. "## list item b\n" +
  232. "# list item 3\n" +
  233. "## list item c\n" +
  234. "### foo\n" +
  235. "#### bar\n" +
  236. "### foo2\n" +
  237. "## list item d\n" +
  238. "\n" +
  239. "Mixed Lists\n" +
  240. "* list item 1\n" +
  241. "* list item 2\n" +
  242. "*# list item a\n" +
  243. "*# list item b\n" +
  244. "* list item 3\n" +
  245. "*# list item c\n" +
  246. "*#* foo\n" +
  247. "*#*# bar\n" +
  248. "*#* foo2\n" +
  249. "*# list item d";
  250. actual = tester.convertList(input);
  251. assertNotNull(actual);
  252. assertEquals(expected, actual);
  253. }
  254. }