1 /* Test of exact or abbreviated match search.
2 Copyright (C) 1990, 1998-1999, 2001-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code
18 by David MacKenzie <djm@gnu.ai.mit.edu>. */
29 /* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
30 thus must link with a definition of that function. Provide it here. */
31 #ifdef ARGMATCH_DIE_DECL
32 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
33 # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
35 # define _GL_ATTRIBUTE_NORETURN /* empty */
38 ARGMATCH_DIE_DECL _GL_ATTRIBUTE_NORETURN;
39 ARGMATCH_DIE_DECL { exit (1); }
46 numbered_existing_backups,
50 static const char *const backup_args[] =
53 "simple", "never", "single",
54 "existing", "nil", "numbered-existing",
55 "numbered", "t", "newstyle",
59 static const enum backup_type backup_vals[] =
61 no_backups, no_backups, no_backups,
62 simple_backups, simple_backups, simple_backups,
63 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
64 numbered_backups, numbered_backups, numbered_backups
68 main (int argc, char *argv[])
70 set_program_name (argv[0]);
73 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
76 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
77 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
80 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
83 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
84 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
85 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
87 /* Exact match and abbreviated. */
88 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
89 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
90 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
91 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
92 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
93 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
94 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
95 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
97 /* Ambiguous abbreviated. */
98 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
100 /* Ambiguous abbreviated, but same value. */
101 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
102 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);