test_tedi2html.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. t2l = new tedi2html();
  2. QUnit.module('tedi2html', function() {
  3. QUnit.test('convert initial line text', function(assert) {
  4. //Empty string
  5. console.log("EMPTY STRINGS");
  6. assert.equal((t2l.convert("", "", "")), (""));
  7. assert.equal(t2l.convert(" ", "", ""), (" \n"));
  8. assert.equal(t2l.convert("\n", "", ""), ("\n"));
  9. });
  10. QUnit.test('titles', function(assert) {
  11. //Titles
  12. console.log("TITLES");
  13. try{
  14. t2l.convert("#####", "", "");
  15. }catch(err) {
  16. assert.equal(err, "Unexpected heading size#####");
  17. }
  18. assert.equal(t2l.convert("paragraph \n#This isn't a title", "", ""), ("paragraph \n<h1>This isn't a title</h1>\n"));
  19. assert.equal(t2l.convert("#This isn't a title", "", ""), ("<h1>This isn't a title</h1>\n"));
  20. assert.equal(t2l.convert(" #This isn't a title", "", ""), ("<h1>This isn't a title</h1>\n"));
  21. assert.equal(t2l.convert("\t##This isn't a title", "", ""), ("<h2>This isn't a title</h2>\n"));
  22. assert.equal(t2l.convert("##This isn't a title", "", ""), ("<h2>This isn't a title</h2>\n"));
  23. assert.equal(t2l.convert("###This isn't a title", "", ""), ("<h3>This isn't a title</h3>\n"));
  24. assert.equal(t2l.convert("####This isn't a title", "", ""), ("<h4>This isn't a title</h4>\n"));
  25. assert.equal(t2l.convert("#####This isn't a title", "", ""), "<h4>This isn't a title</h4>\n" );
  26. assert.equal(t2l.convert("#####This isn't a title", "", ""), "<h4>This isn't a title</h4>\n" );
  27. });
  28. QUnit.test('list', function(assert) {
  29. console.log("LIST");
  30. assert.equal(t2l.convert("__", "", ""), ("<ul>\n"));
  31. assert.equal(t2l.convert("--Text", "", ""), ("--Text"));
  32. assert.equal(t2l.convert(",,", "", ""), (",,"));
  33. assert.equal(t2l.convert("__\n--Text\n,,", "", ""), ("<ul>\n<li>Text</ul>\n"));
  34. });
  35. QUnit.test('quotes', function(assert) {
  36. console.log("QUOTE");
  37. assert.equal(t2l.convert("\"Quoted text\"", "", ""), ("Quoted text"));
  38. try{
  39. t2l.convert("\"Bad quoting", "", "")
  40. }catch(err) {
  41. assert.equal(err, "Missing end quotes.\"Bad quoting");
  42. }
  43. });
  44. QUnit.test('links', function(assert) {
  45. console.log("LINKS");
  46. assert.equal(t2l.convert("[Test with a open square bracket", "", ""), ("[Test with a open square bracket"));
  47. try{
  48. t2l.convert("[(Test with a open square bracket and parenthesis", "", "");
  49. }catch(err){
  50. assert.equal(err, "Missing ')' in link tag.<a href=\"Test with a open square bracket and parenthesis");
  51. }
  52. try{
  53. t2l.convert("[(Test without closing square bracket)", "", "");
  54. }catch(err){
  55. assert.equal(err, "Missing ')' in link tag.<a href=\"Test without closing square bracket)");
  56. }
  57. try{
  58. t2l.convert("[(Test with closing square bracket)]", "", "");
  59. }catch(err){
  60. assert.equal(err, "Missing ')' in link tag.<a href=\"Test with closing square bracket)]");
  61. }
  62. assert.equal(t2l.convert("[(Test with closing square bracket) ]", "", ""), "<a href=\"Test with closing square bracket\"></a>");
  63. assert.equal(t2l.convert("[() ]", "", ""), "<a href=\"\"></a>");
  64. assert.equal(t2l.convert("[( ) ]", "", ""), "<a href=\" \"></a>");
  65. try{
  66. t2l.convert("[(test\\) test with escaped char\\) ]", "", "");
  67. }catch(err){
  68. assert.equal(err, "Missing ')' in link tag.<a href=\"test\\) test with escaped char\\) ]");
  69. }
  70. assert.equal(t2l.convert("[(test\\) test with escaped char) ]", "", ""), "<a href=\"test) test with escaped char\"></a>");
  71. assert.equal(t2l.convert("[(test\\) test with escaped char) \\]sasdfasd]", "", ""), "<a href=\"test) test with escaped char\">]sasdfasd</a>");
  72. assert.equal(t2l.convert("[(test\\( test with escaped char) \\]sasdfasd]", "", ""), "<a href=\"test( test with escaped char\">]sasdfasd</a>");
  73. assert.equal(t2l.convert("\\([Test with closing square bracket) text", "", ""), "([Test with closing square bracket) text");
  74. assert.equal(t2l.convert("\\([ ([Test with closing square bracket] text)", "", ""), "([ <img alt=\"Test with closing square bracket\" src=\"text\">");
  75. });
  76. QUnit.test('images', function(assert) {
  77. console.log("IMAGES");
  78. assert.equal(t2l.convert("(Test with an open parenthesis", "", ""), ("(Test with an open parenthesis"));
  79. try{
  80. t2l.convert("([Test with a open square bracket and parenthesis", "", "");
  81. }catch(err){
  82. assert.equal(err, "Missing ']' in images tag.<img alt=\"Test with a open square bracket and parenthesis");
  83. }
  84. try{
  85. t2l.convert("([Test without closing square bracket]", "", "");
  86. }catch(err){
  87. assert.equal(err, "Missing ']' in images tag.<img alt=\"Test without closing square bracket]");
  88. }
  89. try{
  90. t2l.convert("([Test with closing square bracket])", "", "");
  91. }catch(err){
  92. assert.equal(err, "Missing ']' in images tag.<img alt=\"Test with closing square bracket])");
  93. }
  94. assert.equal(t2l.convert("([Test with closing square bracket] )", "", ""), "<img alt=\"Test with closing square bracket\" src=\"\">");
  95. assert.equal(t2l.convert("([] )", "", ""), "<img alt=\"\" src=\"\">");
  96. assert.equal(t2l.convert("([ ] )", "", ""), "<img alt=\" \" src=\"\">");
  97. try{
  98. t2l.convert("([test\\] test with escaped char\\] )", "", "");
  99. }catch(err){
  100. assert.equal(err, "Missing ']' in images tag.<img alt=\"test\\] test with escaped char\\] )");
  101. }
  102. assert.equal(t2l.convert("([test\\] test with escaped char] )", "", ""), "<img alt=\"test] test with escaped char\" src=\"\">");
  103. assert.equal(t2l.convert("([test\\] test with escaped char] \\)sasdfasd)", "", ""), "<img alt=\"test] test with escaped char\" src=\")sasdfasd\">");
  104. assert.equal(t2l.convert("\\([Test with closing square bracket) text", "", ""), "([Test with closing square bracket) text");
  105. assert.equal(t2l.convert("\\([ ([Test with closing square bracket] text)", "", ""), "([ <img alt=\"Test with closing square bracket\" src=\"text\">");
  106. });
  107. QUnit.test('blocks', function(assert) {
  108. console.log("BLOCKS");
  109. assert.equal(t2l.convert("{Test with an open parenthesis", "", ""), ("{Test with an open parenthesis"));
  110. try{
  111. t2l.convert("{(Test with a open square bracket and parenthesis", "", "");
  112. }catch(err){
  113. assert.equal(err, "Missing ')' in block tag.<div class=\"Test with a open square bracket and parenthesis");
  114. }
  115. try{
  116. t2l.convert("{(Test without closing square bracket)", "", "");
  117. }catch(err){
  118. assert.equal(err, "Missing ')' in block tag.<div class=\"Test without closing square bracket)");
  119. }
  120. try{
  121. t2l.convert("{(Test with closing square bracket)}", "", "")
  122. }catch(err){
  123. assert.equal(err, "Missing ')' in block tag.<div class=\"Test with closing square bracket)}");
  124. }
  125. assert.equal(t2l.convert("{(Test with closing square bracket) }", "", ""), "<div class=\"Test with closing square bracket\"></div>");
  126. assert.equal(t2l.convert("{() }", "", ""), "<div class=\"\"></div>");
  127. assert.equal(t2l.convert("{( ) }", "", ""), "<div class=\" \"></div>");
  128. try{
  129. t2l.convert("{(test\\) test with escaped char\\) }", "", "")
  130. }catch(err){
  131. assert.equal(err, "Missing ')' in block tag.<div class=\"test\\) test with escaped char\\) }");
  132. }
  133. assert.equal(t2l.convert("{(test\\) test with escaped char) }", "", ""), "<div class=\"test) test with escaped char\"></div>");
  134. assert.equal(t2l.convert("{(test\\) test with escaped char) \\}sasdfasd}", "", ""), "<div class=\"test) test with escaped char\">}sasdfasd</div>");
  135. assert.equal(t2l.convert("\\{(Test with closing square bracket) text", "", ""), "{(Test with closing square bracket) text");
  136. assert.equal(t2l.convert("\\{( {(Test with closing square bracket) text}", "", ""), "{( <div class=\"Test with closing square bracket\">text</div>");
  137. assert.equal(t2l.convert(" {() #This isn't a title}", "", ""), (" <div class=\"\">#This isn't a title</div>"));
  138. assert.equal(t2l.convert(" {(class) #This isn't a title}", "", ""), (" <div class=\"class\">#This isn't a title</div>"));
  139. assert.equal(t2l.convert(" {(class) \n #This is a title \n }", "", ""), (" <div class=\"class\"><h1>This is a title </h1>\n </div>"));
  140. try{
  141. t2l.convert(" {(class)#This isn't a title", "", "")
  142. }catch(err){
  143. assert.equal(err, "Missing ')' in block tag. <div class=\"class)#This isn't a title");
  144. }
  145. });
  146. QUnit.test('multiples unquoted tags', function(assert) {
  147. console.log("MULTIPLES UNQUOTED TAGS");
  148. assert.equal(t2l.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", ""), ("[Test with a open square bracket ( also parenthesis and { brackets"));
  149. assert.equal(t2l.convert("[(url) Test with a link ([alternative text] image url)] and {(class) brackets}", "", ""), ("<a href=\"url\">Test with a link <img alt=\"alternative text\" src=\"image url\"></a> and <div class=\"class\">brackets</div>"));
  150. assert.equal(t2l.convert("{(class) [(url) Test with a link ([alternative text] image url)] and brackets}", "", ""), ("<div class=\"class\"><a href=\"url\">Test with a link <img alt=\"alternative text\" src=\"image url\"></a> and brackets</div>"));
  151. });
  152. QUnit.test('table', function(assert) {
  153. console.log("TABLE");
  154. assert.equal(t2l.convert("| first cell | second cell |", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\n");
  155. assert.equal(t2l.convert("| first cell ", "", ""), "| first cell \n");
  156. try{
  157. t2l.convert("| first cell | second cell ", "", "");
  158. }catch(err){
  159. assert.equal(err, "Table not correctly written\nMaybe there's a whitespace at end of line first cell | second cell ");
  160. }
  161. assert.equal(t2l.convert("| first cell | second cell |\n| third cell | fourth cell |", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr><tr><td> third cell </td><td> fourth cell </td></tr></table>\n");
  162. assert.equal(t2l.convert("| first cell |\n| second cell | third cell |", "", ""), "<table><tr><td> first cell </td></tr><tr><td> second cell </td><td> third cell </td></tr></table>\n");
  163. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n");
  164. assert.equal(t2l.convert("Text adhoc for testing\n| a | b |\n| c | d |\n", "", ""), "Text adhoc for testing<table><tr><td> a </td><td> b </td></tr><tr><td> c </td><td> d </td></tr></table>\n");
  165. assert.equal(t2l.convert("Text adhoc for testing\n| a | b |\n| c | d |\nText adhoc for testing\n", "", ""), "Text adhoc for testing<table><tr><td> a </td><td> b </td></tr><tr><td> c </td><td> d </td></tr></table>\nText adhoc for testing");
  166. });
  167. QUnit.test('end_table', function(assert) {
  168. console.log("END TABLE");
  169. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n#Title1", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<h1>Title1</h1>\n");
  170. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n__\n--Item\n,,", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<ul>\n<li>Item</ul>\n");
  171. assert.equal(t2l.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", ""), "<ul>\n<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<li>Item</ul>\n");
  172. assert.equal(t2l.convert("__\n--Item\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n,,", "", ""), "<ul>\n<li>Item<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n</ul>\n");
  173. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<Test\n", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<code>Test</code>");
  174. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test\n", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<pre>Test</pre>\n");
  175. assert.equal(t2l.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test with pipe |\n", "", ""), "<table><tr><td> first cell </td><td> second cell </td></tr></table>\nText line<table><tr><td> third cell </td><td> fourth cell </td></tr></table>\n<pre>Test with pipe |</pre>\n");
  176. });
  177. QUnit.test('new line', function(assert) {
  178. console.log("NEW LINE");
  179. assert.equal(t2l.convert("Lorem Ipsum \n ", "", ""), ("Lorem Ipsum \n \n"));
  180. assert.equal(t2l.convert("First line\nLorem Ipsum \n ", "", ""), ("First lineLorem Ipsum \n \n"));
  181. assert.equal(t2l.convert("First line \nLorem Ipsum \n ", "", ""), ("First line \nLorem Ipsum \n \n"));
  182. assert.equal(t2l.convert("Lorem{(class) Ipsum} \n", "", ""), ("Lorem<div class=\"class\">Ipsum</div>\n"));
  183. assert.equal(t2l.convert("Lorem\nIpsum\nDolor\n", "", ""), ("LoremIpsumDolor"));
  184. assert.equal(t2l.convert("{(class) text}\n", "", ""), ("<div class=\"class\">text</div>"));
  185. assert.equal(t2l.convert("Lorem\n{(class) text}\nDolor\n", "", ""), ("Lorem<div class=\"class\">text</div>Dolor"));
  186. });
  187. QUnit.test('metatags', function(assert) {
  188. console.log("METATAGS");
  189. assert.equal(t2l.convert("<! Comment commenting things", "", ""), "");
  190. assert.equal(t2l.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing", "", ""), "Text adhoc for testing<code> metatag without space at end</code>Text adhoc for testing");
  191. assert.equal(t2l.convert("Text adhoc for testing \n< metatag without space at end\nText adhoc for testing", "", ""), "Text adhoc for testing \n<code> metatag without space at end</code>Text adhoc for testing");
  192. assert.equal(t2l.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing ", "", ""), "Text adhoc for testing<code> metatag without space at end</code>Text adhoc for testing \n");
  193. assert.equal(t2l.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing", "", ""), "Text adhoc for testing<pre> metatag with space at end</pre>\nText adhoc for testing");
  194. assert.equal(t2l.convert("Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing", "", ""), "Text adhoc for testing \n<pre> metatag with space at end</pre>\nText adhoc for testing");
  195. assert.equal(t2l.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing ", "", ""), "Text adhoc for testing<pre> metatag with space at end</pre>\nText adhoc for testing \n");
  196. assert.equal(t2l.convert("Text adhoc for testing\n<> embed with space at end\nText adhoc for testing ", "", ""), "Text adhoc for testing<div class=\"embed\"> embed with space at end</div>\nText adhoc for testing \n");
  197. });
  198. QUnit.test('misc.', function(assert) {
  199. console.log("MISC.");
  200. assert.equal(t2l.convert("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj", "", "")
  201. , ("alkasdfasdf \n<h1>This isn't a title</h1>\nksadjfañlskdfj"));
  202. assert.equal(t2l.convert("alkasdfasdf\n#This isn't a title\nksadjfañlskdfj", "", "")
  203. , "alkasdfasdf<h1>This isn't a title</h1>\nksadjfañlskdfj");
  204. assert.equal(t2l.convert("Text adhoc for testing\n{(class) container text } Text adhoc for testing ", "", ""), "Text adhoc for testing<div class=\"class\">container text </div> Text adhoc for testing\n");
  205. assert.equal(t2l.convert("Text adhoc for testing \n{(class) container text }\nText adhoc for testing ", "", ""), "Text adhoc for testing \n<div class=\"class\">container text </div>Text adhoc for testing \n");
  206. assert.equal(t2l.convert("Text adhoc for testing \n{(class) container text}Text adhoc for testing ", "", ""), "Text adhoc for testing \n<div class=\"class\">container text</div>Text adhoc for testing\n");
  207. assert.equal(t2l.convert("Paragraph without space at end\n< hello ", "", ""), "Paragraph without space at end<code> hello </code>");
  208. assert.equal(t2l.convert("Paragraph without space at end\n< hello without space at end\n lsdkjfgsñdlkfjñlk", "", ""), "Paragraph without space at end<code> hello without space at end</code> lsdkjfgsñdlkfjñlk");
  209. assert.equal(t2l.convert("Paragraph without space at end\n< hello ", "", ""), "Paragraph without space at end<code> hello </code>");
  210. });
  211. });