File: test-encoding.c

package info (click to toggle)
libgedit-gtksourceview 299.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,608 kB
  • sloc: ansic: 49,191; xml: 2,676; perl: 206; sh: 57; yacc: 45; makefile: 30; cobol: 20; objc: 19; javascript: 16; fortran: 14; python: 13; cpp: 8; ml: 3
file content (53 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download
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
/* SPDX-FileCopyrightText: 2014-2025 - Sébastien Wilmet <swilmet@gnome.org>
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gtksourceview/gtksource.h>

static void
test_remove_duplicates (void)
{
	GSList *list = NULL;
	GtkSourceEncoding *utf8;
	GtkSourceEncoding *iso;

	utf8 = gtk_source_encoding_new_utf8 ();
	iso = gtk_source_encoding_new ("ISO-8859-15");

	/* Before: [UTF-8, ISO-8859-15, UTF-8] */
	list = g_slist_prepend (list, gtk_source_encoding_copy (utf8));
	list = g_slist_prepend (list, gtk_source_encoding_copy (iso));
	list = g_slist_prepend (list, gtk_source_encoding_copy (utf8));

	/* After: [UTF-8, ISO-8859-15] */
	list = gtk_source_encoding_remove_duplicates (list, GTK_SOURCE_ENCODING_DUPLICATES_KEEP_FIRST);

	g_assert_cmpint (2, ==, g_slist_length (list));
	g_assert_true (gtk_source_encoding_equals (list->data, utf8));
	g_assert_true (gtk_source_encoding_equals (list->next->data, iso));

	/* Before: [UTF-8, ISO-8859-15, UTF-8] */
	list = g_slist_append (list, gtk_source_encoding_copy (utf8));

	/* After: [ISO-8859-15, UTF-8] */
	list = gtk_source_encoding_remove_duplicates (list, GTK_SOURCE_ENCODING_DUPLICATES_KEEP_LAST);

	g_assert_cmpint (2, ==, g_slist_length (list));
	g_assert_true (gtk_source_encoding_equals (list->data, iso));
	g_assert_true (gtk_source_encoding_equals (list->next->data, utf8));

	g_slist_free_full (list, (GDestroyNotify)gtk_source_encoding_free);
	gtk_source_encoding_free (utf8);
	gtk_source_encoding_free (iso);
}

int
main (int    argc,
      char **argv)
{
	gtk_test_init (&argc, &argv);

	g_test_add_func ("/Encoding/remove_duplicates", test_remove_duplicates);

	return g_test_run ();
}