test_tedi2tex.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. t2t = new tedi2tex();
  2. QUnit.module('tedi2tex', function() {
  3. QUnit.test('convert initial line text', function(assert) {
  4. //Empty string
  5. console.log("EMPTY STRINGS");
  6. assert.equal((t2t.convert("", "", "")), (""));
  7. assert.equal(t2t.convert(" ", "", ""), (" \n\n"));
  8. assert.equal(t2t.convert("\n\n\n", "", ""), ("\n\n\n"));
  9. });
  10. QUnit.test('titles', function(assert) {
  11. //Titles
  12. console.log("TITLES");
  13. try{
  14. t2t.convert("#####", "", "");
  15. }catch(err) {
  16. assert.equal(err, "Unexpected heading size#####");
  17. }
  18. assert.equal(t2t.convert("paragraph\n#This isn't a title", "", ""), ("paragraph\n\\section{This isn't a title}\n"));
  19. assert.equal(t2t.convert("#This isn't a title", "", ""), ("\\section{This isn't a title}\n"));
  20. assert.equal(t2t.convert(" #This isn't a title", "", ""), ("\\section{This isn't a title}\n"));
  21. assert.equal(t2t.convert("\t##This isn't a title", "", ""), ("\\subsection{This isn't a title}\n"));
  22. assert.equal(t2t.convert("##This isn't a title", "", ""), ("\\subsection{This isn't a title}\n"));
  23. assert.equal(t2t.convert("###This isn't a title", "", ""), ("\\subsubsection{This isn't a title}\n"));
  24. assert.equal(t2t.convert("####This isn't a title", "", ""), ("\\subsubsection{This isn't a title}\n"));
  25. assert.equal(t2t.convert("#####This isn't a title", "", ""), "\\subsubsection{This isn't a title}\n" );
  26. assert.equal(t2t.convert("#####This isn't a title", "", ""), "\\subsubsection{This isn't a title}\n" );
  27. });
  28. QUnit.test('list', function(assert) {
  29. console.log("LIST");
  30. assert.equal(t2t.convert("__", "", ""), ("\\begin{itemize}\n"));
  31. assert.equal(t2t.convert("--Text", "", ""), ("--Text\n"));
  32. assert.equal(t2t.convert(",,", "", ""), (",,\n"));
  33. assert.equal(t2t.convert("__\n--Text\n,,", "", ""), ("\\begin{itemize}\n\\item Text\n\\end{itemize}\n"));
  34. });
  35. QUnit.test('quotes', function(assert) {
  36. console.log("QUOTE");
  37. assert.equal(t2t.convert("\"Quoted text\"", "", ""), ("Quoted text\n"));
  38. try{
  39. t2t.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(t2t.convert("[Test with a open square bracket", "", ""), ("[Test with a open square bracket\n"));
  47. try{
  48. t2t.convert("[(Test with a open square bracket and parenthesis", "", "");
  49. }catch(err){
  50. assert.equal(err, "Missing ')' in link tag.\\href{Test with a open square bracket and parenthesis");
  51. }
  52. try{
  53. t2t.convert("[(Test without closing square bracket)", "", "");
  54. }catch(err){
  55. assert.equal(err, "Missing ')' in link tag.\\href{Test without closing square bracket)");
  56. }
  57. try{
  58. t2t.convert("[(Test with closing square bracket)]", "", "");
  59. }catch(err){
  60. assert.equal(err, "Missing ')' in link tag.\\href{Test with closing square bracket)]");
  61. }
  62. assert.equal(t2t.convert("[(Test with closing square bracket) ]", "", ""), "\\href{Test with closing square bracket}{}\n");
  63. assert.equal(t2t.convert("[() ]", "", ""), "\\href{}{}\n");
  64. assert.equal(t2t.convert("[( ) ]", "", ""), "\\href{ }{}\n");
  65. try{
  66. t2t.convert("[(test\\) test with escaped char\\) ]", "", "");
  67. }catch(err){
  68. assert.equal(err, "Missing ')' in link tag.\\href{test\\) test with escaped char\\) ]");
  69. }
  70. assert.equal(t2t.convert("[(test\\) test with escaped char) ]", "", ""), "\\href{test) test with escaped char}{}\n");
  71. assert.equal(t2t.convert("[(test\\) test with escaped char) \\]sasdfasd]", "", ""), "\\href{test) test with escaped char}{]sasdfasd}\n");
  72. assert.equal(t2t.convert("[(test\\( test with escaped char) \\]sasdfasd]", "", ""), "\\href{test( test with escaped char}{]sasdfasd}\n");
  73. assert.equal(t2t.convert("\\([Test with closing square bracket) text", "", ""), "([Test with closing square bracket) text\n");
  74. assert.equal(t2t.convert("\\([ ([Test with closing square bracket] text)", "", ""),
  75. `([ \\begin{figure}[h!]
  76. \\centering
  77. \\includegraphics[width=1\\textwidth]{text}
  78. \\caption{Test with closing square bracket}
  79. \\end{figure}\n`);
  80. });
  81. QUnit.test('images', function(assert) {
  82. console.log("IMAGES");
  83. assert.equal(t2t.convert("(Test with an open parenthesis", "", ""), ("(Test with an open parenthesis\n"));
  84. try{
  85. t2t.convert("([Test with a open square bracket and parenthesis", "", "");
  86. }catch(err){
  87. assert.equal(err, "Missing ']' in images tag.Test with a open square bracket and parenthesis");
  88. }
  89. try{
  90. t2t.convert("([Test without closing square bracket]", "", "");
  91. }catch(err){
  92. assert.equal(err, "Missing ']' in images tag.Test without closing square bracket]");
  93. }
  94. try{
  95. t2t.convert("([Test with closing square bracket])", "", "");
  96. }catch(err){
  97. assert.equal(err, "Missing ']' in images tag.Test with closing square bracket])");
  98. }
  99. assert.equal(t2t.convert("([Test with closing square bracket] )", "", ""), `\\begin{figure}[h!]
  100. \\centering
  101. \\includegraphics[width=1\\textwidth]{}
  102. \\caption{Test with closing square bracket}
  103. \\end{figure}\n`);
  104. assert.equal(t2t.convert("([] )", "", ""), `\\begin{figure}[h!]
  105. \\centering
  106. \\includegraphics[width=1\\textwidth]{}
  107. \\caption{}
  108. \\end{figure}\n`);
  109. assert.equal(t2t.convert("([ ] )", "", ""), `\\begin{figure}[h!]
  110. \\centering
  111. \\includegraphics[width=1\\textwidth]{}
  112. \\caption{ }
  113. \\end{figure}\n`);
  114. try{
  115. t2t.convert("([test\\] test with escaped char\\] )", "", "");
  116. }catch(err){
  117. assert.equal(err, "Missing ']' in images tag.test\\] test with escaped char\\] )");
  118. }
  119. assert.equal(t2t.convert("([test\\] test with escaped char] )", "", ""), `\\begin{figure}[h!]
  120. \\centering
  121. \\includegraphics[width=1\\textwidth]{}
  122. \\caption{test] test with escaped char}
  123. \\end{figure}\n`);
  124. assert.equal(t2t.convert("([test\\] test with escaped char] \\)sasdfasd)", "", ""), `\\begin{figure}[h!]
  125. \\centering
  126. \\includegraphics[width=1\\textwidth]{)sasdfasd}
  127. \\caption{test] test with escaped char}
  128. \\end{figure}\n`);
  129. assert.equal(t2t.convert("\\([Test with closing square bracket) text", "", ""), "([Test with closing square bracket) text\n");
  130. assert.equal(t2t.convert("\\([ ([Test with closing square bracket] text)", "", ""), `([ \\begin{figure}[h!]
  131. \\centering
  132. \\includegraphics[width=1\\textwidth]{text}
  133. \\caption{Test with closing square bracket}
  134. \\end{figure}\n`);
  135. });
  136. QUnit.test('blocks', function(assert) {
  137. console.log("BLOCKS");
  138. assert.equal(t2t.convert("{Test with an open parenthesis", "", ""), ("{Test with an open parenthesis\n"));
  139. try{
  140. t2t.convert("{(Test with a open square bracket and parenthesis", "", "");
  141. }catch(err){
  142. assert.equal(err, "Missing ')' in block tag.Test with a open square bracket and parenthesis");
  143. }
  144. try{
  145. t2t.convert("{(Test without closing square bracket)", "", "");
  146. }catch(err){
  147. assert.equal(err, "Missing ')' in block tag.Test without closing square bracket)");
  148. }
  149. try{
  150. t2t.convert("{(Test with closing square bracket)}", "", "")
  151. }catch(err){
  152. assert.equal(err, "Missing ')' in block tag.Test with closing square bracket)}");
  153. }
  154. assert.equal(t2t.convert("{(Test with closing square bracket) }", "", ""), "\n");
  155. assert.equal(t2t.convert("{() }", "", ""), "\n");
  156. assert.equal(t2t.convert("{( ) }", "", ""), "\n");
  157. try{
  158. t2t.convert("{(test\\) test with escaped char\\) }", "", "")
  159. }catch(err){
  160. assert.equal(err, "Missing ')' in block tag.test\\) test with escaped char\\) }");
  161. }
  162. assert.equal(t2t.convert("{(test\\) test with escaped char) }", "", ""), "\n");
  163. assert.equal(t2t.convert("{(test\\) test with escaped char) \\}sasdfasd}", "", ""), "}sasdfasd\n");
  164. assert.equal(t2t.convert("\\{(Test with closing square bracket) text", "", ""), "{(Test with closing square bracket) text\n");
  165. assert.equal(t2t.convert("\\{( {(Test with closing square bracket) text}", "", ""), "{( text\n");
  166. assert.equal(t2t.convert(" {() #This isn't a title}", "", ""), (" #This isn't a title\n"));
  167. assert.equal(t2t.convert(" {(class) #This isn't a title}", "", ""), (" #This isn't a title\n"));
  168. assert.equal(t2t.convert(" {(class) \n #This is a title \n }", "", ""), (" \n\n\\section{This is a title }\n \n\n"));
  169. try{
  170. t2t.convert(" {(class)#This isn't a title", "", "")
  171. }catch(err){
  172. assert.equal(err, "Missing ')' in block tag. class)#This isn't a title");
  173. }
  174. });
  175. QUnit.test('multiples unquoted tags', function(assert) {
  176. console.log("MULTIPLES UNQUOTED TAGS");
  177. assert.equal(t2t.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", ""), ("[Test with a open square bracket ( also parenthesis and { brackets\n"));
  178. assert.equal(t2t.convert("[(url) Test with a link ([alternative text] image url)] and {(class) brackets}", "", ""), (`\\href{url}{Test with a link \\begin{figure}[h!]
  179. \\centering
  180. \\includegraphics[width=1\\textwidth]{image url}
  181. \\caption{alternative text}
  182. \\end{figure}} and brackets\n`));
  183. assert.equal(t2t.convert("{(class) [(url) Test with a link ([alternative text] image url)] and brackets}", "", ""), (`\\href{url}{Test with a link \\begin{figure}[h!]
  184. \\centering
  185. \\includegraphics[width=1\\textwidth]{image url}
  186. \\caption{alternative text}
  187. \\end{figure}} and brackets\n`));
  188. });
  189. QUnit.test('table', function(assert) {
  190. console.log("TABLE");
  191. assert.equal(t2t.convert("| first cell | second cell |", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  192. \\hline
  193. first cell & second cell \\tabularnewline
  194. \\hline
  195. \\end{longtable}\n`);
  196. assert.equal(t2t.convert("| first cell ", "", ""), "| first cell \n\n");
  197. try{
  198. t2t.convert("| first cell | second cell ", "", "");
  199. }catch(err){
  200. assert.equal(err, "Table not correctly written\nMaybe there's a whitespace at end of line first cell | second cell ");
  201. }
  202. assert.equal(t2t.convert("| first cell | second cell |\n| third cell | fourth cell |", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  203. \\hline
  204. first cell & second cell \\tabularnewline
  205. \\hline
  206. third cell & fourth cell \\tabularnewline
  207. \\hline
  208. \\end{longtable}\n`);
  209. assert.equal(t2t.convert("| first cell |\n| second cell | third cell |", "", ""), `\\begin{longtable}{|p{0.9\\linewidth}|}
  210. \\hline
  211. first cell \\tabularnewline
  212. \\hline
  213. second cell & third cell \\tabularnewline
  214. \\hline
  215. \\end{longtable}\n`);
  216. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  217. \\hline
  218. first cell & second cell \\tabularnewline
  219. \\hline
  220. \\end{longtable}
  221. Text line
  222. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  223. \\hline
  224. third cell & fourth cell \\tabularnewline
  225. \\hline
  226. \\end{longtable}\n`);
  227. assert.equal(t2t.convert("Text adhoc for testing\n| a | b |\n| c | d |\n", "", ""), `Text adhoc for testing
  228. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  229. \\hline
  230. a & b \\tabularnewline
  231. \\hline
  232. c & d \\tabularnewline
  233. \\hline
  234. \\end{longtable}\n`);
  235. assert.equal(t2t.convert("Text adhoc for testing\n| a | b |\n| c | d |\nText adhoc for testing\n", "", ""), `Text adhoc for testing
  236. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  237. \\hline
  238. a & b \\tabularnewline
  239. \\hline
  240. c & d \\tabularnewline
  241. \\hline
  242. \\end{longtable}
  243. Text adhoc for testing\n`);
  244. });
  245. QUnit.test('end_table', function(assert) {
  246. console.log("END TABLE");
  247. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n#Title1", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  248. \\hline
  249. first cell & second cell \\tabularnewline
  250. \\hline
  251. \\end{longtable}
  252. Text line
  253. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  254. \\hline
  255. third cell & fourth cell \\tabularnewline
  256. \\hline
  257. \\end{longtable}
  258. \\section{Title1}\n`);
  259. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n__\n--Item\n,,", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  260. \\hline
  261. first cell & second cell \\tabularnewline
  262. \\hline
  263. \\end{longtable}
  264. Text line
  265. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  266. \\hline
  267. third cell & fourth cell \\tabularnewline
  268. \\hline
  269. \\end{longtable}
  270. \\begin{itemize}
  271. \\item Item
  272. \\end{itemize}\n`);
  273. assert.equal(t2t.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", ""), `\\begin{itemize}
  274. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  275. \\hline
  276. first cell & second cell \\tabularnewline
  277. \\hline
  278. \\end{longtable}
  279. Text line
  280. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  281. \\hline
  282. third cell & fourth cell \\tabularnewline
  283. \\hline
  284. \\end{longtable}
  285. \\item Item
  286. \\end{itemize}\n`);
  287. assert.equal(t2t.convert("__\n--Item\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n,,", "", ""), `\\begin{itemize}
  288. \\item Item
  289. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  290. \\hline
  291. first cell & second cell \\tabularnewline
  292. \\hline
  293. \\end{longtable}
  294. Text line
  295. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  296. \\hline
  297. third cell & fourth cell \\tabularnewline
  298. \\hline
  299. \\end{longtable}
  300. \\end{itemize}\n`);
  301. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<Test\n", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  302. \\hline
  303. first cell & second cell \\tabularnewline
  304. \\hline
  305. \\end{longtable}
  306. Text line
  307. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  308. \\hline
  309. third cell & fourth cell \\tabularnewline
  310. \\hline
  311. \\end{longtable}
  312. \\verb!Test!\n`);
  313. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test\n", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  314. \\hline
  315. first cell & second cell \\tabularnewline
  316. \\hline
  317. \\end{longtable}
  318. Text line
  319. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  320. \\hline
  321. third cell & fourth cell \\tabularnewline
  322. \\hline
  323. \\end{longtable}
  324. \\begin{verbatim}
  325. Test
  326. \\end{verbatim}\n\n`);
  327. assert.equal(t2t.convert("| first cell | second cell |\nText line\n| third cell | fourth cell |\n<+Test with pipe |\n", "", ""), `\\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  328. \\hline
  329. first cell & second cell \\tabularnewline
  330. \\hline
  331. \\end{longtable}
  332. Text line
  333. \\begin{longtable}{|p{0.45\\linewidth}|p{0.45\\linewidth}|}
  334. \\hline
  335. third cell & fourth cell \\tabularnewline
  336. \\hline
  337. \\end{longtable}
  338. \\begin{verbatim}
  339. Test with pipe |
  340. \\end{verbatim}\n\n`);
  341. });
  342. QUnit.test('new line', function(assert) {
  343. console.log("NEW LINE");
  344. assert.equal(t2t.convert("Lorem Ipsum \n ", "", ""), ("Lorem Ipsum \n\n \n\n"));
  345. assert.equal(t2t.convert("First line\nLorem Ipsum \n ", "", ""), ("First line\nLorem Ipsum \n\n \n\n"));
  346. assert.equal(t2t.convert("First line \nLorem Ipsum \n ", "", ""), ("First line \n\nLorem Ipsum \n\n \n\n"));
  347. assert.equal(t2t.convert("Lorem{(class) Ipsum} \n", "", ""), ("LoremIpsum \n\n"));
  348. assert.equal(t2t.convert("Lorem\nIpsum\nDolor\n", "", ""), ("Lorem\nIpsum\nDolor\n"));
  349. assert.equal(t2t.convert("{(class) text}\n", "", ""), ("text\n"));
  350. assert.equal(t2t.convert("Lorem\n{(class) text}\nDolor\n", "", ""), ("Lorem\ntext\nDolor\n"));
  351. });
  352. QUnit.test('metatags', function(assert) {
  353. console.log("METATAGS");
  354. assert.equal(t2t.convert("<! Comment commenting things", "", ""), "");
  355. assert.equal(t2t.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");
  356. assert.equal(t2t.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");
  357. assert.equal(t2t.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");
  358. assert.equal(t2t.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing", "", ""), `Text adhoc for testing
  359. \\begin{verbatim}
  360. metatag with space at end
  361. \\end{verbatim}
  362. Text adhoc for testing\n`);
  363. assert.equal(t2t.convert("Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing", "", ""), `Text adhoc for testing
  364. \\begin{verbatim}
  365. metatag with space at end
  366. \\end{verbatim}
  367. Text adhoc for testing\n`);
  368. assert.equal(t2t.convert("Text adhoc for testing\n<+ metatag with space at end\nText adhoc for testing ", "", ""), `Text adhoc for testing
  369. \\begin{verbatim}
  370. metatag with space at end
  371. \\end{verbatim}
  372. Text adhoc for testing \n\n`);
  373. assert.equal(t2t.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");
  374. });
  375. QUnit.test('misc.', function(assert) {
  376. console.log("MISC.");
  377. assert.equal(t2t.convert("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj", "", "")
  378. , ("alkasdfasdf \n\n\\section{This isn't a title}\nksadjfañlskdfj\n"));
  379. assert.equal(t2t.convert("alkasdfasdf\n#This isn't a title\nksadjfañlskdfj", "", "")
  380. , "alkasdfasdf\n\\section{This isn't a title}\nksadjfañlskdfj\n");
  381. assert.equal(t2t.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");
  382. assert.equal(t2t.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");
  383. assert.equal(t2t.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");
  384. assert.equal(t2t.convert("Paragraph without space at end\n< hello ", "", ""), "Paragraph without space at end\n\\verb! hello !\n");
  385. assert.equal(t2t.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");
  386. assert.equal(t2t.convert("Paragraph without space at end\n< hello ", "", ""), "Paragraph without space at end\n\\verb! hello !\n");
  387. });
  388. });