[gnome-software/gnome-3-20] Move the markdown parsing to the PackageKit plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-20] Move the markdown parsing to the PackageKit plugin
- Date: Thu, 14 Apr 2016 17:30:36 +0000 (UTC)
commit 9ec7fbc51f82748f3af6bd30c36b6808b7b6d73d
Author: Richard Hughes <richard hughsie com>
Date: Thu Apr 7 11:49:23 2016 +0100
Move the markdown parsing to the PackageKit plugin
The format isn't standardized as markdown between distros.
src/Makefile.am | 3 -
src/gs-app-row.c | 12 +--
src/gs-self-test.c | 182 ----------------------------
src/gs-shell-extras.c | 1 -
src/gs-shell-updates.c | 1 -
src/gs-update-dialog.c | 29 +----
src/plugins/Makefile.am | 13 ++-
src/plugins/gs-appstream.c | 2 +-
src/{ => plugins}/gs-markdown.c | 0
src/{ => plugins}/gs-markdown.h | 0
src/plugins/gs-plugin-packagekit-refine.c | 35 ++++++-
src/plugins/gs-self-test.c | 185 ++++++++++++++++++++++++++++-
12 files changed, 236 insertions(+), 227 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index faa9796..642dfd5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -162,8 +162,6 @@ gnome_software_SOURCES = \
gs-screenshot-image.h \
gs-shell.c \
gs-shell.h \
- gs-markdown.c \
- gs-markdown.h \
gs-shell-details.c \
gs-shell-details.h \
gs-shell-category.c \
@@ -285,7 +283,6 @@ check_PROGRAMS = \
gs_self_test_SOURCES = \
gs-app.c \
gs-category.c \
- gs-markdown.c \
gs-os-release.c \
gs-plugin-loader-sync.c \
gs-plugin-loader.c \
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 7cfd465..b40dab0 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -27,7 +27,6 @@
#include "gs-app-row.h"
#include "gs-star-widget.h"
-#include "gs-markdown.h"
#include "gs-progress-button.h"
#include "gs-utils.h"
#include "gs-folders.h"
@@ -90,15 +89,8 @@ gs_app_row_get_description (GsAppRow *app_row)
(gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE ||
gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE_LIVE)) {
tmp = gs_app_get_update_details (priv->app);
- if (tmp != NULL && tmp[0] != '\0') {
- g_autoptr(GsMarkdown) markdown = NULL;
- markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
- gs_markdown_set_smart_quoting (markdown, FALSE);
- gs_markdown_set_autocode (markdown, FALSE);
- gs_markdown_set_autolinkify (markdown, FALSE);
- escaped = gs_markdown_parse (markdown, tmp);
- return g_string_new (escaped);
- }
+ if (tmp != NULL && tmp[0] != '\0')
+ return g_string_new (tmp);
}
if (gs_app_get_state (priv->app) == AS_APP_STATE_UNAVAILABLE)
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index abcec78..ebcc440 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -27,192 +27,11 @@
#include <glib/gstdio.h>
#include "gs-app.h"
-#include "gs-markdown.h"
#include "gs-plugin.h"
#include "gs-plugin-loader.h"
#include "gs-plugin-loader-sync.h"
#include "gs-utils.h"
-static void
-gs_markdown_func (void)
-{
- gchar *text;
- const gchar *markdown;
- const gchar *markdown_expected;
- g_autoptr(GsMarkdown) md = NULL;
-
- /* get GsMarkdown object */
- md = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
- g_assert (md);
-
- markdown = "OEMs\n"
- "====\n"
- " - Bullett\n";
- markdown_expected =
- "<big>OEMs</big>\n"
- "• Bullett";
- /* markdown (type2 header) */
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (autocode) */
- markdown = "this is http://www.hughsie.com/with_spaces_in_url inline link\n";
- markdown_expected = "this is <tt>http://www.hughsie.com/with_spaces_in_url</tt> inline link";
- gs_markdown_set_autocode (md, TRUE);
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown some invalid header */
- markdown = "*** This software is currently in alpha state ***\n";
- markdown_expected = "<b><i> This software is currently in alpha state </b></i>";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (complex1) */
- markdown = " - This is a *very*\n"
- " short paragraph\n"
- " that is not usual.\n"
- " - Another";
- markdown_expected =
- "• This is a <i>very</i> short paragraph that is not usual.\n"
- "• Another";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (complex1) */
- markdown = "* This is a *very*\n"
- " short paragraph\n"
- " that is not usual.\n"
- "* This is the second\n"
- " bullett point.\n"
- "* And the third.\n"
- " \n"
- "* * *\n"
- " \n"
- "Paragraph one\n"
- "isn't __very__ long at all.\n"
- "\n"
- "Paragraph two\n"
- "isn't much better.";
- markdown_expected =
- "• This is a <i>very</i> short paragraph that is not usual.\n"
- "• This is the second bullett point.\n"
- "• And the third.\n"
- "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯\n"
- "Paragraph one isn't <b>very</b> long at all.\n"
- "Paragraph two isn't much better.";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- markdown = "This is a spec file description or\n"
- "an **update** description in bohdi.\n"
- "\n"
- "* * *\n"
- "# Big title #\n"
- "\n"
- "The *following* things 'were' fixed:\n"
- "- Fix `dave`\n"
- "* Fubar update because of \"security\"\n";
- markdown_expected =
- "This is a spec file description or an <b>update</b> description in bohdi.\n"
- "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯\n"
- "<big>Big title</big>\n"
- "The <i>following</i> things 'were' fixed:\n"
- "• Fix <tt>dave</tt>\n"
- "• Fubar update because of \"security\"";
- /* markdown (complex2) */
- text = gs_markdown_parse (md, markdown);
- if (g_strcmp0 (text, markdown_expected) == 0)
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (list with spaces) */
- markdown = "* list seporated with spaces -\n"
- " first item\n"
- "\n"
- "* second item\n"
- "\n"
- "* third item\n";
- markdown_expected =
- "• list seporated with spaces - first item\n"
- "• second item\n"
- "• third item";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- gs_markdown_set_max_lines (md, 1);
-
- /* markdown (one line limit) */
- markdown = "* list seporated with spaces -\n"
- " first item\n"
- "* second item\n";
- markdown_expected =
- "• list seporated with spaces - first item";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- gs_markdown_set_max_lines (md, 1);
-
- /* markdown (escaping) */
- markdown = "* list & <spaces>";
- markdown_expected =
- "• list & <spaces>";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (URLs) */
- markdown = "this is the http://www.hughsie.com/ coolest site";
- markdown_expected =
- "this is the "
- "<a href=\"http://www.hughsie.com/\">http://www.hughsie.com/</a>"
- " coolest site";
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-
- /* markdown (free text) */
- gs_markdown_set_escape (md, FALSE);
- text = gs_markdown_parse (md, "This isn't a present");
- g_assert_cmpstr (text, ==, "This isn't a present");
- g_free (text);
-
- /* markdown (autotext underscore) */
- text = gs_markdown_parse (md, "This isn't CONFIG_UEVENT_HELPER_PATH present");
- g_assert_cmpstr (text, ==, "This isn't <tt>CONFIG_UEVENT_HELPER_PATH</tt> present");
- g_free (text);
-
- /* markdown (end of bullett) */
- markdown = "*Thu Mar 12 12:00:00 2009* Dan Walsh <dwalsh redhat com> - 2.0.79-1\n"
- "- Update to upstream \n"
- " * Netlink socket handoff patch from Adam Jackson.\n"
- " * AVC caching of compute_create results by Eric Paris.\n"
- "\n"
- "*Tue Mar 10 12:00:00 2009* Dan Walsh <dwalsh redhat com> - 2.0.78-5\n"
- "- Add patch from ajax to accellerate X SELinux \n"
- "- Update eparis patch\n";
- markdown_expected =
- "<i>Thu Mar 12 12:00:00 2009</i> Dan Walsh <tt><dwalsh redhat com></tt> - 2.0.79-1\n"
- "• Update to upstream\n"
- "• Netlink socket handoff patch from Adam Jackson.\n"
- "• AVC caching of compute_create results by Eric Paris.\n"
- "<i>Tue Mar 10 12:00:00 2009</i> Dan Walsh <tt><dwalsh redhat com></tt> - 2.0.78-5\n"
- "• Add patch from ajax to accellerate X SELinux\n"
- "• Update eparis patch";
- gs_markdown_set_escape (md, TRUE);
- gs_markdown_set_max_lines (md, 1024);
- text = gs_markdown_parse (md, markdown);
- g_assert_cmpstr (text, ==, markdown_expected);
- g_free (text);
-}
-
static gboolean
gs_plugin_list_filter_cb (GsApp *app, gpointer user_data)
{
@@ -691,7 +510,6 @@ main (int argc, char **argv)
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
/* tests go here */
- g_test_add_func ("/gnome-software/markdown", gs_markdown_func);
g_test_add_func ("/gnome-software/plugin-loader{refine}", gs_plugin_loader_refine_func);
g_test_add_func ("/gnome-software/plugin", gs_plugin_func);
g_test_add_func ("/gnome-software/app", gs_app_func);
diff --git a/src/gs-shell-extras.c b/src/gs-shell-extras.c
index 96ba78d..9633179 100644
--- a/src/gs-shell-extras.c
+++ b/src/gs-shell-extras.c
@@ -26,7 +26,6 @@
#include "gs-app.h"
#include "gs-app-row.h"
#include "gs-language.h"
-#include "gs-markdown.h"
#include "gs-shell.h"
#include "gs-utils.h"
#include "gs-vendor.h"
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 0e908d6..70fffcb 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -29,7 +29,6 @@
#include "gs-utils.h"
#include "gs-app.h"
#include "gs-app-row.h"
-#include "gs-markdown.h"
#include "gs-update-dialog.h"
#include "gs-update-list.h"
#include "gs-update-monitor.h"
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 937c9a0..45bae7d 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -26,7 +26,6 @@
#include "gs-update-dialog.h"
#include "gs-app-row.h"
-#include "gs-markdown.h"
#include "gs-update-list.h"
#include "gs-utils.h"
@@ -93,7 +92,6 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
AsAppKind kind;
const GdkPixbuf *pixbuf;
const gchar *update_details;
- g_autofree gchar *update_desc = NULL;
/* set window title */
kind = gs_app_get_kind (app);
@@ -114,28 +112,15 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
gs_app_get_update_version (app));
}
- /* this is set unconditionally just in case the output of the
- * markdown->PangoMarkup parser is invalid */
- gtk_label_set_markup (GTK_LABEL (dialog->label_details),
- /* TRANSLATORS: this is where the
- * packager did not write a
- * description for the update */
- _("No update description available."));
-
- /* get the update description */
- update_details = gs_app_get_update_details (app);
- if (update_details != NULL) {
- g_autoptr(GsMarkdown) markdown = NULL;
- markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
- gs_markdown_set_smart_quoting (markdown, FALSE);
- gs_markdown_set_autocode (markdown, TRUE);
- update_desc = gs_markdown_parse (markdown, update_details);
- }
-
/* set update header */
gtk_widget_set_visible (dialog->box_header, kind == AS_APP_KIND_DESKTOP);
- if (update_desc != NULL)
- gtk_label_set_markup (GTK_LABEL (dialog->label_details), update_desc);
+ update_details = gs_app_get_update_details (app);
+ if (update_details == NULL) {
+ /* TRANSLATORS: this is where the packager did not write
+ * a description for the update */
+ update_details = _("No update description available.");
+ }
+ gtk_label_set_markup (GTK_LABEL (dialog->label_details), update_details);
gtk_label_set_label (GTK_LABEL (dialog->label_name), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (dialog->label_summary), gs_app_get_summary (app));
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 2391c66..5100000 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -183,6 +183,8 @@ libgs_plugin_packagekit_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
libgs_plugin_packagekit_refine_la_SOURCES = \
gs-plugin-packagekit-refine.c \
+ gs-markdown.c \
+ gs-markdown.h \
packagekit-common.c \
packagekit-common.h
libgs_plugin_packagekit_refine_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
@@ -229,15 +231,16 @@ libgs_plugin_packagekit_proxy_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_packagekit_proxy_la_LDFLAGS = -module -avoid-version
libgs_plugin_packagekit_proxy_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-check_PROGRAMS = \
+check_PROGRAMS = \
gs-self-test
-gs_self_test_SOURCES = \
- gs-moduleset.c \
+gs_self_test_SOURCES = \
+ gs-markdown.c \
+ gs-moduleset.c \
gs-self-test.c
-gs_self_test_LDADD = \
- $(GLIB_LIBS) \
+gs_self_test_LDADD = \
+ $(GLIB_LIBS) \
$(GTK_LIBS)
gs_self_test_CFLAGS = $(WARN_CFLAGS)
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 0c390fc..b8ccb84 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -560,7 +560,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
if (tmp != NULL) {
g_autofree gchar *desc = NULL;
desc = as_markup_convert (tmp,
- AS_MARKUP_CONVERT_FORMAT_MARKDOWN,
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
error);
if (desc == NULL)
return FALSE;
diff --git a/src/gs-markdown.c b/src/plugins/gs-markdown.c
similarity index 100%
rename from src/gs-markdown.c
rename to src/plugins/gs-markdown.c
diff --git a/src/gs-markdown.h b/src/plugins/gs-markdown.h
similarity index 100%
rename from src/gs-markdown.h
rename to src/plugins/gs-markdown.h
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 342b6e6..daf243e 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -28,6 +28,7 @@
#include <gs-utils.h>
#include <glib/gi18n.h>
+#include "gs-markdown.h"
#include "packagekit-common.h"
/*
@@ -374,6 +375,33 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
}
/**
+ * gs_plugin_packagekit_fixup_update_description:
+ *
+ * Lets assume Fedora is sending us valid markdown, but fall back to
+ * plain text if this fails.
+ */
+static gchar *
+gs_plugin_packagekit_fixup_update_description (const gchar *text)
+{
+ gchar *tmp;
+ g_autoptr(GsMarkdown) markdown = NULL;
+
+ /* nothing to do */
+ if (text == NULL)
+ return NULL;
+
+ /* try to parse */
+ markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_TEXT);
+ gs_markdown_set_smart_quoting (markdown, FALSE);
+ gs_markdown_set_autocode (markdown, FALSE);
+ gs_markdown_set_autolinkify (markdown, FALSE);
+ tmp = gs_markdown_parse (markdown, text);
+ if (tmp != NULL)
+ return tmp;
+ return g_strdup (text);
+}
+
+/**
* gs_plugin_packagekit_refine_updatedetails:
*/
static gboolean
@@ -420,11 +448,16 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
app = GS_APP (l->data);
package_id = gs_app_get_source_id_default (app);
for (i = 0; i < array->len; i++) {
+ const gchar *tmp;
+ g_autofree gchar *desc = NULL;
/* right package? */
update_detail = g_ptr_array_index (array, i);
if (g_strcmp0 (package_id, pk_update_detail_get_package_id (update_detail)) != 0)
continue;
- gs_app_set_update_details (app, pk_update_detail_get_update_text (update_detail));
+ tmp = pk_update_detail_get_update_text (update_detail);
+ desc = gs_plugin_packagekit_fixup_update_description (tmp);
+ if (desc != NULL)
+ gs_app_set_update_details (app, desc);
break;
}
}
diff --git a/src/plugins/gs-self-test.c b/src/plugins/gs-self-test.c
index 6b45897..8f0a943 100644
--- a/src/plugins/gs-self-test.c
+++ b/src/plugins/gs-self-test.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2016 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -26,6 +27,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "gs-markdown.h"
#include "gs-moduleset.h"
static void
@@ -64,6 +66,186 @@ moduleset_func (void)
g_assert_cmpstr (data[1], ==, NULL);
}
+static void
+gs_markdown_func (void)
+{
+ gchar *text;
+ const gchar *markdown;
+ const gchar *markdown_expected;
+ g_autoptr(GsMarkdown) md = NULL;
+
+ /* get GsMarkdown object */
+ md = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
+ g_assert (md);
+
+ markdown = "OEMs\n"
+ "====\n"
+ " - Bullett\n";
+ markdown_expected =
+ "<big>OEMs</big>\n"
+ "• Bullett";
+ /* markdown (type2 header) */
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (autocode) */
+ markdown = "this is http://www.hughsie.com/with_spaces_in_url inline link\n";
+ markdown_expected = "this is <tt>http://www.hughsie.com/with_spaces_in_url</tt> inline link";
+ gs_markdown_set_autocode (md, TRUE);
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown some invalid header */
+ markdown = "*** This software is currently in alpha state ***\n";
+ markdown_expected = "<b><i> This software is currently in alpha state </b></i>";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (complex1) */
+ markdown = " - This is a *very*\n"
+ " short paragraph\n"
+ " that is not usual.\n"
+ " - Another";
+ markdown_expected =
+ "• This is a <i>very</i> short paragraph that is not usual.\n"
+ "• Another";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (complex1) */
+ markdown = "* This is a *very*\n"
+ " short paragraph\n"
+ " that is not usual.\n"
+ "* This is the second\n"
+ " bullett point.\n"
+ "* And the third.\n"
+ " \n"
+ "* * *\n"
+ " \n"
+ "Paragraph one\n"
+ "isn't __very__ long at all.\n"
+ "\n"
+ "Paragraph two\n"
+ "isn't much better.";
+ markdown_expected =
+ "• This is a <i>very</i> short paragraph that is not usual.\n"
+ "• This is the second bullett point.\n"
+ "• And the third.\n"
+ "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯\n"
+ "Paragraph one isn't <b>very</b> long at all.\n"
+ "Paragraph two isn't much better.";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ markdown = "This is a spec file description or\n"
+ "an **update** description in bohdi.\n"
+ "\n"
+ "* * *\n"
+ "# Big title #\n"
+ "\n"
+ "The *following* things 'were' fixed:\n"
+ "- Fix `dave`\n"
+ "* Fubar update because of \"security\"\n";
+ markdown_expected =
+ "This is a spec file description or an <b>update</b> description in bohdi.\n"
+ "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯\n"
+ "<big>Big title</big>\n"
+ "The <i>following</i> things 'were' fixed:\n"
+ "• Fix <tt>dave</tt>\n"
+ "• Fubar update because of \"security\"";
+ /* markdown (complex2) */
+ text = gs_markdown_parse (md, markdown);
+ if (g_strcmp0 (text, markdown_expected) == 0)
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (list with spaces) */
+ markdown = "* list seporated with spaces -\n"
+ " first item\n"
+ "\n"
+ "* second item\n"
+ "\n"
+ "* third item\n";
+ markdown_expected =
+ "• list seporated with spaces - first item\n"
+ "• second item\n"
+ "• third item";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ gs_markdown_set_max_lines (md, 1);
+
+ /* markdown (one line limit) */
+ markdown = "* list seporated with spaces -\n"
+ " first item\n"
+ "* second item\n";
+ markdown_expected =
+ "• list seporated with spaces - first item";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ gs_markdown_set_max_lines (md, 1);
+
+ /* markdown (escaping) */
+ markdown = "* list & <spaces>";
+ markdown_expected =
+ "• list & <spaces>";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (URLs) */
+ markdown = "this is the http://www.hughsie.com/ coolest site";
+ markdown_expected =
+ "this is the "
+ "<a href=\"http://www.hughsie.com/\">http://www.hughsie.com/</a>"
+ " coolest site";
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+
+ /* markdown (free text) */
+ gs_markdown_set_escape (md, FALSE);
+ text = gs_markdown_parse (md, "This isn't a present");
+ g_assert_cmpstr (text, ==, "This isn't a present");
+ g_free (text);
+
+ /* markdown (autotext underscore) */
+ text = gs_markdown_parse (md, "This isn't CONFIG_UEVENT_HELPER_PATH present");
+ g_assert_cmpstr (text, ==, "This isn't <tt>CONFIG_UEVENT_HELPER_PATH</tt> present");
+ g_free (text);
+
+ /* markdown (end of bullett) */
+ markdown = "*Thu Mar 12 12:00:00 2009* Dan Walsh <dwalsh redhat com> - 2.0.79-1\n"
+ "- Update to upstream \n"
+ " * Netlink socket handoff patch from Adam Jackson.\n"
+ " * AVC caching of compute_create results by Eric Paris.\n"
+ "\n"
+ "*Tue Mar 10 12:00:00 2009* Dan Walsh <dwalsh redhat com> - 2.0.78-5\n"
+ "- Add patch from ajax to accellerate X SELinux \n"
+ "- Update eparis patch\n";
+ markdown_expected =
+ "<i>Thu Mar 12 12:00:00 2009</i> Dan Walsh <tt><dwalsh redhat com></tt> - 2.0.79-1\n"
+ "• Update to upstream\n"
+ "• Netlink socket handoff patch from Adam Jackson.\n"
+ "• AVC caching of compute_create results by Eric Paris.\n"
+ "<i>Tue Mar 10 12:00:00 2009</i> Dan Walsh <tt><dwalsh redhat com></tt> - 2.0.78-5\n"
+ "• Add patch from ajax to accellerate X SELinux\n"
+ "• Update eparis patch";
+ gs_markdown_set_escape (md, TRUE);
+ gs_markdown_set_max_lines (md, 1024);
+ text = gs_markdown_parse (md, markdown);
+ g_assert_cmpstr (text, ==, markdown_expected);
+ g_free (text);
+}
+
int
main (int argc, char **argv)
{
@@ -75,7 +257,8 @@ main (int argc, char **argv)
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
/* tests go here */
- g_test_add_func ("/moduleset", moduleset_func);
+ g_test_add_func ("/gnome-software/moduleset", moduleset_func);
+ g_test_add_func ("/gnome-software/markdown", gs_markdown_func);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]