VirtualBox

source: kBuild/vendor/grep/2.12/gnulib-tests/test-argmatch.c@ 3627

Last change on this file since 3627 was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/* Test of exact or abbreviated match search.
2 Copyright (C) 1990, 1998-1999, 2001-2012 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17/* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code
18 by David MacKenzie <djm@gnu.ai.mit.edu>. */
19
20#include <config.h>
21
22#include "argmatch.h"
23
24#include <stdlib.h>
25
26#include "progname.h"
27#include "macros.h"
28
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
33_Noreturn ARGMATCH_DIE_DECL;
34ARGMATCH_DIE_DECL { exit (1); }
35
36#endif
37
38enum backup_type
39{
40 no_backups,
41 simple_backups,
42 numbered_existing_backups,
43 numbered_backups
44};
45
46static const char *const backup_args[] =
47{
48 "no", "none", "off",
49 "simple", "never", "single",
50 "existing", "nil", "numbered-existing",
51 "numbered", "t", "newstyle",
52 NULL
53};
54
55static const enum backup_type backup_vals[] =
56{
57 no_backups, no_backups, no_backups,
58 simple_backups, simple_backups, simple_backups,
59 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups,
60 numbered_backups, numbered_backups, numbered_backups
61};
62
63int
64main (int argc, char *argv[])
65{
66 set_program_name (argv[0]);
67
68 /* Not found. */
69 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
70
71 /* Exact match. */
72 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
73 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
74
75 /* Too long. */
76 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
77
78 /* Abbreviated. */
79 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
80 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
81 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
82
83 /* Exact match and abbreviated. */
84 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
85 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
86 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
87 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
88 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
89 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
90 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
91 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
92
93 /* Ambiguous abbreviated. */
94 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
95
96 /* Ambiguous abbreviated, but same value. */
97 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
98 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
99
100 return 0;
101}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette