From 13388a33c9e59c852d735eef74b11f3b572e346e Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 5 Oct 2020 01:50:07 -0400 Subject: test newlines as part of test suite (#147) * test newlines as part of test suite Signed-off-by: Matthew Peveler * fix failing toc tests --- asciidoc.py | 2 +- tests/testasciidoc.py | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/asciidoc.py b/asciidoc.py index 533771d..4828f91 100755 --- a/asciidoc.py +++ b/asciidoc.py @@ -969,7 +969,7 @@ def system(name, args, is_macro=False, attrs=None): line = subs_attrs(line) if line is not None: result.append(line) - result = '\n'.join(result) + result = DEFAULT_NEWLINE.join(result) else: assert False if result and name in ('eval3', 'sys3'): diff --git a/tests/testasciidoc.py b/tests/testasciidoc.py index 4882f80..fef160b 100755 --- a/tests/testasciidoc.py +++ b/tests/testasciidoc.py @@ -13,7 +13,6 @@ import sys sys.path.append(str(Path(__file__).resolve().parent.parent)) import asciidocapi # noqa: E402 -from asciidoc import DEFAULT_NEWLINE # noqa: E402 # Default backends. BACKENDS = ('html4', 'xhtml11', 'docbook', 'docbook5', 'html5') @@ -170,11 +169,12 @@ class AsciiDocTest(object): """ Return expected test data output for backend. """ - with open(self.backend_filename(backend), encoding='utf-8') as open_file: - result = open_file.readlines() - # Strip line terminators. - result = [s.rstrip() for s in result] - return result + with open( + self.backend_filename(backend), + encoding='utf-8', + newline='' + ) as open_file: + return open_file.readlines() def generate_expected(self, backend): """ @@ -186,7 +186,7 @@ class AsciiDocTest(object): infile = self.source outfile = io.StringIO() asciidoc.execute(infile, outfile, backend) - return outfile.getvalue().splitlines() + return outfile.getvalue().splitlines(keepends=True) def update_expected(self, backend): """ @@ -196,9 +196,14 @@ class AsciiDocTest(object): if not os.path.isdir(self.datadir): print('CREATING: %s' % self.datadir) os.mkdir(self.datadir) - with open(self.backend_filename(backend), 'w+', encoding='utf-8') as open_file: + with open( + self.backend_filename(backend), + 'w+', + encoding='utf-8', + newline='' + ) as open_file: print('WRITING: %s' % open_file.name) - open_file.writelines([s + DEFAULT_NEWLINE for s in lines]) + open_file.writelines(lines) def update(self, backend=None, force=False): """ -- cgit v1.2.1