error: Avoid "function declaration isn't a prototype" warning.
[gnulib.git] / tests / test-argmatch.c
blob5fe0df73db792a72b2e1041b2faddd86236b9c93
1 /* Test of exact or abbreviated match search.
2 Copyright (C) 1990, 1998-1999, 2001-2017 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>. */
20 #include <config.h>
22 #include "argmatch.h"
24 #include <stdlib.h>
26 #include "macros.h"
28 /* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
29 thus must link with a definition of that function. Provide it here. */
30 #ifdef ARGMATCH_DIE_DECL
32 _Noreturn ARGMATCH_DIE_DECL;
33 ARGMATCH_DIE_DECL { exit (1); }
35 #endif
37 enum backup_type
39 no_backups,
40 simple_backups,
41 numbered_existing_backups,
42 numbered_backups
45 static const char *const backup_args[] =
47 "no", "none", "off",
48 "simple", "never", "single",
49 "existing", "nil", "numbered-existing",
50 "numbered", "t", "newstyle",
51 NULL
54 static const enum backup_type backup_vals[] =
56 no_backups, no_backups, no_backups,
57 simple_backups, simple_backups, simple_backups,
58 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
59 numbered_backups, numbered_backups, numbered_backups
62 int
63 main (int argc, char *argv[])
65 /* Not found. */
66 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
68 /* Exact match. */
69 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
70 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
72 /* Too long. */
73 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
75 /* Abbreviated. */
76 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
77 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
78 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
80 /* Exact match and abbreviated. */
81 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
82 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
83 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
84 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
85 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
86 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
87 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
88 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
90 /* Ambiguous abbreviated. */
91 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
93 /* Ambiguous abbreviated, but same value. */
94 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
95 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
97 return 0;