Skip to content

Commit

Permalink
Add ConvertAndSplitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Oct 15, 2023
1 parent 004c558 commit 6cd86ca
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
55 changes: 55 additions & 0 deletions tests/Menees.Chords.Tests/ChordProLyricLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#region Using Directives

using System.Diagnostics;
using Menees.Chords.Parsers;

#endregion
Expand Down Expand Up @@ -185,5 +186,59 @@ static void Test(string text, string? expectedChords, string? expectedLyrics)
}
}

[TestMethod]
public void ConvertAndSplitTest()
{
int pairs = 0;
int lines = 0;
foreach (Document document in TestUtility.SampleDocuments)
{
TryConvertAndSplit(document.Entries);

void TryConvertAndSplit(IEnumerable<Entry> entries)
{
foreach (Entry entry in entries)
{
switch (entry)
{
case ChordLyricPair pair:
{
ChordProLyricLine line = ChordProLyricLine.Convert(pair);
(ChordLine? chords, LyricLine? lyrics) = line.Split();
chords.ShouldNotBeNull(document.FileName);
lyrics.ShouldNotBeNull(document.FileName);

chords.ToString().ShouldBe(pair.Chords.ToString(), document.FileName);
lyrics.ToString().ShouldBe(pair.Lyrics.ToString(), document.FileName);
pairs++;
}

break;

case ChordProLyricLine line:
{
(ChordLine? chords, LyricLine? lyrics) = line.Split();
if (chords != null && lyrics != null)
{
ChordLyricPair newPair = new(chords, lyrics);
ChordProLyricLine newLine = ChordProLyricLine.Convert(newPair);
newLine.ToString().ShouldBe(line.ToString(), document.FileName);
lines++;
}
}

break;

case IEntryContainer container:
TryConvertAndSplit(container.Entries);
break;
}
}
}
}

Debug.WriteLine($"Round-trip tested {pairs} ChordLyricPairs and {lines} ChordProLyricLines.");
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Every rose has its thorn
[Bridge]
Em D
Though it's been a while now
Cadd9 G (g f#)
Cadd9 G g f# (bass notes)
I can still feel so much pain
Em D
Like a knife that cuts you the wound heals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Every rose has its [Cadd9]thorn

{start_of_bridge}
[Em] Though it's been a [D]while now
I can [Cadd9]still feel so much [G]pain [*g f#]
I can [Cadd9]still feel so much [G]pain [g] [f#] [*bass notes]
[Em] Like a knife that [D]cuts you the wound heals
[Cadd9] But the scar, that scar [G]remains
{end_of_bridge}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Every rose has its [Cadd9]thorn

{start_of_verse: Bridge}
[Em] Though it's been a [D]while now
I can [Cadd9]still feel so much [G]pain [*g f#]
I can [Cadd9]still feel so much [G]pain [g] [f#] [*bass notes]
[Em] Like a knife that [D]cuts you the wound heals
[Cadd9] But the scar, that scar [G]remains
{end_of_verse}
Expand Down

0 comments on commit 6cd86ca

Please sign in to comment.