# HG changeset patch # User Denis Laxalde # Date 1554556915 -7200 # Node ID bf777c1e78ddfb217dc7f12b8841e42461a17cbe # Parent f3db5c805a67b50bafe2720cae1630dd7d23588d match: add a docstring with doctest examples to patternmatcher Doctest examples aim at illustrating how __call__() and exact() are different, depending on the pattern kind. diff -r f3db5c805a67 -r bf777c1e78dd mercurial/match.py --- a/mercurial/match.py Sun Apr 07 12:21:23 2019 +0200 +++ b/mercurial/match.py Sat Apr 06 15:21:55 2019 +0200 @@ -432,6 +432,37 @@ return '' % s class patternmatcher(basematcher): + """Matches a set of (kind, pat, source) against a 'root' directory. + + >>> kindpats = [ + ... ('re', '.*\.c$', ''), + ... ('path', 'foo/a', ''), + ... ('relpath', 'b', ''), + ... ('glob', '*.h', ''), + ... ] + >>> m = patternmatcher('foo', kindpats) + >>> bool(m('main.c')) # matches re:.*\.c$ + True + >>> bool(m('b.txt')) + False + >>> bool(m('foo/a')) # matches path:foo/a + True + >>> bool(m('a')) # does not match path:b, since 'root' is 'foo' + False + >>> bool(m('b')) # matches relpath:b, since 'root' is 'foo' + True + >>> bool(m('lib.h')) # matches glob:*.h + True + + >>> m.files() + ['.', 'foo/a', 'b', '.'] + >>> m.exact('foo/a') + True + >>> m.exact('b') + True + >>> m.exact('lib.h') # exact matches are for (rel)path kinds + False + """ def __init__(self, root, kindpats, badfn=None): super(patternmatcher, self).__init__(badfn)