-
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.
Merge branch 'main' into localize-character-names
- Loading branch information
Showing
89 changed files
with
512 additions
and
227 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
ThScoreFileConverter.Core.Tests/Models/IntegerParserTests.cs
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Text.RegularExpressions; | ||
using ThScoreFileConverter.Core.Models; | ||
|
||
namespace ThScoreFileConverter.Core.Tests.Models; | ||
|
||
[TestClass] | ||
public class IntegerParserTests | ||
{ | ||
[TestMethod] | ||
public void ParseTestDefault() | ||
{ | ||
var parser = new IntegerParser(); | ||
|
||
var pattern = $@"var (\w+) = ({parser.Pattern});"; | ||
var evaluator = new MatchEvaluator(match => | ||
{ | ||
var name = match.Groups[1].Value; | ||
var value = parser.Parse(match.Groups[2]); | ||
return $"{name}^2 == {value * value}"; | ||
}); | ||
|
||
var pairs = new[] | ||
{ | ||
("var a = 1;", "a^2 == 1"), | ||
("var b = 23;", "b^2 == 529"), | ||
("var c = 456;", "c^2 == 207936"), | ||
}; | ||
|
||
foreach (var pair in pairs) | ||
{ | ||
var replaced = Regex.Replace(pair.Item1, pattern, evaluator); | ||
Assert.AreEqual(pair.Item2, replaced); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ParseTest() | ||
{ | ||
var parser = new IntegerParser(@"[2-4]"); | ||
|
||
var pattern = $@"var (\w+) = ({parser.Pattern});"; | ||
var evaluator = new MatchEvaluator(match => | ||
{ | ||
var name = match.Groups[1].Value; | ||
var value = parser.Parse(match.Groups[2]); | ||
return $"{name}^2 == {value * value}"; | ||
}); | ||
|
||
var pairs = new[] | ||
{ | ||
("var a = 1;", "var a = 1;"), | ||
("var b = 2;", "b^2 == 4"), | ||
("var c = 3;", "c^2 == 9"), | ||
("var d = 4;", "d^2 == 16"), | ||
("var e = 5;", "var e = 5;"), | ||
}; | ||
|
||
foreach (var pair in pairs) | ||
{ | ||
var replaced = Regex.Replace(pair.Item1, pattern, evaluator); | ||
Assert.AreEqual(pair.Item2, replaced); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ThScoreFileConverter.Core.Tests/Models/Th143/SceneParserTests.cs
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Text.RegularExpressions; | ||
using ThScoreFileConverter.Core.Models.Th143; | ||
|
||
namespace ThScoreFileConverter.Core.Tests.Models.Th143; | ||
|
||
[TestClass] | ||
public class SceneParserTests | ||
{ | ||
[TestMethod] | ||
public void ParseTest() | ||
{ | ||
var parser = new SceneParser(); | ||
|
||
var pattern = $@"var (\w+) = ({parser.Pattern});"; | ||
var evaluator = new MatchEvaluator(match => | ||
{ | ||
var name = match.Groups[1].Value; | ||
var value = parser.Parse(match.Groups[2]); | ||
return $"{name}^2 == {value * value}"; | ||
}); | ||
|
||
var pairs = new[] | ||
{ | ||
("var a0 = 0;", "a0^2 == 100"), | ||
("var a1 = 1;", "a1^2 == 1"), | ||
("var a2 = 2;", "a2^2 == 4"), | ||
("var a3 = 3;", "a3^2 == 9"), | ||
("var a4 = 4;", "a4^2 == 16"), | ||
("var a5 = 5;", "a5^2 == 25"), | ||
("var a6 = 6;", "a6^2 == 36"), | ||
("var a7 = 7;", "a7^2 == 49"), | ||
("var a8 = 8;", "a8^2 == 64"), | ||
("var a9 = 9;", "a9^2 == 81"), | ||
}; | ||
|
||
foreach (var pair in pairs) | ||
{ | ||
var replaced = Regex.Replace(pair.Item1, pattern, evaluator); | ||
Assert.AreEqual(pair.Item2, replaced); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="IntegerParser.cs" company="None"> | ||
// Copyright (c) IIHOSHI Yoshinori. | ||
// Licensed under the BSD-2-Clause license. See LICENSE.txt file in the project root for full license information. | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using System.Text.RegularExpressions; | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace ThScoreFileConverter.Core.Models; | ||
|
||
/// <summary> | ||
/// Provides a parser for an integer value. | ||
/// </summary> | ||
/// <param name="pattern">The regular expression used for parsing.</param> | ||
public class IntegerParser([StringSyntax(StringSyntaxAttribute.Regex)] string pattern) : IRegexParser<int> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="IntegerParser"/> class. | ||
/// </summary> | ||
public IntegerParser() | ||
: this(@"\d+") | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string Pattern { get; } = pattern; | ||
|
||
/// <inheritdoc/> | ||
public virtual int Parse(Group group) | ||
{ | ||
Guard.IsNotNull(group); | ||
return int.Parse(group.Value, CultureInfo.InvariantCulture); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="SceneParser.cs" company="None"> | ||
// Copyright (c) IIHOSHI Yoshinori. | ||
// Licensed under the BSD-2-Clause license. See LICENSE.txt file in the project root for full license information. | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace ThScoreFileConverter.Core.Models.Th143; | ||
|
||
/// <summary> | ||
/// Provides the parser of ISC scenes. | ||
/// </summary> | ||
public sealed class SceneParser : IntegerParser | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SceneParser"/> class. | ||
/// </summary> | ||
public SceneParser() | ||
: base(@"\d") | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Converts from the group matched with the pattern to a value indicating a scene. | ||
/// </summary> | ||
/// <param name="group">The group matched by <see cref="IntegerParser.Pattern"/>.</param> | ||
/// <returns>The parsed value indicating a scene.</returns> | ||
public override int Parse(Group group) | ||
{ | ||
var scene = base.Parse(group); | ||
return scene == 0 ? 10 : scene; | ||
} | ||
} |
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
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
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
Oops, something went wrong.