Browse Source

[test] Create a test with CLRF endings

pull/160/head
Louis 9 years ago
parent
commit
2468f2f094
  1. 43
      test/test_chordpro/clrf.html
  2. 41
      test/test_chordpro/clrf.sgc
  3. 32
      test/test_chordpro/clrf.source
  4. 61
      test/test_chordpro/clrf.tex
  5. 39
      test/test_chordpro/test_parser.py

43
test/test_chordpro/clrf.html

@ -0,0 +1,43 @@
<span class="song-language">Lang: en</span><br>
<div class="song_content">
<p class="verse">This is a verse<br>
With a new line<br>
<br>
The second part of the verse<br>
Is this line
</p>
<p class="verse">Here is a new line at the end<br>
</p>
<p class="verse">Foo bar
</p>
<p class="verse"><br>
And a new line<br>
At the beginning
</p>
<p class="chorus">New lines can also<br>
<br>
Be in chorus
</p>
<p class="bridge">New lines can also<br>
<br>
Be in bridges
</p>
<p class="verse">New lines can also<br>
<br>
Be surrounded by spaces
</p>
<p class="verse">New lines cannot
</p>
</div>

41
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

32
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

61
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

39
test/test_chordpro/test_parser.py

@ -60,12 +60,6 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"test_{}_{}".format(os.path.basename(base), dest), "test_{}_{}".format(os.path.basename(base), dest),
cls._create_test(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 @classmethod
def _create_test(cls, base, dest): 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." "Test that '{base}' is correctly parsed and rendererd into '{format}' format."
).format(base=os.path.basename(base), format=dest) ).format(base=os.path.basename(base), format=dest)
return test_parse_render 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

Loading…
Cancel
Save