Ignore:
Timestamp:
Jun 13, 2010, 6:46:29 PM (11 years ago)
Author:
Peter Johansson
Message:

closes #450. extend filename matching tp allow [xyz] and ?. Also fixed a bug when having asterisk (*) in end of pattern string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r1096 r1098  
    4343  ok &= test_fnmatch(true,"peter", "peter");
    4444  ok &= test_fnmatch(false,"peter", "peterj");
     45
     46  ok &= test_fnmatch(true,"*", "peterj");
    4547  ok &= test_fnmatch(true,"p*", "peterj");
    4648  ok &= test_fnmatch(true, "p*", "peter");
    4749  ok &= test_fnmatch(false, "p*j", "peter");
     50  ok &= test_fnmatch(true, "p*j", "peterj");
    4851  ok &= test_fnmatch(true, "*peter", "peter");
     52
     53  ok &= test_fnmatch(true, "p?ter", "peter");
     54  ok &= test_fnmatch(false, "p?er", "peter");
     55  ok &= test_fnmatch(false, "p?eter", "peter");
    4956
    5057  ok &= test_fnmatch(true, "filename", "filename");
    5158  ok &= test_fnmatch(true, "*name", "filename");
    5259  ok &= test_fnmatch(true, "[fa]il?name", "filename");
     60  ok &= test_fnmatch(true, "[fa]*il?name", "ffilename");
     61
     62  ok &= test_fnmatch(true, "[fa]*il?name", "fafafailename");
     63  ok &= test_fnmatch(false, "[fa]?il?name", "ilename");
     64  ok &= test_fnmatch(false, "?[fa]il?name", "ilename");
     65  ok &= test_fnmatch(true, "[fa]il?name", "filename");
     66  ok &= test_fnmatch(false, "[fa]?il?name", "fafafailename");
     67
    5368  ok &= test_fnmatch(true, "*name", "/path/to/filename");
    5469  ok &= test_fnmatch(true, "*name", "file.name");
    55   // posix dictates that leading persion can not be matched by wildcard
    56   ok &= test_fnmatch(false, "*.txt", ".file.txt");
     70  // posix dictates that leading period can not be matched by
     71  // wildcard, but here we allow match
     72  ok &= test_fnmatch(true, "*.txt", ".file.txt");
     73
    5774
    5875  std::vector<std::string> vec;
    5976  ok &= test_regexp(true,"abcde", "abcde", vec);
     77  vec.push_back("c");
     78  ok &= test_regexp(true,"ab?de", "abcde", vec);
     79  vec[0] = "bcd";
     80  ok &= test_regexp(true,"a*e", "abcde", vec);
    6081  vec.push_back("");
    61   ok &= test_regexp(true,"abcde", "abcd?e", vec);
    62   vec[0]="c";
    63   ok &= test_regexp(true,"abcde", "ab?de", vec);
    64   vec[0] = "bcd";
    65   ok &= test_regexp(true,"abcde", "a*e", vec);
    66   vec.push_back("");
    67   ok &= test_regexp(true,"abcddf", "a*d*f", vec);
     82  ok &= test_regexp(true,"a*d*f", "abcddf", vec);
    6883  vec[0] = "bc";
    6984  vec[1] = "ef";
    70   ok &= test_regexp(true,"abcdefg", "a*d*g", vec);
     85  ok &= test_regexp(true,"a*d*g", "abcdefg", vec);
    7186  vec.push_back("");
    72   ok &= test_regexp(true,"abcdefg", "a*d*?g", vec);
    7387  vec[1]="e";
    7488  vec[2]="f";
    75   ok &= test_regexp(true,"abcdefg", "a*d??g", vec);
     89  ok &= test_regexp(true,"a*d*?g", "abcdefg", vec);
     90  ok &= test_regexp(true,"a*d??g", "abcdefg", vec);
     91  vec.resize(2);
     92  vec[0]="f";
     93  vec[1]="e";
     94  ok &= test_regexp(true, "[fa]il?name", "filename", vec);
    7695
    7796  if (ok)
     
    84103  using namespace theplu::svndigest;
    85104  bool res = fnmatch(a.c_str(), b.c_str());
    86   if (res == answ)
     105  // check that fnmatch and regexp agree
     106  std::vector<std::string> v;
     107  bool res2 = regexp(a, b, v);
     108  if (res == answ && res2==answ)
    87109    return true;
    88   std::cerr << "fnmatch(" << a << ", " << b << ") results "
    89             << res
    90             << ". Expects " << answ << std::endl;
     110  if (res!=answ)
     111    std::cerr << "fnmatch(" << a << ", " << b << ") results "
     112              << res
     113              << ". Expects " << answ << std::endl;
     114  if (res2!=answ)
     115    std::cerr << "regexp(" << b << ", " << a << ") results "
     116              << res2
     117              << ". Expects " << answ << std::endl;
    91118  return false;
    92119}
     
    107134  using namespace theplu::svndigest;
    108135  std::vector<std::string> v;
    109   bool res = regexp(a.begin(), a.end(), b.begin(), b.end(), v);
     136  bool res = regexp(a, b, v);
    110137  if (res!=ans || v!=vec) {
    111138    std::cerr << "regexp(" << a << ", " << b << ") results "
Note: See TracChangeset for help on using the changeset viewer.