test.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "../../tedi2lang/dessert.hpp"
  2. #include "../../tedi2lang/tedi2lang.h"
  3. #include "../tedi2tex.h"
  4. #include "../../tedi2lang/exception.h"
  5. #include <string>
  6. #include <cstring>
  7. #include <iostream>
  8. int main(){
  9. tedi2tex td;
  10. //Empty string
  11. cout << "EMPTY STRINGS" << endl;
  12. dessert((td.convert("", "", "")) == (""));
  13. dessert(td.convert(" ", "", "") == (" \n\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", "", "") == ("paragraph\n\\section{This isn't a title}\n"));
  19. dessert(td.convert("#This isn't a title", "", "") == ("\\section{This isn't a title}\n"));
  20. dessert(td.convert(" #This isn't a title", "", "") == ("\\section{This isn't a title}\n"));
  21. dessert(td.convert("\t##This isn't a title", "", "") == ("\\subsection{This isn't a title}\n"));
  22. dessert(td.convert("##This isn't a title", "", "") == ("\\subsection{This isn't a title}\n"));
  23. dessert(td.convert("###This isn't a title", "", "") == ("\\subsubsection{This isn't a title}\n"));
  24. dessert(td.convert("####This isn't a title", "", "") == ("\\subsubsection{This isn't a title}\n"));
  25. dessert(td.convert("#####This isn't a title", "", "") == "\\subsubsection{This isn't a title}\n" );
  26. dessert(td.convert("#####This isn't a title", "", "") == "\\subsubsection{This isn't a title}\n" );
  27. cout << "LIST" << endl;
  28. dessert(td.convert("__", "", "") == ("\\begin{itemize}\n"));
  29. dessert(td.convert("--Text", "", "") == ("--Text\n"));
  30. dessert(td.convert(",,", "", "") == (",,\n"));
  31. dessert(td.convert("__\n--Text\n,,", "", "") == ("\\begin{itemize}\n\\item Text\n\\end{itemize}\n"));
  32. cout << "QUOTE" << endl;
  33. dessert(td.convert("\"Quoted text\"", "", "") == ("Quoted text\n"));
  34. dessert(throws(td.convert("\"Bad quoting", "", "")));
  35. cout << "LINKS" << endl;
  36. dessert(td.convert("[Test with a open square bracket", "", "") == ("[Test with a open square bracket\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) ]", "", "") == "\\href{Test with closing square bracket}{}\n");
  41. dessert(td.convert("[() ]", "", "") == "\\href{}{}\n");
  42. dessert(td.convert("[( ) ]", "", "") == "\\href{ }{}\n");
  43. dessert(throws(td.convert("[(test\\) test with escaped char\\) ]", "", "")));
  44. dessert(td.convert("[(test\\) test with escaped char) ]", "", "") == "\\href{test) test with escaped char}{}\n");
  45. dessert(td.convert("[(test\\) test with escaped char) \\]sasdfasd]", "", "") == "\\href{test) test with escaped char}{]sasdfasd}\n");
  46. dessert(td.convert("[(test\\( test with escaped char) \\]sasdfasd]", "", "") == "\\href{test( test with escaped char}{]sasdfasd}\n");
  47. dessert(td.convert("\\[(Test with closing square bracket) text", "", "") == "[(Test with closing square bracket) text\n");
  48. dessert(td.convert("\\[( [(Test with closing square bracket) text]", "", "") == "[( \\href{Test with closing square bracket}{text}\n");
  49. cout << "IMAGES" << endl;
  50. dessert(td.convert("(Test with an open parenthesis", "", "") == ("(Test with an open parenthesis\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] )", "", "") == "\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{}\n\\caption{Test with closing square bracket}\n\\end{figure}\n");
  55. dessert(td.convert("([] )", "", "") == "\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{}\n\\caption{}\n\\end{figure}\n");
  56. dessert(td.convert("([ ] )", "", "") == "\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{}\n\\caption{ }\n\\end{figure}\n");
  57. dessert(throws(td.convert("([test\\] test with escaped char\\] )", "", "")));
  58. dessert(td.convert("([test\\] test with escaped char] )", "", "") == "\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{}\n\\caption{test] test with escaped char}\n\\end{figure}\n");
  59. dessert(td.convert("([test\\] test with escaped char] \\)sasdfasd)", "", "") == "\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{)sasdfasd}\n\\caption{test] test with escaped char}\n\\end{figure}\n");
  60. dessert(td.convert("\\([Test with closing square bracket) text", "", "") == "([Test with closing square bracket) text\n");
  61. dessert(td.convert("\\([ ([Test with closing square bracket] text)", "", "") == "([ \\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{text}\n\\caption{Test with closing square bracket}\n\\end{figure}\n");
  62. cout << "BLOCKS" << endl;
  63. dessert(td.convert("{Test with an open parenthesis", "", "") == ("{Test with an open parenthesis\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) }", "", "") == "\n");
  68. dessert(td.convert("{() }", "", "") == "\n");
  69. dessert(td.convert("{( ) }", "", "") == "\n");
  70. dessert(throws(td.convert("{(test\\) test with escaped char\\) }", "", "")));
  71. dessert(td.convert("{(test\\) test with escaped char) }", "", "") == "\n");
  72. dessert(td.convert("{(test\\) test with escaped char) \\}sasdfasd}", "", "") == "}sasdfasd\n");
  73. dessert(td.convert("\\{(Test with closing square bracket) text", "", "") == "{(Test with closing square bracket) text\n");
  74. dessert(td.convert("\\{( {(Test with closing square bracket) text}", "", "") == "{( text\n");
  75. cout << "MULTIPLES UNQUOTED TAGS" << endl;
  76. dessert(td.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", "") == ("[Test with a open square bracket ( also parenthesis and { brackets\n"));
  77. dessert(td.convert("[(url) Test with a link ([alternative text] image url)] and {(class) brackets}", "", "") == ("\\href{url}{Test with a link \\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{image url}\n\\caption{alternative text}\n\\end{figure}} and brackets\n"));
  78. dessert(td.convert("{(class) [(url) Test with a link ([alternative text] image url)] and brackets}", "", "") == ("\\href{url}{Test with a link \\begin{figure}[h!]\n\\centering\n\\includegraphics[width=1\\textwidth]{image url}\n\\caption{alternative text}\n\\end{figure}} and brackets\n"));
  79. cout << "TABLE" << endl;
  80. dessert(td.convert("| first cell | second cell |", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n");
  81. dessert(td.convert("| first cell ", "", "") == "| first cell \n\n");
  82. dessert(throws(td.convert("| first cell | second cell ", "", "")));
  83. dessert(td.convert("| first cell | second cell |\n| third cell | fourth cell |", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n");
  84. dessert(td.convert("| first cell |\n| second cell | third cell |", "", "") == "\\begin{longtable}{|p{0.900000\\linewidth}|}\n\\hline\n first cell \\tabularnewline\n\\hline\n second cell & third cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n");
  85. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n");
  86. dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\n", "", "") == "Text adhoc for testing\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n a & b \\tabularnewline\n\\hline\n c & d \\tabularnewline\n\\hline\n\\end{longtable}\n\n");
  87. dessert(td.convert("Text adhoc for testing\n| a | b |\n| c | d |\nText adhoc for testing\n", "", "") == "Text adhoc for testing\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n a & b \\tabularnewline\n\\hline\n c & d \\tabularnewline\n\\hline\n\\end{longtable}\n\nText adhoc for testing\n");
  88. dessert(td.convert(" {() #This isn't a title}", "", "") == (" #This isn't a title\n"));
  89. dessert(td.convert(" {(class) #This isn't a title}", "", "") == (" #This isn't a title\n"));
  90. dessert(td.convert(" {(class) \n #This is a title \n }", "", "") == (" \n\n\\section{This is a title }\n \n\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", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\section{Title1}\n");
  94. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n__\n--Item\n,,", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\begin{itemize}\n\\item Item\n\\end{itemize}\n");
  95. dessert(td.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", "") == "\\begin{itemize}\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\item Item\n\\end{itemize}\n");
  96. dessert(td.convert("__\n--Item\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n,,", "", "") == "\\begin{itemize}\n\\item Item\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\end{itemize}\n");
  97. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<Test\n", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\verb!Test!\n");
  98. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test\n", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\begin{verbatim}\nTest\n\\end{verbatim}\n\n");
  99. dessert(td.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test with pipe |\n", "", "") == "\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n first cell & second cell \\tabularnewline\n\\hline\n\\end{longtable}\n\nText line\n\\begin{longtable}{|p{0.450000\\linewidth}|p{0.450000\\linewidth}|}\n\\hline\n third cell & fourth cell \\tabularnewline\n\\hline\n\\end{longtable}\n\n\\begin{verbatim}\nTest with pipe |\n\\end{verbatim}\n\n");
  100. cout << "NEW LINE" << endl;
  101. dessert(td.convert("Lorem Ipsum \n ", "", "") == ("Lorem Ipsum \n\n \n\n"));
  102. dessert(td.convert("First line\nLorem Ipsum \n ", "", "") == ("First line\nLorem Ipsum \n\n \n\n"));
  103. dessert(td.convert("First line \nLorem Ipsum \n ", "", "") == ("First line \n\nLorem Ipsum \n\n \n\n"));
  104. dessert(td.convert("Lorem{(class) Ipsum} \n", "", "") == ("LoremIpsum \n\n"));
  105. dessert(td.convert("Lorem\nIpsum\nDolor\n", "", "") == ("Lorem\nIpsum\nDolor\n"));
  106. dessert(td.convert("{(class) text}\n", "", "") == ("text\n"));
  107. dessert(td.convert("Lorem\n{(class) text}\nDolor\n", "", "") == ("Lorem\ntext\nDolor\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", "", "") == "Text adhoc for testing\n\\verb! metatag without space at end!\nText adhoc for testing\n");
  111. dessert(td.convert("Text adhoc for testing \n< metatag without space at end\nText adhoc for testing", "", "") == "Text adhoc for testing \n\n\\verb! metatag without space at end!\nText adhoc for testing\n");
  112. dessert(td.convert("Text adhoc for testing\n< metatag without space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n\\verb! metatag without space at end!\nText adhoc for testing \n\n");
  113. dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing", "", "") == "Text adhoc for testing\n\\begin{verbatim}\n metatag with space at end\n\\end{verbatim}\n\nText adhoc for testing\n");
  114. dessert(td.convert("Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing", "", "") == "Text adhoc for testing \n\n\\begin{verbatim}\n metatag with space at end\n\\end{verbatim}\n\nText adhoc for testing\n");
  115. dessert(td.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n\\begin{verbatim}\n metatag with space at end\n\\end{verbatim}\n\nText adhoc for testing \n\n");
  116. dessert(td.convert("Text adhoc for testing\n<> embed with space at end\nText adhoc for testing ", "", "") == "Text adhoc for testing\n embed with space at end\nText adhoc for testing \n\n");
  117. cout << "MISC." << endl;
  118. dessert(td.convert("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj", "", "")
  119. == ("alkasdfasdf \n\n\\section{This isn't a title}\nksadjfañlskdfj\n"));
  120. dessert(td.convert("alkasdfasdf\n#This isn't a title\nksadjfañlskdfj", "", "")
  121. == "alkasdfasdf\n\\section{This isn't a title}\nksadjfañlskdfj\n");
  122. dessert(td.convert("Text adhoc for testing\n{(class) container text } Text adhoc for testing ", "", "") == "Text adhoc for testing\ncontainer text Text adhoc for testing \n\n");
  123. dessert(td.convert("Text adhoc for testing \n{(class) container text }\nText adhoc for testing ", "", "") == "Text adhoc for testing \n\ncontainer text \n\nText adhoc for testing \n\n");
  124. dessert(td.convert("Text adhoc for testing \n{(class) container text}Text adhoc for testing ", "", "") == "Text adhoc for testing \n\ncontainer textText adhoc for testing \n\n");
  125. dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "Paragraph without space at end\n\\verb! hello !\n");
  126. dessert(td.convert("Paragraph without space at end\n< hello without space at end\n lsdkjfgsñdlkfjñlk", "", "") == "Paragraph without space at end\n\\verb! hello without space at end!\n lsdkjfgsñdlkfjñlk\n");
  127. dessert(td.convert("Paragraph without space at end\n< hello ", "", "") == "Paragraph without space at end\n\\verb! hello !\n");
  128. cout << "TEST FOR THIS MODULE ONLY" << endl;
  129. dessert(td.convert("< hello! ", "", "") == "\\verb{ hello! }\n");
  130. dessert(td.convert("< hello¡ ", "", "") == "\\verb{ hello¡ }\n");
  131. dessert(td.convert("< hello} ", "", "") == "\\verb! hello} !\n");
  132. dessert(td.convert("< hello{ ", "", "") == "\\verb! hello{ !\n");
  133. dessert(td.convert("< hello!{ ", "", "") == "\\begin{verbatim}\n hello!{ \n\\end{verbatim}\n\n");
  134. }