Skip to content

Commit

Permalink
♻️ refatoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnSky1010 committed Mar 14, 2024
1 parent ae55589 commit d5d2df7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
34 changes: 0 additions & 34 deletions src/SoundMaker/ScoreData/SMSC/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,6 @@
using System.Diagnostics.CodeAnalysis;

namespace SoundMaker.ScoreData.SMSC;

internal class TokenQueue
{
private readonly Queue<Token> _tokens;

public TokenQueue(IEnumerable<Token> tokens)
{
_tokens = new(tokens);
}

public Token? PrevToken { get; private set; }

public int Count => _tokens.Count;

public bool TryDequeue([MaybeNullWhen(false)] out Token token)
{
if (_tokens.TryDequeue(out token))
{
PrevToken = token;
return true;
}
return false;
}

public Token Dequeue()
{
return _tokens.Dequeue();
}

public bool TryPeek([MaybeNullWhen(false)] out Token token)
{
return _tokens.TryPeek(out token);
}
}
internal class Parser
{
private record LengthResult(LengthType LengthType, bool IsDotted);
Expand Down
36 changes: 36 additions & 0 deletions src/SoundMaker/ScoreData/SMSC/TokenQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Diagnostics.CodeAnalysis;

namespace SoundMaker.ScoreData.SMSC;
internal class TokenQueue
{
private readonly Queue<Token> _tokens;

public TokenQueue(IEnumerable<Token> tokens)
{
_tokens = new(tokens);
}

public Token? PrevToken { get; private set; }

public int Count => _tokens.Count;

public bool TryDequeue([MaybeNullWhen(false)] out Token token)
{
if (_tokens.TryDequeue(out token))
{
PrevToken = token;
return true;
}
return false;
}

public Token Dequeue()
{
return _tokens.Dequeue();
}

public bool TryPeek([MaybeNullWhen(false)] out Token token)
{
return _tokens.TryPeek(out token);
}
}
22 changes: 11 additions & 11 deletions test/UnitTests/ScoreData/SMSC/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ParserTest
[Fact(DisplayName = "普通の音符を解析できるか")]
public void TestParse_Note()
{
var data = @"C4, 16";
var data = "C4, 16";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -34,7 +34,7 @@ public void TestParse_Note()
[Fact(DisplayName = "付点音符を解析できるか")]
public void TestParse_DottedNote()
{
var data = @"C4, 16.";
var data = "C4, 16.";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -59,7 +59,7 @@ public void TestParse_DottedNote()
[Fact(DisplayName = "半音上の音符を解析できるか")]
public void TestParse_SharpNote()
{
var data = @"C#4, 16";
var data = "C#4, 16";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -84,7 +84,7 @@ public void TestParse_SharpNote()
[Fact(DisplayName = "普通の休符を解析できるか")]
public void TestParse_Rest()
{
var data = @"rest, 16";
var data = "rest, 16";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -107,7 +107,7 @@ public void TestParse_Rest()
[Fact(DisplayName = "付点休符を解析できるか")]
public void TestParse_DottedRest()
{
var data = @"rest, 16.";
var data = "rest, 16.";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -130,7 +130,7 @@ public void TestParse_DottedRest()
[Fact(DisplayName = "タイを解析できるか")]
public void TestParse_Tie()
{
var data = @"tie(C#4, 16, 8.)";
var data = "tie(C#4, 16, 8.)";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -155,7 +155,7 @@ public void TestParse_Tie()
[Fact(DisplayName = "連符を解析できるか")]
public void TestParse_Tuplet()
{
var data = @"tup(16, C#4, rest, E4.)";
var data = "tup(16, C#4, rest, E4.)";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand All @@ -182,7 +182,7 @@ public void TestParse_Tuplet()
[Fact(DisplayName = "連符内のタイや連符を解析できるか")]
public void TestParse_TupletInTupletAndTie()
{
var data = @"tup(16, tup(16, rest, rest), tie(C#4, 16, 8, 8, 8.))";
var data = "tup(16, tup(16, rest, rest), tie(C#4, 16, 8, 8, 8.))";
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
var parser = new Parser(tokens);
Expand Down Expand Up @@ -217,7 +217,7 @@ public void TestParse_TupletInTupletAndTie()
// ------------------エラーのテスト---------------------------

[Fact(DisplayName = "空の文でエラーが発生しないか")]
public void TestEmptyStatment()
public void Test_EmptyStatment()
{
var data = ";;;";
var lexer = new Lexer(data);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void Test_NotFoundCommaErrors(string data, int expectedCount)

[Theory(DisplayName = ")が見つからないエラーのテスト")]
[InlineData("tie(C4,1;tup(4.,C4.", 2)]
public void TestNotFoundRightParenthesesErrors(string data, int expectedCount)
public void Test_NotFoundRightParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
Expand All @@ -275,7 +275,7 @@ public void TestNotFoundRightParenthesesErrors(string data, int expectedCount)

[Theory(DisplayName = "(が見つからないエラーのテスト")]
[InlineData("tie)C4,1;tup4.,C4.", 2)]
public void TestNotFoundLeftParenthesesErrors(string data, int expectedCount)
public void Test_NotFoundLeftParenthesesErrors(string data, int expectedCount)
{
var lexer = new Lexer(data);
var tokens = lexer.ReadAll();
Expand Down

0 comments on commit d5d2df7

Please sign in to comment.