Patchwork [1,of,8] match: add doctest examples for exactmatcher

login
register
mail settings
Submitter Denis Laxalde
Date April 8, 2019, 8:23 a.m.
Message ID <9514c11ecebac78d47f1.1554711825@steppe.logilab.fr>
Download mbox | patch
Permalink /patch/39528/
State Accepted
Headers show

Comments

Denis Laxalde - April 8, 2019, 8:23 a.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1554632483 -7200
#      Sun Apr 07 12:21:23 2019 +0200
# Node ID 9514c11ecebac78d47f1b174a4bbc4d17971ab05
# Parent  675775c33ab66cd157b9929bb0371bf05cbceee6
match: add doctest examples for exactmatcher

Make the docstring raw, since it now includes escape characters.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -568,8 +568,24 @@  class includematcher(basematcher):
         return ('<includematcher includes=%r>' % pycompat.bytestr(self._pats))
 
 class exactmatcher(basematcher):
-    '''Matches the input files exactly. They are interpreted as paths, not
+    r'''Matches the input files exactly. They are interpreted as paths, not
     patterns (so no kind-prefixes).
+
+    >>> m = exactmatcher(['a.txt', 're:.*\.c$'])
+    >>> m('a.txt')
+    True
+    >>> m('b.txt')
+    False
+
+    Input files that would be matched are exactly those returned by .files()
+    >>> m.files()
+    ['a.txt', 're:.*\\.c$']
+
+    So pattern 're:.*\.c$' is not considered as a regex, but as a file name
+    >>> m('main.c')
+    False
+    >>> m('re:.*\.c$')
+    True
     '''
 
     def __init__(self, files, badfn=None):