-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the metadata object from class to struct.
Here's the reason: 1. technically, metadata should not be chagned after initialized and assign the value. 2. easier to compare the object, means there's no need to write lots of code to check if two metadata are the same in the test case everytime.
- Loading branch information
1 parent
69199f3
commit 4e7cbf0
Showing
9 changed files
with
67 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using LrcParser.Parser.Lines; | ||
|
||
namespace LrcParser.Tests.Parser.Lines; | ||
|
||
public class BaseSingleLineParserTest<TParser, TModel> where TParser : SingleLineParser<TModel>, new() where TModel : class | ||
public class BaseSingleLineParserTest<TParser, TModel> | ||
where TParser : SingleLineParser<TModel>, new() where TModel : struct, IEquatable<TModel> | ||
{ | ||
protected bool CanDecode(string text) => new TParser().CanDecode(text); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) karaoke.dev <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using LrcParser.Model; | ||
|
@@ -45,13 +46,13 @@ public TestLyricParser() | |
|
||
protected override Song PostProcess(List<object> values) | ||
{ | ||
var lines = values.OfType<string>(); | ||
var lines = values.OfType<Line>(); | ||
|
||
return new Song | ||
{ | ||
Lyrics = lines.Select(l => new Lyric | ||
{ | ||
Text = l, | ||
Text = l.Text, | ||
}).ToList(), | ||
}; | ||
} | ||
|
@@ -60,14 +61,31 @@ protected override IEnumerable<object> PreProcess(Song song) | |
=> song.Lyrics.Select(lyric => lyric.Text); | ||
} | ||
|
||
private class TestLineParser : SingleLineParser<string> | ||
private class TestLineParser : SingleLineParser<Line> | ||
{ | ||
public override bool CanDecode(string text) | ||
=> true; | ||
|
||
public override string Decode(string text) => text; | ||
public override Line Decode(string text) => new() | ||
{ | ||
Text = text, | ||
}; | ||
|
||
public override string Encode(Line component, int index) | ||
=> $"index:{index}, value: {component.Text}"; | ||
} | ||
|
||
private struct Line : IEquatable<Line> | ||
{ | ||
public Line() | ||
{ | ||
} | ||
|
||
public string Text { get; set; } = string.Empty; | ||
|
||
public override string Encode(string component, int index) | ||
=> $"index:{index}, value: {component}"; | ||
public bool Equals(Line other) | ||
{ | ||
return Text == other.Text; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters