1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
struct TestContent {
public string original;
public string sanitized;
}
const TestContent[] PANGO_TESTS = {
{ "\n\n<strong>te<em>st</em></strong>\n\n", "\n\n<b>te<i>st</i></b>\n\n" },
{ "\n<br/>\n<strong>te<em>st</em></strong>\n\n", "<br/><b>te<i>st</i></b>" },
};
const TestContent[] RESTORE_TESTS = {
{ "&lt;", "<" },
{ "<>'&foo;"'", "<>'&foo;\"'" }
};
const TestContent[] SIMPLIFY_TESTS = {
{
"<a class=\"proletariat\" href=\"https://tuba.geopjr.dev/\" target=\"_blank\">Tuba</a>\n",
"<a href='https://tuba.geopjr.dev/'>Tuba</a>"
},
{
"<p>Everything is going to be<br />okay</p><div>š±</div>",
"Everything is going to be\nokay\n\nš±"
}
};
const TestContent[] REMOVE_TAGS_TESTS = {
{
"<a class=\"proletariat\" href\"https://tuba.geopjr.dev/\" target=\"_blank\">Tuba</a>\n",
"Tuba\n"
},
{
"<p>Everything is going to be<br />okay</p><footer>š±</footer>",
"Everything is going to be\nokay\nš±"
},
{
"<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Document</title></head><body><header>I am an<strong><br>example</strong></header><main>another <p>multi <strong>nested <button>one</button></strong></p></main>end</body></html>",
"DocumentI am an\nexampleanother multi nested one\nend"
}
};
public void test_pango () {
foreach (var test_pango in PANGO_TESTS) {
var res = Tuba.Utils.Htmlx.replace_with_pango_markup (test_pango.original);
assert_cmpstr (res, CompareOperator.EQ, test_pango.sanitized);
}
}
public void test_restore () {
foreach (var test_restore in RESTORE_TESTS) {
var res = Tuba.Utils.Htmlx.restore_entities (test_restore.original);
assert_cmpstr (res, CompareOperator.EQ, test_restore.sanitized);
}
}
public void test_simplify () {
foreach (var test_simplify in SIMPLIFY_TESTS) {
var res = Tuba.Utils.Htmlx.simplify (test_simplify.original);
assert_cmpstr (res, CompareOperator.EQ, test_simplify.sanitized);
}
}
public void test_remove_tags () {
foreach (var test_remove_tag in REMOVE_TAGS_TESTS) {
var res = Tuba.Utils.Htmlx.remove_tags (test_remove_tag.original);
assert_cmpstr (res, CompareOperator.EQ, test_remove_tag.sanitized);
}
}
public int main (string[] args) {
Test.init (ref args);
Test.add_func ("/test_pango", test_pango);
Test.add_func ("/test_restore", test_restore);
Test.add_func ("/test_simplify", test_simplify);
Test.add_func ("/test_remove_tags", test_remove_tags);
return Test.run ();
}
|