~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to gnulib-tests/test-argmatch.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- buffer-read-only: t -*- vi: set ro: */
 
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 
3
/* Test of exact or abbreviated match search.
 
4
   Copyright (C) 1990, 1998-1999, 2001-2010 Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software: you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program 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
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
18
 
 
19
/* Written by Bruno Haible <bruno@clisp.org>, 2007, based on test code
 
20
   by David MacKenzie <djm@gnu.ai.mit.edu>.  */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include "argmatch.h"
 
25
 
 
26
#include <stdlib.h>
 
27
 
 
28
#include "progname.h"
 
29
#include "macros.h"
 
30
 
 
31
/* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
 
32
   thus must link with a definition of that function.  Provide it here.  */
 
33
#ifdef ARGMATCH_DIE_DECL
 
34
ARGMATCH_DIE_DECL { exit (1); }
 
35
#endif
 
36
 
 
37
enum backup_type
 
38
{
 
39
  no_backups,
 
40
  simple_backups,
 
41
  numbered_existing_backups,
 
42
  numbered_backups
 
43
};
 
44
 
 
45
static const char *const backup_args[] =
 
46
{
 
47
  "no", "none", "off",
 
48
  "simple", "never", "single",
 
49
  "existing", "nil", "numbered-existing",
 
50
  "numbered", "t", "newstyle",
 
51
  NULL
 
52
};
 
53
 
 
54
static const enum backup_type backup_vals[] =
 
55
{
 
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
 
60
};
 
61
 
 
62
int
 
63
main (int argc, char *argv[])
 
64
{
 
65
  set_program_name (argv[0]);
 
66
 
 
67
  /* Not found.  */
 
68
  ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1);
 
69
 
 
70
  /* Exact match.  */
 
71
  ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1);
 
72
  ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7);
 
73
 
 
74
  /* Too long.  */
 
75
  ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1);
 
76
 
 
77
  /* Abbreviated.  */
 
78
  ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3);
 
79
  ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3);
 
80
  ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3);
 
81
 
 
82
  /* Exact match and abbreviated.  */
 
83
  ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9);
 
84
  ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2);
 
85
  ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2);
 
86
  ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2);
 
87
  ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2);
 
88
  ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2);
 
89
  ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2);
 
90
  ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2);
 
91
 
 
92
  /* Ambiguous abbreviated.  */
 
93
  ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2);
 
94
 
 
95
  /* Ambiguous abbreviated, but same value.  */
 
96
  ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3);
 
97
  ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3);
 
98
 
 
99
  return 0;
 
100
}