From b0d7a9757866f5587ef245fee05a9a3474620be8 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 6 Nov 2015 16:20:28 +0100 Subject: [PATCH] Add a test for source files with CRLF lin endings (failing) --- test/test_chordpro/test_parser.py | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index f0e94290..fd30a9b3 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -60,6 +60,12 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): "test_{}_{}".format(os.path.basename(base), dest), cls._create_test(base, dest), ) + if os.path.basename(base) == 'newline': + yield ( + "test_crlf_{}_{}".format(os.path.basename(base), dest), + cls._create_crlf_test(base, dest), + ) + @classmethod def _create_test(cls, base, dest): @@ -86,3 +92,35 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): ).format(base=os.path.basename(base), format=dest) return test_parse_render + @classmethod + def _create_crlf_test(cls, base, dest): + """Transform the `base` line endings into CRLF and test the compilation. + """ + + def test_parse_render(self): + """Test that `base` is correctly parsed and rendered when line endings are CRLF. + """ + if base is None or dest is None: + return + originalname = "{}.source".format(base) + chordproname = "{}.crlf.source".format(base) + with open_read(originalname) as originalfile: + with open(chordproname, 'w') as chordprofile: + for line in originalfile: + chordprofile.write(line.replace('\n', '\r\n')) + destname = "{}.{}".format(base, dest) + with open_read(destname) as expectfile: + with disable_logging(): + self.assertMultiLineEqual( + self.song_plugins[LANGUAGES[dest]]['sgc'](chordproname, self.config).render( + output=chordproname, + ).strip(), + expectfile.read().strip(), + ) + os.remove(chordproname) + + test_parse_render.__doc__ = ( + "Test that '{base}' is correctly parsed and rendererd into '{format}' format with CRLF." + ).format(base=os.path.basename(base), format=dest) + return test_parse_render +