Skip to content

Commit 6688c05

Browse files
committed
Replace rule tests, Placeholder parameter in FindRule
1 parent 2ff71ce commit 6688c05

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

src/SimpleStateMachine.StructuralSearch.Tests/RuleParserTests.cs renamed to src/SimpleStateMachine.StructuralSearch.Tests/FindRuleParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleStateMachine.StructuralSearch.Tests
66
{
7-
public class RuleParserTests
7+
public class FindRuleParserTests
88
{
99
[Theory]
1010
[InlineData("equals $var$")]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Linq;
2+
using Pidgin;
3+
using Xunit;
4+
5+
namespace SimpleStateMachine.StructuralSearch.Tests
6+
{
7+
public class ReplaceRuleParserTests
8+
{
9+
[Theory]
10+
[InlineData("equals $var$", "$var$")]
11+
[InlineData("Not equals $var$.Lenght", "$var$.Lenght")]
12+
[InlineData("Not equals $var$.offset.Start", "$var$.offset.Start")]
13+
[InlineData("equals $var$.Lenght and Not StartsWith \"123\"", "$var$.offset.Start.Trim")]
14+
[InlineData("equals $var$.Lenght and Not StartsWith \"\\\"Test\"", "$var$.offset.Start.ToUpper")]
15+
public void FindRuleParsingShouldBeSuccess(string findRule, string replaceRule)
16+
{
17+
string placeholder = "$var$";
18+
string replaceRuleStr = $"{placeholder} {findRule} => {replaceRule}";
19+
var rule = StructuralSearch.ParseReplaceRule(replaceRuleStr);
20+
var _ruleStr = rule.ToString()?.ToLower();
21+
Assert.NotNull(rule);
22+
Assert.Equal(_ruleStr, replaceRuleStr.ToLower());
23+
}
24+
}
25+
}

src/SimpleStateMachine.StructuralSearch/Constant.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public static partial class Constant
9797
/// </summary>
9898
public static readonly char More = '>';
9999

100+
/// <summary>
101+
/// String: "=>"
102+
/// </summary>
103+
public static readonly string Should = $"{Equals}{More}";
104+
100105
/// <summary>
101106
/// Parenthesis chars: '(' and ')'
102107
/// </summary>

src/SimpleStateMachine.StructuralSearch/Rule/FindRule/FindRule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
public class FindRule
44
{
5-
public string Placeholder { get; }
5+
public IRuleParameter Placeholder { get; }
66

77
private IRule _rule { get; }
88

9-
public FindRule(string placeholder, IRule rule)
9+
public FindRule(IRuleParameter placeholder, IRule rule)
1010
{
1111
Placeholder = placeholder;
1212
_rule = rule;

src/SimpleStateMachine.StructuralSearch/Rule/ReplaceRule/ReplaceRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ReplaceRule(FindRule findRule, IRuleParameter parameter)
1818

1919
public override string ToString()
2020
{
21-
return $"{FindRule}{Constant.Space}{Parameter}";
21+
return $"{FindRule}{Constant.Space}{Constant.Should}{Constant.Space}{Parameter}";
2222
}
2323
}
2424
}

src/SimpleStateMachine.StructuralSearch/StructuralSearch/CommonTemplateParser.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ internal static readonly Parser<char, string> StringWithPlshd
1717
= AnyCharWithPlshd.AtLeastOnceString();
1818

1919
internal static readonly Parser<char, string> Should
20-
= Parsers.Stringc(Constant.Equals).Then(Parsers.Stringc(Constant.More),
21-
(c1, c2) => c1 + c2);
20+
= String(Constant.Should);
2221

2322
//can be contains one $
2423
internal static readonly Parser<char, string> StringWithoutPlaceholder

src/SimpleStateMachine.StructuralSearch/StructuralSearch/FindRulesParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ internal static readonly Parser<char, Func<IRule, IRule>> Not
7272
);
7373

7474
internal static readonly Parser<char, FindRule> Rule =
75-
Parser.Map((name, rule) => new FindRule(name, rule),
76-
CommonTemplateParser.Placeholder.TrimStart(),
75+
Parser.Map((parameter, rule) => new FindRule(parameter, rule),
76+
ParametersParser.PlaceholderParameter,
7777
Expr.TrimStart());
7878

7979
internal static FindRule ParseTemplate(string str)

0 commit comments

Comments
 (0)