-
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.
- Loading branch information
Showing
4 changed files
with
106 additions
and
18 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
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,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; | ||
} | ||
} |