From 2468f2f094ab1807dfaf26d7c868d0f553acafc8 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 6 Nov 2015 19:55:25 +0100 Subject: [PATCH] [test] Create a test with CLRF endings --- test/test_chordpro/clrf.html | 43 ++++++++++++++++++++++ test/test_chordpro/clrf.sgc | 41 +++++++++++++++++++++ test/test_chordpro/clrf.source | 32 ++++++++++++++++ test/test_chordpro/clrf.tex | 61 +++++++++++++++++++++++++++++++ test/test_chordpro/test_parser.py | 39 -------------------- 5 files changed, 177 insertions(+), 39 deletions(-) create mode 100644 test/test_chordpro/clrf.html create mode 100644 test/test_chordpro/clrf.sgc create mode 100644 test/test_chordpro/clrf.source create mode 100644 test/test_chordpro/clrf.tex diff --git a/test/test_chordpro/clrf.html b/test/test_chordpro/clrf.html new file mode 100644 index 00000000..5540af64 --- /dev/null +++ b/test/test_chordpro/clrf.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/clrf.sgc b/test/test_chordpro/clrf.sgc new file mode 100644 index 00000000..e9bf0c62 --- /dev/null +++ b/test/test_chordpro/clrf.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/clrf.source b/test/test_chordpro/clrf.source new file mode 100644 index 00000000..484df519 --- /dev/null +++ b/test/test_chordpro/clrf.source @@ -0,0 +1,32 @@ +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 + +{soc} +New lines can also +{newline} +Be in chorus +{eoc} + +{sob} +New lines can also +{newline} +Be in bridges +{eob} + +New lines can also + {newline} +Be surrounded by spaces + +New lines cannot {newline} appear in the middle of a line diff --git a/test/test_chordpro/clrf.tex b/test/test_chordpro/clrf.tex new file mode 100644 index 00000000..d557de5f --- /dev/null +++ b/test/test_chordpro/clrf.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 fd30a9b3..3f0c652e 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -60,12 +60,6 @@ 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): @@ -91,36 +85,3 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): "Test that '{base}' is correctly parsed and rendererd into '{format}' format." ).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 -