[gnome-builder] plugins/copyright: port plugin to C



commit b7f710440c054df71045c83bdeaed43335ee6201
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 11 22:23:24 2022 -0700

    plugins/copyright: port plugin to C

 src/plugins/copyright/copyright-plugin.c           |  39 +++++++
 src/plugins/copyright/copyright.plugin             |   6 +-
 src/plugins/copyright/copyright_plugin.py          | 121 --------------------
 src/plugins/copyright/gbp-copyright-buffer-addin.c | 127 +++++++++++++++++++++
 src/plugins/copyright/gbp-copyright-buffer-addin.h |  32 ++++++
 .../copyright/gbp-copyright-preferences-addin.c    |  85 ++++++++++++++
 .../copyright/gbp-copyright-preferences-addin.h    |  32 ++++++
 src/plugins/copyright/gbp-copyright-util.c         | 116 +++++++++++++++++++
 src/plugins/copyright/gbp-copyright-util.h         |  30 +++++
 src/plugins/copyright/meson.build                  |  22 ++--
 src/plugins/copyright/test-copyright.c             |  60 ++++++++++
 11 files changed, 537 insertions(+), 133 deletions(-)
---
diff --git a/src/plugins/copyright/copyright-plugin.c b/src/plugins/copyright/copyright-plugin.c
new file mode 100644
index 000000000..3bb6ac1ac
--- /dev/null
+++ b/src/plugins/copyright/copyright-plugin.c
@@ -0,0 +1,39 @@
+/* copyright-plugin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Tristan Partin <tristan partin io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <libpeas/peas.h>
+
+#include <libide-core.h>
+#include <libide-gui.h>
+
+#include "gbp-copyright-buffer-addin.h"
+#include "gbp-copyright-preferences-addin.h"
+
+_IDE_EXTERN void
+_gbp_copyright_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PREFERENCES_ADDIN,
+                                              GBP_TYPE_COPYRIGHT_PREFERENCES_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUFFER_ADDIN,
+                                              GBP_TYPE_COPYRIGHT_BUFFER_ADDIN);
+}
diff --git a/src/plugins/copyright/copyright.plugin b/src/plugins/copyright/copyright.plugin
index a4e35eafb..f389cb6a4 100644
--- a/src/plugins/copyright/copyright.plugin
+++ b/src/plugins/copyright/copyright.plugin
@@ -3,7 +3,9 @@ Authors=Christian Hergert <chergert redhat com>
 Builtin=true
 Copyright=Copyright © 2020 Christian Hergert
 Description=Update copyright when files are saved
-Loader=python3
+Embedded=_gbp_copyright_register_types
 Module=copyright_plugin
 Name=Update Copyright
-X-Builder-ABI=@PACKAGE_ABI@
+X-Category=editing
+X-Preferences-Kind=application;
+
diff --git a/src/plugins/copyright/gbp-copyright-buffer-addin.c 
b/src/plugins/copyright/gbp-copyright-buffer-addin.c
new file mode 100644
index 000000000..10870f4f8
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-buffer-addin.c
@@ -0,0 +1,127 @@
+/* gbp-copyright-buffer-addin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Tristan Partin <tristan partin io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-copyright-buffer-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-code.h>
+#include <libide-gui.h>
+
+#include "gbp-copyright-buffer-addin.h"
+#include "gbp-copyright-util.h"
+
+#define MAX_LINE 100
+#define MAX_BYTES_IN_SCAN (64 << 10) /* 64kb */
+
+static GSettings *copyright_settings;
+
+struct _GbpCopyrightBufferAddin
+{
+  GObject parent_instance;
+};
+
+static void
+gbp_copyright_buffer_addin_save_file (IdeBufferAddin *addin,
+                                      IdeBuffer      *buffer,
+                                      GFile          *file)
+{
+  GbpCopyrightBufferAddin *self = GBP_COPYRIGHT_BUFFER_ADDIN (addin);
+  g_autoptr(GDateTime) now = NULL;
+  g_autofree char *year = NULL;
+  const char *name;
+  GtkTextIter iter, limit;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_COPYRIGHT_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+  g_assert (G_IS_FILE (file));
+
+  if (!g_settings_get_boolean (copyright_settings, "update-on-save"))
+    IDE_EXIT;
+
+  name = g_get_real_name ();
+  if (ide_str_equal0 (name, "Unknown"))
+    IDE_EXIT;
+
+  now = g_date_time_new_now_local ();
+  year = g_date_time_format (now, "%Y");
+
+  gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
+  gtk_text_buffer_get_iter_at_line_offset (GTK_TEXT_BUFFER (buffer), &limit, MAX_LINE, 0);
+
+  /* Protect against situations where a user may have opened a minified file */
+  if ((gtk_text_iter_get_offset (&limit) - gtk_text_iter_get_offset (&iter)) > MAX_BYTES_IN_SCAN)
+    IDE_EXIT;
+
+  while (gtk_text_iter_compare (&iter, &limit) < 0)
+    {
+      GtkTextIter match_begin, match_end;
+      g_autofree char *text = NULL;
+      g_autofree char *replace = NULL;
+
+      if (!gtk_text_iter_forward_search (&iter, name, GTK_TEXT_SEARCH_TEXT_ONLY, &match_begin, &match_end, 
&limit))
+        continue;
+
+      gtk_text_iter_set_line_offset (&match_begin, 0);
+      if (!gtk_text_iter_ends_line (&match_end))
+        gtk_text_iter_forward_to_line_end (&match_end);
+
+      text = gtk_text_iter_get_slice (&match_begin, &match_end);
+
+      if ((replace = gbp_update_copyright (text, year)))
+        {
+          gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
+          gtk_text_buffer_delete (GTK_TEXT_BUFFER (buffer), &match_begin, &match_end);
+          gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &match_begin, replace, -1);
+          gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
+          IDE_EXIT;
+        }
+
+      iter = match_end;
+    }
+
+  IDE_EXIT;
+}
+
+static void
+buffer_addin_init (IdeBufferAddinInterface *iface)
+{
+  iface->save_file = gbp_copyright_buffer_addin_save_file;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpCopyrightBufferAddin, gbp_copyright_buffer_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_BUFFER_ADDIN, buffer_addin_init))
+
+static void
+gbp_copyright_buffer_addin_class_init (GbpCopyrightBufferAddinClass *klass)
+{
+  copyright_settings = g_settings_new("org.gnome.builder.plugins.copyright");
+}
+
+static void
+gbp_copyright_buffer_addin_init (GbpCopyrightBufferAddin *self)
+{
+}
diff --git a/src/plugins/copyright/gbp-copyright-buffer-addin.h 
b/src/plugins/copyright/gbp-copyright-buffer-addin.h
new file mode 100644
index 000000000..101fa7557
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-buffer-addin.h
@@ -0,0 +1,32 @@
+/* gbp-copyright-buffer-addin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Tristan Partin <tristan partin io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_COPYRIGHT_BUFFER_ADDIN (gbp_copyright_buffer_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpCopyrightBufferAddin, gbp_copyright_buffer_addin, GBP, COPYRIGHT_BUFFER_ADDIN, 
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/copyright/gbp-copyright-preferences-addin.c 
b/src/plugins/copyright/gbp-copyright-preferences-addin.c
new file mode 100644
index 000000000..39e11fbda
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-preferences-addin.c
@@ -0,0 +1,85 @@
+/* gbp-copyright-preferences-addin.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Tristan Partin <tristan partin io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-copyright-preferences-addin"
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include <libide-gui.h>
+#include <libide-sourceview.h>
+
+#include "gbp-copyright-preferences-addin.h"
+
+#define SCHEMA_ID "org.gnome.builder.plugins.copyright"
+
+struct _GbpCopyrightPreferencesAddin
+{
+  GObject parent_instance;
+};
+
+static const IdePreferenceItemEntry preference_items[] = {
+  { .page = "editing", .group = "formatting", .name = "update-copyright", .priority = 0,
+    .callback = ide_preferences_window_toggle, .title = N_("Update Copyright"),
+    .subtitle = N_("Automatically update copyright headers when saving a file"),
+    .schema_id = SCHEMA_ID, .key = "update-on-save",
+  }
+};
+
+static void
+gbp_copyright_preferences_addin_load (IdePreferencesAddin  *addin,
+                                     IdePreferencesWindow *window,
+                                     IdeContext           *context)
+{
+  GbpCopyrightPreferencesAddin *self = GBP_COPYRIGHT_PREFERENCES_ADDIN (addin);
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_COPYRIGHT_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+  g_assert (!context || IDE_IS_CONTEXT (context));
+
+  ide_preferences_window_add_items (window, preference_items, G_N_ELEMENTS (preference_items), NULL, NULL);
+
+  IDE_EXIT;
+}
+
+static void
+preferences_addin_init (IdePreferencesAddinInterface *iface)
+{
+  iface->load = gbp_copyright_preferences_addin_load;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpCopyrightPreferencesAddin, gbp_copyright_preferences_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, preferences_addin_init))
+
+static void
+gbp_copyright_preferences_addin_class_init (GbpCopyrightPreferencesAddinClass *klass)
+{
+}
+
+static void
+gbp_copyright_preferences_addin_init (GbpCopyrightPreferencesAddin *self)
+{
+}
diff --git a/src/plugins/copyright/gbp-copyright-preferences-addin.h 
b/src/plugins/copyright/gbp-copyright-preferences-addin.h
new file mode 100644
index 000000000..a7e7cc430
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-preferences-addin.h
@@ -0,0 +1,32 @@
+/* gbp-copyright-preferences-addin.h
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ * Copyright 2022 Tristan Partin <tristan partin io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_COPYRIGHT_PREFERENCES_ADDIN (gbp_copyright_preferences_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpCopyrightPreferencesAddin, gbp_copyright_preferences_addin, GBP, 
COPYRIGHT_PREFERENCES_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/copyright/gbp-copyright-util.c b/src/plugins/copyright/gbp-copyright-util.c
new file mode 100644
index 000000000..0012fb1be
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-util.c
@@ -0,0 +1,116 @@
+/* gbp-copyright-util.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-copyright-util"
+
+#include "config.h"
+
+#include "gbp-copyright-util.h"
+
+static inline gboolean
+is_dash (const char *token)
+{
+  return token[0] == '-' && token[1] == 0;
+}
+
+static inline gboolean
+isalnumdigit (char c)
+{
+  return c >= '0' && 'c' <= '9';
+}
+
+static inline gboolean
+is_year (const char *token)
+{
+  return token[0] != 0 && isalnumdigit (token[0]) &&
+         token[1] != 0 && isalnumdigit (token[1]) &&
+         token[2] != 0 && isalnumdigit (token[2]) &&
+         token[3] != 0 && isalnumdigit (token[3]) &&
+         token[4] == 0;
+}
+
+static char *
+replace_copyright_year (const char * const *tokens,
+                        guint               n_tokens,
+                        const char         *with_year)
+{
+  g_autoptr(GPtrArray) ar = NULL;
+  int dash = -1;
+
+  ar = g_ptr_array_sized_new (n_tokens + 3);
+  memcpy (ar->pdata, tokens, sizeof (char *) * n_tokens);
+  ar->pdata[n_tokens] = NULL;
+  ar->len = n_tokens + 1;
+
+  for (guint i = 0; i < n_tokens; i++)
+    {
+      if (i > 0 && is_dash (tokens[i]))
+        dash = i;
+      else if (g_strcmp0 (tokens[i], with_year) == 0)
+        return NULL;
+    }
+
+  if (dash >= 0)
+    {
+      if (dash+1 < n_tokens && is_year (tokens[dash+1]))
+        g_ptr_array_index (ar, dash+1) = (gpointer)with_year;
+      else
+        g_ptr_array_insert (ar, dash+1, (gpointer)with_year);
+    }
+  else
+    {
+      g_ptr_array_insert (ar, 2, (gpointer)"-");
+      g_ptr_array_insert (ar, 3, (gpointer)with_year);
+
+      /* Maybe swallow trailing - like "2022- " */
+      if (ar->pdata[4] != NULL && ((char *)ar->pdata[4])[0] == '-')
+        ar->pdata[4] = &((char *)ar->pdata[4])[1];
+    }
+
+  return g_strjoinv (NULL, (char **)(gpointer)ar->pdata);
+}
+
+char *
+gbp_update_copyright (const char *input,
+                      const char *with_year)
+{
+  static GRegex *regex;
+  g_auto(GStrv) tokens = NULL;
+  guint n_tokens;
+
+  if (input == NULL || input[0] == 0)
+    return NULL;
+
+  if (regex == NULL)
+    regex = g_regex_new ("([0-9]{4})", G_REGEX_OPTIMIZE, 0, NULL);
+
+  tokens = g_regex_split (regex, input, 0);
+
+  /* n_tokens > 2 */
+  if (tokens == NULL || tokens[0] == NULL || tokens[1] == NULL)
+    return NULL;
+
+  /* Sanity check */
+  n_tokens = g_strv_length (tokens);
+  if (n_tokens > 6)
+    return NULL;
+
+  return replace_copyright_year ((const char * const *)tokens, n_tokens, with_year);
+}
diff --git a/src/plugins/copyright/gbp-copyright-util.h b/src/plugins/copyright/gbp-copyright-util.h
new file mode 100644
index 000000000..caf27912a
--- /dev/null
+++ b/src/plugins/copyright/gbp-copyright-util.h
@@ -0,0 +1,30 @@
+/* gbp-copyright-util.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+char *gbp_update_copyright (const char *input,
+                            const char *with_year);
+
+G_END_DECLS
diff --git a/src/plugins/copyright/meson.build b/src/plugins/copyright/meson.build
index ba75e7bbe..5ba17ab71 100644
--- a/src/plugins/copyright/meson.build
+++ b/src/plugins/copyright/meson.build
@@ -1,14 +1,16 @@
 if get_option('plugin_copyright')
+  plugins_sources += files(
+    'copyright-plugin.c',
+    'gbp-copyright-buffer-addin.c',
+    'gbp-copyright-preferences-addin.c',
+    'gbp-copyright-util.c',
+  )
 
-install_data('copyright_plugin.py', install_dir: plugindir)
-install_data('org.gnome.builder.plugins.copyright.gschema.xml', install_dir: schema_dir)
-
-configure_file(
-          input: 'copyright.plugin',
-         output: 'copyright.plugin',
-  configuration: config_h,
-        install: true,
-    install_dir: plugindir,
-)
+  install_data('org.gnome.builder.plugins.copyright.gschema.xml', install_dir: schema_dir)
 
+  test_copyright = executable('test-copyright',
+    ['test-copyright.c', 'gbp-copyright-util.c'],
+    dependencies: [ libglib_dep ],
+  )
+  test('test-copyright', test_copyright)
 endif
diff --git a/src/plugins/copyright/test-copyright.c b/src/plugins/copyright/test-copyright.c
new file mode 100644
index 000000000..e34517a37
--- /dev/null
+++ b/src/plugins/copyright/test-copyright.c
@@ -0,0 +1,60 @@
+/* test-copyright.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "gbp-copyright-util.h"
+
+#define TEST_YEAR "2042"
+
+static void
+test_update_copyright (void)
+{
+  static const struct {
+    const char *input;
+    const char *output; /* NULL indicates no change requested */
+  } copyright_year_tests[] = {
+    { "1234", "1234-"TEST_YEAR },
+    { " 1234-", " 1234-"TEST_YEAR },
+    { "-1234", "-1234-"TEST_YEAR }, /* odd, but expected */
+    { "-", NULL },
+    { "", NULL },
+    { "# Copyright 2019 Foo", "# Copyright 2019-"TEST_YEAR" Foo" },
+    { "# Copyright "TEST_YEAR" Foo", NULL },
+    { "# Copyright -"TEST_YEAR" Foo", NULL },
+    { "/* Copyright "TEST_YEAR"- Foo */", NULL },
+    { "# Copyright 2019- Foo", "# Copyright 2019-"TEST_YEAR" Foo" },
+    { "# Copyright - ", NULL },
+  };
+
+  for (guint i = 0; i < G_N_ELEMENTS (copyright_year_tests); i++)
+    {
+      g_autofree char *replaced = gbp_update_copyright (copyright_year_tests[i].input, TEST_YEAR);
+
+      g_assert_cmpstr (replaced, ==, copyright_year_tests[i].output);
+    }
+}
+
+int
+main (int argc,
+      char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/Plugins/Copyright/update_copyright", test_update_copyright);
+  return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]