[PATCH 1 of 1] tests: asciify output of tsttest

Yuya Nishihara yuya at tcha.org
Sun Sep 19 21:19:39 CDT 2010


Mads Kiilerich wrote:
>  Yuya Nishihara wrote, On 09/19/2010 04:30 PM:
> > Martin Geisler wrote:
> >> Yuya Nishihara <yuya at tcha.org> writes:
> >>> It'll be simple if we can just write s.encode('string-escape') or
> >>> repr(s)[1:-1] without re.sub(), but it's necessary to avoid unwanted
> >>> escapes like \t, \n, \'.
> >> I think the simplest way is to use
> >>
> >>   s.encode('string-escape').replace(r'\'', '\'').replace(r'\n', '\n')
> > It breaks edge case:
> >
> > In [22]: r'\n'
> > Out[22]: '\\n'
> > In [25]: r'\n'.encode('string-escape').replace('\\\\', '\\').replace(r'\n', '\n')
> > Out[25]: '\n'
> >
> > unescape needs to be done at once.
> 
> Yes, unescape generally has to be done at once. But we don't want to
> unescape backslash. We just want to unescape "'", so I agree with Martin
> that it will work in _this_ case.

So keeping '\\' escaped?

> IIRC unescaping of \n isn't necessary.

if we handle the last character exceptionally.
'for l in output' preserves the last new-line character.

> I'm a bit in doubt if we should unescape \t too. Having \t in the output
> makes it less readable, but it also makes it obvious what the output
> really is.

Maybe it depends whether or not the following output looks acceptable:

  --- a/file.txt\tThu Jan 01 00:00:00 1970 +0000
  +++ b/file.txt\tThu Jan 01 00:00:00 1970 +0000

Yuya,


More information about the Mercurial-devel mailing list