/* * Copyright 2016 Michael Gratton * * This software is licensed under the GNU Lesser General Public License * (version 2.1 or later). See the COPYING file in this distribution. */ class Geary.HTML.UtilTest : TestCase { public UtilTest() { base("Geary.HTML.Util"); add_test("preserve_whitespace", preserve_whitespace); add_test("smart_escape_div", smart_escape_div); add_test("smart_escape_no_closing_tag", smart_escape_no_closing_tag); add_test("smart_escape_img", smart_escape_img); add_test("smart_escape_xhtml_img", smart_escape_xhtml_img); add_test("smart_escape_mixed", smart_escape_mixed); add_test("smart_escape_text", smart_escape_text); add_test("smart_escape_text_url", smart_escape_text_url); add_test("remove_html_tags", remove_html_tags); } public void preserve_whitespace() throws GLib.Error { assert_string("some text", Geary.HTML.smart_escape("some text")); assert_string("some  text", Geary.HTML.smart_escape("some text")); assert_string("some   text", Geary.HTML.smart_escape("some text")); assert_string("some    text", Geary.HTML.smart_escape("some\ttext")); assert_string("some
text", Geary.HTML.smart_escape("some\ntext")); assert_string("some
text", Geary.HTML.smart_escape("some\rtext")); assert_string("some
text", Geary.HTML.smart_escape("some\r\ntext")); assert_string("some

text", Geary.HTML.smart_escape("some\n\ntext")); assert_string("some

text", Geary.HTML.smart_escape("some\r\rtext")); assert_string("some

text", Geary.HTML.smart_escape("some\n\rtext")); assert_string("some

text", Geary.HTML.smart_escape("some\r\n\r\ntext")); } public void smart_escape_div() throws Error { string html = "
ohhai
"; assert(Geary.HTML.smart_escape(html) == html); } public void smart_escape_no_closing_tag() throws Error { string html = "
ohhai"; assert(Geary.HTML.smart_escape(html) == html); } public void smart_escape_img() throws Error { string html = ""; assert(Geary.HTML.smart_escape(html) == html); } public void smart_escape_xhtml_img() throws Error { string html = ""; assert(Geary.HTML.smart_escape(html) == html); } public void smart_escape_mixed() throws Error { string html = "mixed
ohhai
text"; assert(Geary.HTML.smart_escape(html) == html); } public void smart_escape_text() throws GLib.Error { assert_string("some text", Geary.HTML.smart_escape("some text")); assert_string("<some text", Geary.HTML.smart_escape("")); } public void smart_escape_text_url() throws GLib.Error { assert_string( "<http://example.com>", Geary.HTML.smart_escape("") ); assert_string( "<http://example.com>", Geary.HTML.smart_escape("") ); } public void remove_html_tags() throws Error { string blockquote_body = """
hello

there

"""; string style_complete = """"""; string style_truncated = """


Hi Kenneth,

We xxxxx xxxx xx xxx xxx xx xxxx x xxxxxxxx xxxxxxxx.



Thank you,

XXXXX X XXXXXX

You can reply directly to this message or click the following link:
https://app.foobar.com/xxxxxxxxxxxxxxxx1641966deff6c48623aba

You can change your email preferences at:
https://app.foobar.com/xxxxxxxxxxx

"""; private static string HTML_BODY_COMPLETE_EXPECTED = """ Hi Kenneth, We xxxxx xxxx xx xxx xxx xx xxxx x xxxxxxxx xxxxxxxx. Thank you, XXXXX X XXXXXX You can reply directly to this message or click the following link: https://app.foobar.com/xxxxxxxxxxxxxxxx1641966deff6c48623aba You can change your email preferences at: https://app.foobar.com/xxxxxxxxxxx """; private static string HTML_ENTITIES_BODY = """
What if I said that I'd like to go to the theater tomorrow night.
 
I think we could do that!
"""; private static string HTML_ENTITIES_EXPECTED = """ What if I said that I'd like to go to the theater tomorrow night.   I think we could do that! """; }