diff --git a/test/test_chordpro/newline.crlf.html b/test/test_chordpro/newline.crlf.html
new file mode 100644
index 00000000..5540af64
--- /dev/null
+++ b/test/test_chordpro/newline.crlf.html
@@ -0,0 +1,43 @@
+
+Lang: en
+
+
+
+
+
This is a verse
+With a new line
+
+The second part of the verse
+Is this line
+
+
+
Here is a new line at the end
+
+
+
+
Foo bar
+
+
+
+And a new line
+At the beginning
+
+
+
New lines can also
+
+Be in chorus
+
+
+
New lines can also
+
+Be in bridges
+
+
+
New lines can also
+
+Be surrounded by spaces
+
+
+
New lines cannot
+
+
\ No newline at end of file
diff --git a/test/test_chordpro/newline.crlf.sgc b/test/test_chordpro/newline.crlf.sgc
new file mode 100644
index 00000000..e9bf0c62
--- /dev/null
+++ b/test/test_chordpro/newline.crlf.sgc
@@ -0,0 +1,41 @@
+{lang: en}
+
+This is a verse
+With a new line
+{newline}
+The second part of the verse
+Is this line
+
+
+Here is a new line at the end
+{newline}
+
+
+Foo bar
+
+
+{newline}
+And a new line
+At the beginning
+
+
+{start_of_chorus}
+ New lines can also
+ {newline}
+ Be in chorus
+{end_of_chorus}
+
+
+{start_of_bridge}
+ New lines can also
+ {newline}
+ Be in bridges
+{end_of_bridge}
+
+
+New lines can also
+{newline}
+Be surrounded by spaces
+
+
+New lines cannot
diff --git a/test/test_chordpro/newline.crlf.source b/test/test_chordpro/newline.crlf.source
new file mode 100644
index 00000000..bd45d5ce
--- /dev/null
+++ b/test/test_chordpro/newline.crlf.source
@@ -0,0 +1,2 @@
+# This content will be overwritten with `newline.source` content
+# with windows line endings (CRLF) - for testing purposes
diff --git a/test/test_chordpro/newline.crlf.tex b/test/test_chordpro/newline.crlf.tex
new file mode 100644
index 00000000..d557de5f
--- /dev/null
+++ b/test/test_chordpro/newline.crlf.tex
@@ -0,0 +1,61 @@
+\selectlanguage{english}
+
+\beginsong{}[
+ by={
+ },
+]
+
+
+\begin{verse}
+ This is a verse
+ With a new line
+ ~\\
+ The second part of the verse
+ Is this line
+\end{verse}
+
+
+\begin{verse}
+ Here is a new line at the end
+ ~\\
+\end{verse}
+
+
+\begin{verse}
+ Foo bar
+\end{verse}
+
+
+\begin{verse}
+ ~\\
+ And a new line
+ At the beginning
+\end{verse}
+
+
+\begin{chorus}
+ New lines can also
+ ~\\
+ Be in chorus
+\end{chorus}
+
+
+\begin{bridge}
+ New lines can also
+ ~\\
+ Be in bridges
+\end{bridge}
+
+
+\begin{verse}
+ New lines can also
+ ~\\
+ Be surrounded by spaces
+\end{verse}
+
+
+\begin{verse}
+ New lines cannot
+\end{verse}
+
+\endsong
diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py
index 82a02fb6..bab1bb9a 100644
--- a/test/test_chordpro/test_parser.py
+++ b/test/test_chordpro/test_parser.py
@@ -34,6 +34,14 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
maxDiff = None
+ @classmethod
+ def setUpClass(cls):
+ cls._overwrite_clrf()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._reset_clrf()
+
@staticmethod
@contextlib.contextmanager
def chdir():
@@ -44,9 +52,11 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
yield
os.chdir(olddir)
- def assertRender(self, destformat, sourcename, destname): # pylint: disable=invalid-name
- """Assert that `sourcename` is correctly rendered as `destname` in `destformat`.
+ def assertRender(self, base, destformat): # pylint: disable=invalid-name
+ """Assert that `{base}.source` is correctly rendered in the `destformat`.
"""
+ sourcename = "{}.source".format(base)
+ destname = "{}.{}".format(base, destformat)
with self.chdir():
with open_read(destname) as expectfile:
with disable_logging():
@@ -91,24 +101,35 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test that `base` is correctly parsed and rendered."""
if base is None or dest is None:
return
- self.assertRender(dest, "{}.source".format(base), "{}.{}".format(base, dest))
+ self.assertRender(base, dest)
test_parse_render.__doc__ = (
"Test that '{base}' is correctly parsed and rendererd into '{format}' format."
).format(base=os.path.basename(base), format=dest)
return test_parse_render
- def test_clrf(self):
- """Test that source is correctly parsed and rendered when line endings are CRLF.
+ @classmethod
+ def _overwrite_clrf(cls):
+ """Overwrite `*.crlf.source` files to force the CRLF line endings.
"""
- originalname = "newline.source"
- chordproname = "newline.crlf.source"
- with self.chdir():
- with open_read(originalname) as originalfile:
- with open(chordproname, 'w') as chordprofile:
- for line in originalfile:
- chordprofile.write(line.replace('\n', '\r\n'))
- for dest in LANGUAGES:
- with self.subTest(dest):
- self.assertRender(dest, chordproname, "newline.{}".format(dest))
- os.remove(chordproname)
+ with cls.chdir():
+ for crlfname in sorted(glob.glob('*.crlf.source')):
+ base = crlfname[:-len(".crlf.source")]
+ sourcename = base + ".source"
+ with open_read(sourcename) as sourcefile:
+ with open(crlfname, 'w') as crlffile:
+ for line in sourcefile:
+ crlffile.write(line.replace('\n', '\r\n'))
+
+ @classmethod
+ def _reset_clrf(cls):
+ """Reset `*.crlf.source` files.
+ """
+ crlf_msg = """# This content will be overwritten with `{}.source` content
+# with windows line endings (CRLF) - for testing purposes
+"""
+ with cls.chdir():
+ for crlfname in sorted(glob.glob('*.crlf.source')):
+ base = crlfname[:-len(".crlf.source")]
+ with open(crlfname, 'w') as crlffile:
+ crlffile.write(crlf_msg.format(base))