test.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "../../tedi2lang/dessert.hpp"
  2. #include "../../tedi2lang/tedi2lang.h"
  3. #include "../tedi2html.h"
  4. #include "../../tedi2lang/exception.h"
  5. #include <string>
  6. #include <cstring>
  7. #include <iostream>
  8. int main(){
  9. tedi2html td;
  10. //Empty string
  11. cout << "EMPTY STRINGS" << endl;
  12. dessert((td.convert("", "", "")) == (""));
  13. dessert(td.convert(" ", "", "") == (" \n"));
  14. dessert(td.convert("\n\n\n", "", "") == ("\n\n\n"));
  15. //Titles
  16. cout << "TITLES" << endl;
  17. dessert(throws(td.convert("#####", "", "")));
  18. dessert(td.convert("paragraph\n#This isn't a title", "", "") == ("<p>paragraph\n</p>\n<h1>This isn't a title</h1>\n"));
  19. dessert(td.convert("#This isn't a title", "", "") == ("<h1>This isn't a title</h1>\n"));
  20. dessert(td.convert(" #This isn't a title", "", "") == ("<h1>This isn't a title</h1>\n"));
  21. dessert(td.convert("\t##This isn't a title", "", "") == ("<h2>This isn't a title</h2>\n"));
  22. dessert(td.convert("##This isn't a title", "", "") == ("<h2>This isn't a title</h2>\n"));
  23. dessert(td.convert("###This isn't a title", "", "") == ("<h3>This isn't a title</h3>\n"));
  24. dessert(td.convert("####This isn't a title", "", "") == ("<h4>This isn't a title</h4>\n"));
  25. dessert(td.convert("#####This isn't a title", "", "") == "<h4>This isn't a title</h4>\n" );
  26. dessert(td.convert("#####This isn't a title", "", "") == "<h4>This isn't a title</h4>\n" );
  27. cout << "LIST" << endl;
  28. dessert(td.convert("__", "", "") == ("<ul>\n"));
  29. dessert(td.convert("--Text", "", "") == ("<p>--Text\n</p>\n"));
  30. dessert(td.convert(",,", "", "") == ("<p>,,\n</p>\n"));
  31. dessert(td.convert("__\n--Text\n,,", "", "") == ("<ul>\n<li>Text\n</ul>\n"));
  32. cout << "QUOTE" << endl;
  33. dessert(td.convert("\"Quoted text\"", "", "") == ("<p>Quoted text\n</p>\n"));
  34. dessert(throws(td.convert("\"Bad quoting", "", "")));
  35. cout << "LINKS" << endl;
  36. dessert(td.convert("[Test with a open square bracket", "", "") == ("<p>[Test with a open square bracket\n</p>\n"));
  37. dessert(throws(td.convert("[(Test with a open square bracket and parenthesis", "", "")));
  38. dessert(throws(td.convert("[(Test without closing square bracket)", "", "")));
  39. dessert(throws(td.convert("[(Test with closing square bracket)]", "", "")));
  40. dessert(td.convert("[(Test with closing square bracket) ]", "", "") == "<p><a href=\"Test with closing square bracket\"></a>\n</p>\n");
  41. dessert(td.convert("[() ]", "", "") == "<p><a href=\"\"></a>\n</p>\n");
  42. dessert(td.convert("[( ) ]", "", "") == "<p><a href=\" \"></a>\n</p>\n");
  43. dessert(throws(td.convert("[(test\\) test with escaped char\\) ]", "", "")));
  44. dessert(td.convert("[(test\\) test with escaped char) ]", "", "") == "<p><a href=\"test) test with escaped char\"></a>\n</p>\n");
  45. dessert(td.convert("[(test\\) test with escaped char) \\]sasdfasd]", "", "") == "<p><a href=\"test) test with escaped char\">]sasdfasd</a>\n</p>\n");
  46. dessert(td.convert("[(test\\( test with escaped char) \\]sasdfasd]", "", "") == "<p><a href=\"test( test with escaped char\">]sasdfasd</a>\n</p>\n");
  47. dessert(td.convert("\\([Test with closing square bracket) text", "", "") == "<p>([Test with closing square bracket) text\n</p>\n");
  48. dessert(td.convert("\\([ ([Test with closing square bracket] text)", "", "") == "<p>([ <img alt=\"Test with closing square bracket\" src=\"text\">\n</p>\n");
  49. cout << "IMAGES" << endl;
  50. dessert(td.convert("(Test with an open parenthesis", "", "") == ("<p>(Test with an open parenthesis\n</p>\n"));
  51. dessert(throws(td.convert("([Test with a open square bracket and parenthesis", "", "")));
  52. dessert(throws(td.convert("([Test without closing square bracket]", "", "")));
  53. dessert(throws(td.convert("([Test with closing square bracket])", "", "")));
  54. dessert(td.convert("([Test with closing square bracket] )", "", "") == "<p><img alt=\"Test with closing square bracket\" src=\"\">\n</p>\n");
  55. dessert(td.convert("([] )", "", "") == "<p><img alt=\"\" src=\"\">\n</p>\n");
  56. dessert(td.convert("([ ] )", "", "") == "<p><img alt=\" \" src=\"\">\n</p>\n");
  57. dessert(throws(td.convert("([test\\] test with escaped char\\] )", "", "")));
  58. dessert(td.convert("([test\\] test with escaped char] )", "", "") == "<p><img alt=\"test] test with escaped char\" src=\"\">\n</p>\n");
  59. dessert(td.convert("([test\\] test with escaped char] \\)sasdfasd)", "", "") == "<p><img alt=\"test] test with escaped char\" src=\")sasdfasd\">\n</p>\n");
  60. dessert(td.convert("\\([Test with closing square bracket) text", "", "") == "<p>([Test with closing square bracket) text\n</p>\n");
  61. dessert(td.convert("\\([ ([Test with closing square bracket] text)", "", "") == "<p>([ <img alt=\"Test with closing square bracket\" src=\"text\">\n</p>\n");
  62. cout << "BLOCKS" << endl;
  63. dessert(td.convert("{Test with an open parenthesis", "", "") == ("<p>{Test with an open parenthesis\n</p>\n"));
  64. dessert(throws(td.convert("{(Test with a open square bracket and parenthesis", "", "")));
  65. dessert(throws(td.convert("{(Test without closing square bracket)", "", "")));
  66. dessert(throws(td.convert("{(Test with closing square bracket)}", "", "")));
  67. dessert(td.convert("{(Test with closing square bracket) }", "", "") == "<div class=\"Test with closing square bracket\"></div>\n");
  68. dessert(td.convert("{() }", "", "") == "<div class=\"\"></div>\n");
  69. dessert(td.convert("{( ) }", "", "") == "<div class=\" \"></div>\n");
  70. dessert(throws(td.convert("{(test\\) test with escaped char\\) }", "", "")));
  71. dessert(td.convert("{(test\\) test with escaped char) }", "", "") == "<div class=\"test) test with escaped char\"></div>\n");
  72. dessert(td.convert("{(test\\) test with escaped char) \\}sasdfasd}", "", "") == "<div class=\"test) test with escaped char\">}sasdfasd</div>\n");
  73. dessert(td.convert("\\{(Test with closing square bracket) text", "", "") == "<p>{(Test with closing square bracket) text\n</p>\n");
  74. dessert(td.convert("\\{( {(Test with closing square bracket) text}", "", "") == "{( <div class=\"Test with closing square bracket\">text</div>\n");
  75. cout << "MULTIPLES UNQUOTED TAGS" << endl;
  76. dessert(td.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", "") == ("<p>[Test with a open square bracket ( also parenthesis and { brackets\n</p>\n"));
  77. dessert(td.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>\n"));
  78. dessert(td.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>\n"));
  79. cout << "TABLE" << endl;
  80. dessert(td.convert("| first cell | second cell |", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n");
  81. dessert(td.convert("| first cell ", "", "") == "<p>| first cell </p>\n");
  82. dessert(throws(td.convert("| first cell | second cell ", "", "")));
  83. dessert(td.convert("| first cell | second cell |\n| third cell | fourth cell |", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n");
  84. dessert(td.convert("| first cell |\n| second cell | third cell |", "", "") == "<table>\n<tr>\n<td> first cell </td>\n</tr>\n<tr>\n<td> second cell </td>\n<td> third cell </td>\n</tr>\n</table>\n");
  85. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n");
  86. dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\n", "", "") == "<p>Text adhoc for testing\n</p>\n<table>\n<tr>\n<td> a </td>\n<td> b </td>\n</tr>\n<tr>\n<td> c </td>\n<td> d </td>\n</tr>\n</table>\n");
  87. dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\nText adhoc for testing\n", "", "") == "<p>Text adhoc for testing\n</p>\n<table>\n<tr>\n<td> a </td>\n<td> b </td>\n</tr>\n<tr>\n<td> c </td>\n<td> d </td>\n</tr>\n</table>\n<p>Text adhoc for testing\n</p>\n");
  88. dessert(td.convert(" {() #This isn't a title}", "", "") == (" <div class=\"\">#This isn't a title</div>\n"));
  89. dessert(td.convert(" {(class) #This isn't a title}", "", "") == (" <div class=\"class\">#This isn't a title</div>\n"));
  90. dessert(td.convert(" {(class) \n #This is a title \n }", "", "") == (" <div class=\"class\">\n<h1>This is a title </h1>\n </div>\n"));
  91. dessert(throws(td.convert(" {(class)#This isn't a title", "", "")));
  92. cout << "END TABLE" << endl;
  93. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n#Title1", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n<h1>Title1</h1>\n");
  94. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n__\n--Item\n,,", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n<ul>\n<li>Item\n</ul>\n");
  95. dessert(td.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", "") == "<ul>\n<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\nText line\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n<li>Item\n</ul>\n");
  96. dessert(td.convert("__\n--Item\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n,,", "", "") == "<ul>\n<li>Item\n<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\nText line\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n</ul>\n");
  97. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<Test\n", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\nTest\n");
  98. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test\n", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n<p>Test</p>\n");
  99. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test with pipe |\n", "", "") == "<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n<p>Text line\n</p>\n<table>\n<tr>\n<td> third cell </td>\n<td> fourth cell </td>\n</tr>\n</table>\n<p>Test with pipe |</p>\n");
  100. cout << "NEW LINE" << endl;
  101. dessert(td.convert("Lorem Ipsum \n ", "", "") == ("<p>Lorem Ipsum </p>\n \n"));
  102. dessert(td.convert("First line\nLorem Ipsum \n ", "", "") == ("<p>First line\nLorem Ipsum </p>\n \n"));
  103. dessert(td.convert("First line \nLorem Ipsum \n ", "", "") == ("<p>First line </p>\n<p>Lorem Ipsum </p>\n \n"));
  104. dessert(td.convert("Lorem{(class) Ipsum} \n", "", "") == ("Lorem<div class=\"class\">Ipsum</div> \n"));
  105. dessert(td.convert("Lorem\nIpsum\nDolor\n", "", "") == ("<p>Lorem\nIpsum\nDolor\n</p>\n"));
  106. dessert(td.convert("{(class) text}\n", "", "") == ("<div class=\"class\">text</div>\n"));
  107. dessert(td.convert("Lorem\n{(class) text}\nDolor\n", "", "") == ("<p>Lorem\n</p>\n<div class=\"class\">text</div>\n<p>Dolor\n</p>\n"));
  108. cout << "METATAGS" << endl;
  109. dessert(td.convert("<! Comment commenting things", "", "") == "");
  110. dessert(td.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing", "", "") == "<p>Text adhoc for testing\n metatag without space at end\nText adhoc for testing\n</p>\n");
  111. dessert(td.convert("Text adhoc for testing \n< metatag without space at end\nText adhoc for testing", "", "") == "<p>Text adhoc for testing </p>\n metatag without space at end\n<p>Text adhoc for testing\n</p>\n");
  112. dessert(td.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing ", "", "") == "<p>Text adhoc for testing\n metatag without space at end\nText adhoc for testing </p>\n");
  113. dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing", "", "") == "<p>Text adhoc for testing\n metatag with space at end</p>\n<p>Text adhoc for testing\n</p>\n");
  114. dessert(td.convert("Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing", "", "") == "<p>Text adhoc for testing </p>\n<p> metatag with space at end</p>\n<p>Text adhoc for testing\n</p>\n");
  115. dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing ", "", "") == "<p>Text adhoc for testing\n metatag with space at end</p>\n<p>Text adhoc for testing </p>\n");
  116. dessert(td.convert("Text adhoc for testing\n<> embed with space at end\nText adhoc for testing ", "", "") == "<p>Text adhoc for testing\n embed with space at end\nText adhoc for testing </p>\n");
  117. cout << "MISC." << endl;
  118. dessert(td.convert("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj", "", "")
  119. == ("<p>alkasdfasdf </p>\n<h1>This isn't a title</h1>\n<p>ksadjfañlskdfj\n</p>\n"));
  120. dessert(td.convert("alkasdfasdf\n#This isn't a title\nksadjfañlskdfj", "", "")
  121. == "<p>alkasdfasdf\n</p>\n<h1>This isn't a title</h1>\n<p>ksadjfañlskdfj\n</p>\n");
  122. dessert(td.convert("Text adhoc for testing\n{(class) container text } Text adhoc for testing ", "", "") == "<p>Text adhoc for testing\n</p>\n<div class=\"class\">container text </div> Text adhoc for testing \n");
  123. dessert(td.convert("Text adhoc for testing \n{(class) container text }\nText adhoc for testing ", "", "") == "<p>Text adhoc for testing </p>\n<div class=\"class\">container text </div>\n<p>Text adhoc for testing </p>\n");
  124. dessert(td.convert("Text adhoc for testing \n{(class) container text}Text adhoc for testing ", "", "") == "<p>Text adhoc for testing </p>\n<div class=\"class\">container text</div>Text adhoc for testing \n");
  125. dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "<p>Paragraph without space at end\n hello \n</p>\n");
  126. dessert(td.convert("Paragraph without space at end\n< hello without space at end\n lsdkjfgsñdlkfjñlk", "", "") == "<p>Paragraph without space at end\n hello without space at end\n lsdkjfgsñdlkfjñlk\n</p>\n");
  127. dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "<p>Paragraph without space at end\n hello \n</p>\n");
  128. }