1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2014 Theppitak Karoonboonyanan <theppitak@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * test_nonalpha.c - Test for datrie behaviors on non-alphabet inputs
24 * Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
27 #include <datrie/trie.h>
32 const AlphaChar *nonalpha_src[] = {
33 (AlphaChar *)L"a6acus",
34 (AlphaChar *)L"a5acus",
43 const AlphaChar **nonalpha_key;
47 msg_step ("Preparing trie");
48 test_trie = en_trie_new ();
50 fprintf (stderr, "Fail to create test trie\n");
51 goto err_trie_not_created;
55 msg_step ("Adding data to trie");
56 for (dict_p = dict_src; dict_p->key; dict_p++) {
57 if (!trie_store (test_trie, dict_p->key, dict_p->data)) {
58 printf ("Failed to add key '%ls', data %d.\n",
59 (wchar_t *)dict_p->key, dict_p->data);
60 goto err_trie_created;
64 /* test storing keys with non-alphabet chars */
66 for (nonalpha_key = nonalpha_src; *nonalpha_key; nonalpha_key++) {
67 if (trie_retrieve (test_trie, *nonalpha_key, &trie_data)) {
68 printf ("False duplication on key '%ls', with existing data %d.\n",
69 (wchar_t *)*nonalpha_key, trie_data);
72 if (trie_store (test_trie, *nonalpha_key, TRIE_DATA_UNREAD)) {
73 printf ("Wrongly added key '%ls' containing non-alphanet char\n",
74 (wchar_t *)*nonalpha_key);
80 goto err_trie_created;
82 trie_free (test_trie);
86 trie_free (test_trie);