1/* Test of exact or abbreviated match search. 2 Copyright (C) 1990, 1998-1999, 2001-2007 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 <stdio.h> 25#include <stdlib.h> 26 27#include "progname.h" 28 29#define ASSERT(expr) \ 30 do \ 31 { \ 32 if (!(expr)) \ 33 { \ 34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ 35 abort (); \ 36 } \ 37 } \ 38 while (0) 39 40enum backup_type 41{ 42 no_backups, 43 simple_backups, 44 numbered_existing_backups, 45 numbered_backups 46}; 47 48static const char *const backup_args[] = 49{ 50 "no", "none", "off", 51 "simple", "never", "single", 52 "existing", "nil", "numbered-existing", 53 "numbered", "t", "newstyle", 54 NULL 55}; 56 57static const enum backup_type backup_vals[] = 58{ 59 no_backups, no_backups, no_backups, 60 simple_backups, simple_backups, simple_backups, 61 numbered_existing_backups, numbered_existing_backups, numbered_existing_backups, 62 numbered_backups, numbered_backups, numbered_backups 63}; 64 65int 66main (int argc, char *argv[]) 67{ 68 set_program_name (argv[0]); 69 70 /* Not found. */ 71 ASSERT (ARGMATCH ("klingon", backup_args, backup_vals) == -1); 72 73 /* Exact match. */ 74 ASSERT (ARGMATCH ("none", backup_args, backup_vals) == 1); 75 ASSERT (ARGMATCH ("nil", backup_args, backup_vals) == 7); 76 77 /* Too long. */ 78 ASSERT (ARGMATCH ("nilpotent", backup_args, backup_vals) == -1); 79 80 /* Abbreviated. */ 81 ASSERT (ARGMATCH ("simpl", backup_args, backup_vals) == 3); 82 ASSERT (ARGMATCH ("simp", backup_args, backup_vals) == 3); 83 ASSERT (ARGMATCH ("sim", backup_args, backup_vals) == 3); 84 85 /* Exact match and abbreviated. */ 86 ASSERT (ARGMATCH ("numbered", backup_args, backup_vals) == 9); 87 ASSERT (ARGMATCH ("numbere", backup_args, backup_vals) == -2); 88 ASSERT (ARGMATCH ("number", backup_args, backup_vals) == -2); 89 ASSERT (ARGMATCH ("numbe", backup_args, backup_vals) == -2); 90 ASSERT (ARGMATCH ("numb", backup_args, backup_vals) == -2); 91 ASSERT (ARGMATCH ("num", backup_args, backup_vals) == -2); 92 ASSERT (ARGMATCH ("nu", backup_args, backup_vals) == -2); 93 ASSERT (ARGMATCH ("n", backup_args, backup_vals) == -2); 94 95 /* Ambiguous abbreviated. */ 96 ASSERT (ARGMATCH ("ne", backup_args, backup_vals) == -2); 97 98 /* Ambiguous abbreviated, but same value. */ 99 ASSERT (ARGMATCH ("si", backup_args, backup_vals) == 3); 100 ASSERT (ARGMATCH ("s", backup_args, backup_vals) == 3); 101 102 return 0; 103} 104