1 /*
   2  * Copyright (c) 2000 Sendmail, Inc. and its suppliers.
   3  *      All rights reserved.
   4  *
   5  * By using this file, you agree to the terms and conditions set
   6  * forth in the LICENSE file which can be found at the top level of
   7  * the sendmail distribution.
   8  */
   9 
  10 #pragma ident   "%Z%%M% %I%     %E% SMI"
  11 
  12 #include <sm/gen.h>
  13 SM_IDSTR(id, "@(#)$Id: t-match.c,v 1.7 2000/12/18 18:12:12 ca Exp $")
  14 
  15 #include <sm/string.h>
  16 #include <sm/io.h>
  17 #include <sm/test.h>
  18 
  19 #define try(str, pat, want) \
  20         got = sm_match(str, pat); \
  21         if (!SM_TEST(got == want)) \
  22                 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, \
  23                         "sm_match(\"%s\", \"%s\") returns %s\n", \
  24                         str, pat, got ? "true" : "false");
  25 
  26 int
  27 main(argc, argv)
  28         int argc;
  29         char **argv;
  30 {
  31         bool got;
  32 
  33         sm_test_begin(argc, argv, "test sm_match");
  34 
  35         try("foo", "foo", true);
  36         try("foo", "bar", false);
  37         try("foo[bar", "foo[bar", true);
  38         try("foo[bar]", "foo[bar]", false);
  39         try("foob", "foo[bar]", true);
  40         try("a-b", "a[]-]b", true);
  41         try("abcde", "a*e", true);
  42         try("[", "[[]", true);
  43         try("c", "[a-z]", true);
  44         try("C", "[a-z]", false);
  45         try("F:sm.heap", "[!F]*", false);
  46         try("E:sm.err", "[!F]*", true);
  47 
  48         return sm_test_end();
  49 }