1 # -*- coding: iso-8859-1 -*-
4 BLANKLINE_MARKER = '<BLANKLINE>'
5 ELLIPSIS_MARKER = '...'
10 if got == want: return True
12 # Replace <BLANKLINE> in want with a blank line.
13 want = re.sub('(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
15 # If a line in got contains only spaces, then remove the
17 got = re.sub('(?m)^\s*?$', '', got)
21 if _ellipsis_match(want, got):
26 def _ellipsis_match(want, got):
27 if ELLIPSIS_MARKER not in want:
30 # Find "the real" strings.
31 ws = want.split(ELLIPSIS_MARKER)
34 # Deal with exact matches possibly needed at one or both ends.
35 startpos, endpos = 0, len(got)
37 if w: # starts with exact match
44 if w: # ends with exact match
52 # Exact end matches required more characters than we have, as in
53 # _ellipsis_match('aa...aa', 'aaa')
56 # For the rest, we only need to find the leftmost non-overlapping
57 # match for each piece. If there's no overall match that way alone,
58 # there's no overall match period.
60 # w may be '' at times, if there are consecutive ellipses, or
61 # due to an ellipsis at the start or end of `want`. That's OK.
62 # Search for an empty string succeeds, and doesn't change startpos.
63 startp = got.find(w, startpos, endpos)
66 startpos = startp + len(w)