summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-self-test.c
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2022-07-15 21:18:47 +0200
committerRichard Hughes <richard@hughsie.com>2022-07-18 19:43:07 +0100
commit674490bd54ff206f213ca4547db7fdb591a0fb3d (patch)
tree754f13870582908910ebb30fff6ea2daa360ab72 /libappstream-glib/as-self-test.c
parent8d39640032752bf81d648d018ff115aa8d495957 (diff)
downloadappstream-glib-674490bd54ff206f213ca4547db7fdb591a0fb3d.tar.gz
Improve handling of <em> and <code> tags
This is still not great code but at least somewhat an improvement. Tests were expanded to showcase the new behavior. I think, ideally, we would append opening/closing tags to the ancestor `p` or `li` node's cdata as soon as we encounter the start/end of an `em` or `code` element. This would then also handle empty elements correctly.
Diffstat (limited to 'libappstream-glib/as-self-test.c')
-rw-r--r--libappstream-glib/as-self-test.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 11b51b6..aade35c 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -2870,6 +2870,15 @@ as_test_node_xml_func (void)
"It now also supports <em>em</em> and <code>code</code> tags."
"</p>"
"</description>";
+ const gchar *valid_em_code_2 = "<description>"
+ "<p><em>Emphasis</em> at the start of the paragraph</p>"
+ "</description>";
+ const gchar *valid_em_code_empty = "<description>"
+ "<p><em></em></p>"
+ "</description>";
+ const gchar *valid_em_code_empty_2 = "<description>"
+ "<p>empty <em></em> emphasis</p>"
+ "</description>";
GError *error = NULL;
AsNode *n2;
AsNode *root;
@@ -2940,8 +2949,34 @@ as_test_node_xml_func (void)
n2 = as_node_find (root, "description/p");
g_assert (n2 != NULL);
- printf ("<%s>\n", as_node_get_data (n2));
- g_assert_cmpstr (as_node_get_data (n2), ==, "It now also supports<em>em</em> and <code>code</code> tags.");
+ g_assert_cmpstr (as_node_get_data (n2), ==, "It now also supports <em>em</em> and <code>code</code> tags.");
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_2, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, "<em>Emphasis</em> at the start of the paragraph");
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_empty, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, NULL);
+ as_node_unref (root);
+
+ root = as_node_from_xml (valid_em_code_empty_2, 0, &error);
+ g_assert_no_error (error);
+ g_assert (root != NULL);
+
+ n2 = as_node_find (root, "description/p");
+ g_assert (n2 != NULL);
+ g_assert_cmpstr (as_node_get_data (n2), ==, "empty emphasis");
as_node_unref (root);
/* keep comments */