123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- h2t = new html2tedi();
- QUnit.module('html2tedi', function() {
- QUnit.test('convert initial line text', function(assert) {
- //Empty string
- console.log("EMPTY STRINGS");
- assert.equal((h2t.convert("", "", "")), (""));
- assert.equal(h2t.convert(" \n", "", ""), ("\n"));
- assert.equal(h2t.convert("\n", "", ""), ("\n"));
- });
- QUnit.test('titles', function(assert) {
- //Titles
- console.log("TITLES");
- try{
- h2t.convert("#####", "", "");
- }catch(err) {
- assert.equal(err, "Unexpected heading size#####");
- }
- assert.equal(h2t.convert("paragraph \n#This isn't a title", "", ""), ("paragraph \n#This isn't a title\n"));
- assert.equal(h2t.convert("<h1>This isn't a title</h1>", "", ""), ("#This isn't a title\n"));
- assert.equal(h2t.convert(" <h1>This isn't a title</h1>", "", ""), ("#This isn't a title\n"));
- assert.equal(h2t.convert("\t<h2>This isn't a title</h2>", "", ""), ("##This isn't a title\n"));
- assert.equal(h2t.convert("<h2>This isn't a title</h2>", "", ""), ("##This isn't a title\n"));
- assert.equal(h2t.convert("<h3>This isn't a title</h3>", "", ""), ("###This isn't a title\n"));
- assert.equal(h2t.convert("<h4>This isn't a title</h4>", "", ""), ("###This isn't a title\n"));
- assert.equal(h2t.convert("<h4>This isn't a title</h4>", "", ""), "###This isn't a title\n" );
- assert.equal(h2t.convert("<h4>This isn't a title</h4>", "", ""), "###This isn't a title\n" );
- });
- QUnit.test('list', function(assert) {
- console.log("LIST");
- assert.equal(h2t.convert("<ul>", "", ""), ("__\n"));
- assert.equal(h2t.convert("<li>Text", "", ""), ("Text\n"));
- assert.equal(h2t.convert("</ul>", "", ""), ("\n"));
- assert.equal(h2t.convert("<ul>\n<li>Text\n</ul>", "", ""), ("__\n--Text\n,,\n"));
- });
- QUnit.test('quotes', function(assert) {
- console.log("QUOTE");
- assert.equal(h2t.convert("\"Quoted text\"", "", ""), ("\"Quoted text\"\n"));
- try{
- h2t.convert("\"Bad quoting", "", "")
- }catch(err) {
- assert.equal(err, "Missing end quotes.\"Bad quoting");
- }
- });
- QUnit.test('links', function(assert) {
- console.log("LINKS");
- assert.equal(h2t.convert("<a>Test with a open square bracket", "", ""), ("Test with a open square bracket\n"));
-
- assert.equal(h2t.convert("<a href=\">Test with a open square bracket", "", ""), ("Test with a open square bracket\n"));
-
- assert.equal(h2t.convert("<a href=\"\">Test with a open square bracket", "", ""), ("Test with a open square bracket\n"));
-
- assert.equal(h2t.convert("<a href=\"\">Test with a open square bracket</a>", "", ""), ("[() Test with a open square bracket]\n"));
-
- assert.equal(h2t.convert("<a >Test with a open square bracket</a>", "", ""), ("[() Test with a open square bracket]\n"));
-
- assert.equal(h2t.convert("[ ", "", ""), "\\[ \n");
-
- assert.equal(h2t.convert("[( ", "", ""), "\\[\\( \n");
-
- assert.equal(h2t.convert("[() ", "", ""), "\\[\\(\\) \n");
- assert.equal(h2t.convert("[() ]", "", ""), "\\[\\(\\) \\]\n");
- });
- QUnit.test('images', function(assert) {
- console.log("IMAGES");
- //Can be improved
- assert.equal(h2t.convert("<img Test with an open parenthesis", "", ""), ("\n"));
-
- assert.equal(h2t.convert("<img >Test with an open parenthesis", "", ""), ("([] )Test with an open parenthesis\n"));
- assert.equal(h2t.convert("<img src=\"\">Test with an open parenthesis", "", ""), ("([] )Test with an open parenthesis\n"));
- assert.equal(h2t.convert("<img src=\"\" alt=\"\">Test with an open parenthesis", "", ""), ("([] )Test with an open parenthesis\n"));
-
- assert.equal(h2t.convert("(", "", ""), "\\(\n");
- assert.equal(h2t.convert("([", "", ""), "\\(\\[\n");
- assert.equal(h2t.convert("([] ", "", ""), "\\(\\[\\] \n");
- assert.equal(h2t.convert("([] )", "", ""), "\\(\\[\\] \\)\n");
- assert.equal(h2t.convert("([ ] )", "", ""), "\\(\\[ \\] \\)\n");
- });
- QUnit.test('blocks', function(assert) {
- console.log("BLOCKS");
- assert.equal(h2t.convert("<div>Test with a open square bracket", "", ""), ("Test with a open square bracket\n"));
-
- assert.equal(h2t.convert("<div >Test with a open square bracket", "", ""), ("{() Test with a open square bracket\n"));
-
- assert.equal(h2t.convert("<div >Test with a open square bracket</div>", "", ""), ("{() Test with a open square bracket}\n"));
-
- assert.equal(h2t.convert("<div class=\">Test with a open square bracket</div>", "", ""), ("{() Test with a open square bracket}\n"));
-
- assert.equal(h2t.convert("<div class=\"sadfasf\">Test with a open square bracket</div>", "", ""), ("{(sadfasf) Test with a open square bracket}\n"));
- //raro
- assert.equal(h2t.convert("<div class=\">Test with a open square bracket</div>", "", ""), ("{() Test with a open square bracket}\n"));
-
- assert.equal(h2t.convert("{Test with an open parenthesis", "", ""), ("\\{Test with an open parenthesis\n"));
- assert.equal(h2t.convert("{(Test with closing square bracket) }", "", ""), "\\{\\(Test with closing square bracket\\) \\}\n");
- assert.equal(h2t.convert("{() }", "", ""), "\\{\\(\\) \\}\n");
- assert.equal(h2t.convert("{( ) }", "", ""), "\\{\\( \\) \\}\n");
-
- });
- QUnit.test('multiples unquoted tags', function(assert) {
- console.log("MULTIPLES UNQUOTED TAGS");
- assert.equal(h2t.convert("[Test with a open square bracket ( also parenthesis and { brackets", "", ""), ("\\[Test with a open square bracket \\( also parenthesis and \\{ brackets\n"));
- assert.equal(h2t.convert("<a href=\"url\">Test with a link <img alt=\"alternative text\" src=\"image url\"></a> and <div class=\"class\">brackets</div>", "", ""), ("[(url) Test with a link ([alternative text] image url)] and {(class) brackets}\n"));
- assert.equal(h2t.convert("<div class=\"class\"><a href=\"url\">Test with a link <img alt=\"alternative text\" src=\"image url\"></a> and brackets</div>", "", ""), ("{(class) [(url) Test with a link ([alternative text] image url)] and brackets}\n"));
- });
- QUnit.test('table', function(assert) {
- console.log("TABLE");
- assert.equal(h2t.convert("<table>\n<tr>\n<td> first cell </td>\n<td> second cell </td>\n</tr>\n</table>\n", "", ""), " | first cell | second cell |\n");
- assert.equal(h2t.convert("<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", "", ""), " | first cell | second cell |\n | third cell | fourth cell |\n");
- assert.equal(h2t.convert("<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>", "", ""), " | first cell | second cell |\n | third cell | fourth cell |\n");
-
- assert.equal(h2t.convert("<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", "", ""), " | first cell |\n | second cell | third cell |\n");
-
- assert.equal(h2t.convert("<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", "", ""), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n");
-
- assert.equal(h2t.convert("Text adhoc for testing\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", "", ""), "Text adhoc for testing\n | a | b |\n | c | d |\n");
- assert.equal(h2t.convert("Text adhoc for testing<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>\nText adhoc for testing\n", "", ""), " | a | b |\n | c | d |\nText adhoc for testing\n");
- });
-
- QUnit.test('end_table', function(assert) {
- console.log("END TABLE");
- assert.equal(h2t.convert("<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<h1>Title1</h1>", "", ""), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n#Title1\n");
- assert.equal(h2t.convert("<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<li>Item\n</ul>"), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n__\n--Item\n,,\n");
- assert.equal(h2t.convert("__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,", "", ""), "__\n| first cell | second cell |\nText line\n| third cell | fourth cell |\n--Item\n,,\n");
- assert.equal(h2t.convert("<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--Item\n | first cell | second cell |\nText line\n | third cell | fourth cell |\n,,\n");
-
- assert.equal(h2t.convert("<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<code>Test</code>", "", ""), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n\n<+Test\n");
-
- assert.equal(h2t.convert("<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<pre>Test</pre>\n", "", ""), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n<+ Test\n");
-
- assert.equal(h2t.convert("<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<pre>Test with pipe |</pre>\n", "", ""), " | first cell | second cell |\nText line\n | third cell | fourth cell |\n<+ Test with pipe |\n");
- });
- QUnit.test('new line', function(assert) {
- console.log("NEW LINE");
- assert.equal(h2t.convert("Lorem Ipsum \n ", "", ""), ("Lorem Ipsum \n\n"));
- assert.equal(h2t.convert("First line\nLorem Ipsum \n ", "", ""), ("First line\nLorem Ipsum \n\n"));
- assert.equal(h2t.convert("First line \nLorem Ipsum \n ", "", ""), ("First line \nLorem Ipsum \n\n"));
- assert.equal(h2t.convert("Lorem<div class=\"class\">Ipsum</div>\n", "", ""), ("Lorem{(class) Ipsum}\n"));
- assert.equal(h2t.convert("Lorem\nIpsum\nDolor\n", "", ""), ("Lorem\nIpsum\nDolor\n"));
- assert.equal(h2t.convert("<div class=\"class\">text</div>\n", "", ""), ("{(class) text}\n"));
- assert.equal(h2t.convert("Lorem<div class=\"class\">text</div>Dolor", "", ""), ("Lorem{(class) text}Dolor\n"));
- });
- QUnit.test('metatags', function(assert) {
- console.log("METATAGS");
- assert.equal(h2t.convert("<! Comment commenting things", "", ""), "\n");
- assert.equal(h2t.convert("Text adhoc for testing<code> metatag without space at end</code>Text adhoc for testing", "", ""), "Text adhoc for testing\n< metatag without space at end\nText adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing \n<code> metatag without space at end</code>Text adhoc for testing", "", ""), "Text adhoc for testing \n\n< metatag without space at end\nText adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing\n<code> metatag without space at end</code>\nText adhoc for testing ", "", ""), "Text adhoc for testing\n\n<+ metatag without space at end\nText adhoc for testing \n");
- assert.equal(h2t.convert("Text adhoc for testing<pre> metatag with space at end</pre>\nText adhoc for testing", "", ""), "<+ Text adhoc for testing metatag with space at end\nText adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing \n<pre> metatag with space at end</pre>\nText adhoc for testing", "", ""), "Text adhoc for testing \n<+ metatag with space at end\nText adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing<pre> metatag with space at end</pre>\nText adhoc for testing", "", ""), "<+ Text adhoc for testing metatag with space at end\nText adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing\n<div class=\"embed\"> embed with space at end</div>\nText adhoc for testing ", "", ""), "Text adhoc for testing\n<> embed with space at end\nText adhoc for testing \n");
- });
- QUnit.test('misc.', function(assert) {
- console.log("MISC.");
- assert.equal(h2t.convert("alkasdfasdf \n<h1>This isn't a title</h1>\nksadjfañlskdfj", "", "")
- , ("alkasdfasdf \n#This isn't a title\nksadjfañlskdfj\n"));
- assert.equal(h2t.convert("alkasdfasdf\n<h1>This isn't a title</h1>\nksadjfañlskdfj", "", "")
- , "alkasdfasdf\n#This isn't a title\nksadjfañlskdfj\n");
- assert.equal(h2t.convert("Text adhoc for testing<div class=\"class\">container text </div> Text adhoc for testing", "", ""), "Text adhoc for testing{(class) container text } Text adhoc for testing\n");
- assert.equal(h2t.convert("Text adhoc for testing \n<div class=\"class\">container text </div>Text adhoc for testing", "", ""), "Text adhoc for testing \n{(class) container text }Text adhoc for testing\n");
-
- assert.equal(h2t.convert("Text adhoc for testing \n<div class=\"class\">container text</div>Text adhoc for testing", "", ""), "Text adhoc for testing \n{(class) container text}Text adhoc for testing\n");
- assert.equal(h2t.convert("Paragraph without space at end<code> hello </code>", "", ""), "Paragraph without space at end\n<+ hello \n");
- assert.equal(h2t.convert("Paragraph without space at end<code> hello without space at end</code> lsdkjfgsñdlkfjñlk", "", ""), "Paragraph without space at end\n< hello without space at end\nlsdkjfgsñdlkfjñlk\n");
- assert.equal(h2t.convert("Paragraph without space at end<code> hello </code>", "", ""), "Paragraph without space at end\n<+ hello \n");
- });
-
- QUnit.test('div line', function(assert) {
- console.log("div line");
- assert.equal(h2t.convert("<div> laskjfdalksjdf </div>", "", "") , ("laskjfdalksjdf \n"));
-
- assert.equal(h2t.convert("<div> <img src=\"\" alt=\"\"> </div>", "", "") , ("([] ) \n"));
-
- assert.equal(h2t.convert("<div> <img src=\"\" alt=\"\"> </div>", "", "") , ("([] ) \n"));
- });
- });
-
|