Skip to content

Commit

Permalink
👍 Add tests of errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnSky1010 committed Mar 14, 2024
1 parent d10b625 commit 0c5acbf
Showing 1 changed file with 71 additions and 3 deletions.
74 changes: 71 additions & 3 deletions test/UnitTests/ScoreData/SMSC/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void TestParse_DottedRest()
[Fact(DisplayName = "タイを解析できるか")]
public void TestParse_Tie()
{
var data = @"tie(C#4, 16, 8, 8, 8.)";
var data = @"tie(C#4, 16, 8.)";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -139,8 +139,6 @@ public void TestParse_Tie()
{
new Tie(new(Scale.CSharp, 4, LengthType.Sixteenth), new List<Note>()
{
new(LengthType.Eighth),
new(LengthType.Eighth),
new(LengthType.Eighth, true),
}),
};
Expand Down Expand Up @@ -215,4 +213,74 @@ public void TestParse_TupletInTupletAndTie()
var actual = Assert.IsType<Tuplet>(actualCollection[0]);
Assert.Equal(expected.Count, actual.Count);
}

// ------------------エラーのテスト---------------------------

[Fact(DisplayName = "空の文でエラーが発生しないか")]
public void TestEmptyStatment()
{
var data = ";;;";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors;
Assert.Empty(actual);
}

[Theory(DisplayName = "音程解析エラーのテスト")]
[InlineData("C100,1\n D8,1 // A0~C8のみ許可する", 2)]
[InlineData("A0,1; C8,1", 0)]
public void Test_ScaleErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors.Count(err => err.Type is SMSCReadErrorType.InvalidScale);
Assert.Equal(expectedCount, actual);
}

[Theory(DisplayName = "長さ解析エラーのテスト")]
[InlineData("C4,1; C4,2; C4,4; C4,8; C4,16; C4,32; C4,1; C4,64", 0)]
[InlineData("C4,0; C4,65; C4,", 3)]
public void Test_LengthErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors.Count(err => err.Type is SMSCReadErrorType.InvalidLength);
Assert.Equal(expectedCount, actual);
}

[Theory(DisplayName = "カンマが見つからないエラーのテスト")]
[InlineData("C4.1; tie(C4.1)", 2)]
public void Test_NotFoundCommaErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors.Count(err => err.Type is SMSCReadErrorType.NotFoundComma);
Assert.Equal(expectedCount, actual);
}

[Theory(DisplayName = ")が見つからないエラーのテスト")]
[InlineData("tie(C4,1;tup(4.,C4.", 2)]
public void TestNotFoundRightParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors.Count(err => err.Type is SMSCReadErrorType.NotFoundRightParentheses);
Assert.Equal(expectedCount, actual);
}

[Theory(DisplayName = "(が見つからないエラーのテスト")]
[InlineData("tie)C4,1;tup4.,C4.", 2)]
public void TestNotFoundLeftParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
var actual = parser.Parse().Errors.Count(err => err.Type is SMSCReadErrorType.NotFoundLeftParentheses);
Assert.Equal(expectedCount, actual);
}
}

0 comments on commit 0c5acbf

Please sign in to comment.