Skip to content

Commit 2532ec4

Browse files
Merge pull request #31 from SimpleStateMachine/personal/rsolovev/add_structural_search_tests
ref(Tests): FindParserExtensions, structural search tests
2 parents 20850fb + d9effd5 commit 2532ec4

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using SimpleStateMachine.StructuralSearch.Extensions;
4+
using Xunit;
5+
6+
namespace SimpleStateMachine.StructuralSearch.Tests;
7+
8+
public class StructuralSearchTests
9+
{
10+
[Theory]
11+
[MemberData(nameof(TestCases))]
12+
public static void StructuralSearchShouldBeSuccess(string inputText, string template, Dictionary<string, string> expectedResult)
13+
{
14+
var results = StructuralSearch.ParseFindTemplate(template).ParseString(inputText).ToList();
15+
Assert.Single(results);
16+
var parseResult = results.Single();
17+
18+
Assert.Equal(expectedResult.Count, parseResult.Placeholders.Count);
19+
20+
foreach (var (key, value) in expectedResult)
21+
Assert.Equal(parseResult.Placeholders[key].Value, value);
22+
}
23+
24+
public static IEnumerable<object[]> TestCases => new List<object[]>
25+
{
26+
new object[]
27+
{
28+
// Input text
29+
"void MyMethodName(int value1, double value2)",
30+
// Template
31+
"void $methodName$($params$)",
32+
// Result placeholders
33+
new Dictionary<string, string>()
34+
{
35+
{ "methodName", "MyMethodName" },
36+
{ "params", "int value1, double value2" }
37+
}
38+
}
39+
};
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
4+
namespace SimpleStateMachine.StructuralSearch.Extensions;
5+
6+
public static class FindParserExtensions
7+
{
8+
public static IEnumerable<FindParserResult> ParseString(this IFindParser findParser, string inputString)
9+
{
10+
var input = Input.String(inputString);
11+
IParsingContext context = new ParsingContext(input);
12+
return findParser.Parse(ref context);
13+
}
14+
15+
public static IEnumerable<FindParserResult> ParseFile(this IFindParser findParser, FileInfo fileInfo)
16+
{
17+
var input = Input.File(fileInfo);
18+
IParsingContext context = new ParsingContext(input);
19+
return findParser.Parse(ref context);
20+
}
21+
}

0 commit comments

Comments
 (0)