Blame tests/completion-test.c

Packit ae235b
/* GLIB - Library of useful routines for C programming
Packit ae235b
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit ae235b
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit ae235b
 * files for a list of changes.  These files are distributed with
Packit ae235b
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
Packit ae235b
 */
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "glib.h"
Packit ae235b
Packit ae235b
int main (int argc, char *argv[])
Packit ae235b
{
Packit ae235b
  GCompletion *cmp;
Packit ae235b
  GList *items;
Packit ae235b
  gchar *prefix;
Packit ae235b
  
Packit ae235b
  cmp = g_completion_new (NULL);
Packit ae235b
  g_completion_set_compare (cmp, strncmp);
Packit ae235b
Packit ae235b
  items = NULL;
Packit ae235b
  items = g_list_append (items, "a\302\243");
Packit ae235b
  items = g_list_append (items, "a\302\244");
Packit ae235b
  items = g_list_append (items, "bb");
Packit ae235b
  items = g_list_append (items, "bc");
Packit ae235b
  g_completion_add_items (cmp, items);
Packit ae235b
  g_list_free (items);
Packit ae235b
Packit ae235b
  items = g_completion_complete (cmp, "a", &prefix);
Packit ae235b
  g_assert (!strcmp ("a\302", prefix));
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
  g_free (prefix);
Packit ae235b
  
Packit ae235b
  items = g_completion_complete_utf8 (cmp, "a", &prefix);
Packit ae235b
  g_assert (!strcmp ("a", prefix));
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
  g_free (prefix);
Packit ae235b
Packit ae235b
  items = g_completion_complete (cmp, "b", &prefix);
Packit ae235b
  g_assert (!strcmp ("b", prefix));
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
  g_free (prefix);
Packit ae235b
  
Packit ae235b
  items = g_completion_complete_utf8 (cmp, "b", &prefix);
Packit ae235b
  g_assert (!strcmp ("b", prefix));
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
  g_free (prefix);
Packit ae235b
Packit ae235b
  items = g_completion_complete (cmp, "a", NULL);
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
Packit ae235b
  items = g_completion_complete_utf8 (cmp, "a", NULL);
Packit ae235b
  g_assert (g_list_length (items) == 2);
Packit ae235b
Packit ae235b
  items = g_list_append (NULL, "bb");
Packit ae235b
  g_completion_remove_items (cmp, items);
Packit ae235b
  g_list_free (items);
Packit ae235b
Packit ae235b
  items = g_completion_complete_utf8 (cmp, "b", &prefix);
Packit ae235b
  g_assert (g_list_length (items) == 1);
Packit ae235b
  g_free (prefix);
Packit ae235b
Packit ae235b
  g_completion_free (cmp);
Packit ae235b
Packit ae235b
  return 0;
Packit ae235b
}