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>
31 const AlphaChar *nonalpha_src[] = {
32 (AlphaChar *)L"a6acus",
33 (AlphaChar *)L"a5acus",
42 const AlphaChar **nonalpha_key;
46 msg_step ("Preparing trie");
47 test_trie = en_trie_new ();
49 fprintf (stderr, "Fail to create test trie\n");
50 goto err_trie_not_created;
54 msg_step ("Adding data to trie");
55 for (dict_p = dict_src; dict_p->key; dict_p++) {
56 if (!trie_store (test_trie, dict_p->key, dict_p->data)) {
57 printf ("Failed to add key '%ls', data %d.\n",
58 dict_p->key, dict_p->data);
59 goto err_trie_created;
63 /* test storing keys with non-alphabet chars */
65 for (nonalpha_key = nonalpha_src; *nonalpha_key; nonalpha_key++) {
66 if (trie_retrieve (test_trie, *nonalpha_key, &trie_data)) {
67 printf ("False duplication on key '%ls', with existing data %d.\n",
68 *nonalpha_key, trie_data);
71 if (trie_store (test_trie, *nonalpha_key, TRIE_DATA_UNREAD)) {
72 printf ("Wrongly added key '%ls' containing non-alphanet char\n",
79 goto err_trie_created;
81 trie_free (test_trie);
85 trie_free (test_trie);