Skip to content

Commit a9670f9

Browse files
committed
some before check
1 parent bff4e31 commit a9670f9

File tree

15 files changed

+219
-29
lines changed

15 files changed

+219
-29
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace SimpleStateMachine.StructuralSearch.Tests.Examples;
2+
3+
public class NullUnionOperator
4+
{
5+
public int Test1()
6+
{
7+
int? temp = 1;
8+
9+
if(temp is null)
10+
return 3;
11+
else
12+
return 4;
13+
}
14+
15+
public int Test2()
16+
{
17+
int? temp = 5;
18+
19+
if(temp is null)
20+
return 7;
21+
else
22+
return 8;
23+
}
24+
25+
public int Test3()
26+
{
27+
int? temp2 = 1;
28+
29+
if(temp2 is null)
30+
return 3;
31+
else
32+
return 4;
33+
}
34+
35+
public int Test4()
36+
{
37+
int? temp3 = 5;
38+
39+
if(temp3 is null)
40+
return 7;
41+
else if (temp3 == 8)
42+
return 9;
43+
else
44+
return 10;
45+
}
46+
47+
public void Test5()
48+
{
49+
50+
}
51+
}

src/SimpleStateMachine.StructuralSearch.Tests/FindRuleParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class FindRuleParserTests
2828

2929
public void FindRuleExprParsingShouldBeSuccess(string ruleStr)
3030
{
31-
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
31+
var rule = RuleParser.Expr.ParseOrThrow(ruleStr);
3232
var _ruleStr = rule.ToString()?.ToLower();
3333
Assert.NotNull(rule);
3434
Assert.Equal(_ruleStr, ruleStr.ToLower());
@@ -39,7 +39,7 @@ public void FindRuleExprParsingShouldBeSuccess(string ruleStr)
3939
[InlineData("In (\"Is\", \"==\", \"!=\", \"is not\")", "In \"Is\",\"==\",\"!=\",\"is not\"")]
4040
public void FindRuleExprParsingShouldBeEqualsCustomResult(string ruleStr, string customResult)
4141
{
42-
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
42+
var rule = RuleParser.Expr.ParseOrThrow(ruleStr);
4343
var _ruleStr = rule.ToString()?.ToLower();
4444
Assert.NotNull(rule);
4545
Assert.Equal(_ruleStr, customResult.ToLower());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$sign$ Is ("Is", "==", "!=", "is not")

src/SimpleStateMachine.StructuralSearch.Tests/SimpleStateMachine.StructuralSearch.Tests.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@
5050
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5151
</Content>
5252
</ItemGroup>
53-
54-
<ItemGroup>
55-
<Folder Include="ReplaceRule" />
56-
</ItemGroup>
5753

5854
</Project>

src/SimpleStateMachine.StructuralSearch.Tests/StructurSearchParserTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public static void StructuralSearchShouldBeSuccess(string exampleName, string ex
2222

2323
var matches = parser.Parse(ref context);
2424
Assert.Equal(matches.Count(), matchesCount);
25-
// foreach (var match in matches)
26-
// {
27-
// input.Replace(match.Match);
28-
// }
29-
3025
}
3126
}
3227
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SimpleStateMachine.StructuralSearch.Rules;
2+
3+
public interface ILogicalRule
4+
{
5+
bool Execute();
6+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using SimpleStateMachine.StructuralSearch.Helper;
2+
3+
namespace SimpleStateMachine.StructuralSearch.Rules;
4+
5+
public class BinaryLogicalRule : ILogicalRule
6+
{
7+
public BinaryRuleType Type { get; }
8+
9+
public ILogicalRule Left { get; }
10+
11+
public ILogicalRule Right { get; }
12+
13+
public BinaryLogicalRule(BinaryRuleType type, ILogicalRule left, ILogicalRule right)
14+
{
15+
Type = type;
16+
Left = left;
17+
Right = right;
18+
}
19+
20+
public bool Execute()
21+
{
22+
var left = Left.Execute();
23+
var right = Right.Execute();
24+
25+
return LogicalHelper.Calculate(Type, left, right);
26+
}
27+
28+
public override string ToString()
29+
{
30+
return $"{Left}{Constant.Space}{Type}{Constant.Space}{Right}";
31+
}
32+
}

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/FindRule.cs renamed to src/SimpleStateMachine.StructuralSearch/Rules/FindRule/LogicalRule/PlaceholderLogicalRule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace SimpleStateMachine.StructuralSearch.Rules
22
{
3-
public class FindRule
3+
public class PlaceholderLogicalRule : ILogicalRule
44
{
55
public PlaceholderParameter Placeholder { get; }
66

77
private IRule _rule { get; }
88

9-
public FindRule(PlaceholderParameter placeholder, IRule rule)
9+
public PlaceholderLogicalRule(PlaceholderParameter placeholder, IRule rule)
1010
{
1111
Placeholder = placeholder;
1212
_rule = rule;
@@ -16,7 +16,7 @@ public override string ToString()
1616
{
1717
return $"{Placeholder}{Constant.Space}{_rule}";
1818
}
19-
19+
2020
public bool Execute()
2121
{
2222
var value = Placeholder.GetValue();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
namespace SimpleStateMachine.StructuralSearch.Rules;
4+
5+
public class UnaryLogicalRule : ILogicalRule
6+
{
7+
public UnaryRuleType Type { get; }
8+
9+
public ILogicalRule Parameter { get; }
10+
11+
public UnaryLogicalRule(UnaryRuleType type, ILogicalRule parameter)
12+
{
13+
Type = type;
14+
Parameter = parameter;
15+
}
16+
17+
public bool Execute()
18+
{
19+
var result = Parameter.Execute();
20+
21+
return Type switch
22+
{
23+
UnaryRuleType.Not => !result,
24+
_ => throw new ArgumentOutOfRangeException()
25+
};
26+
}
27+
28+
public override string ToString()
29+
{
30+
return $"{Type}{Constant.Space}{Parameter}";
31+
}
32+
}

src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace SimpleStateMachine.StructuralSearch
66
{
77
public class ReplaceRule
88
{
9-
public FindRule FindRule { get; }
9+
public PlaceholderLogicalRule FindRule { get; }
1010

1111
public IRuleParameter Parameter { get; }
1212

13-
public ReplaceRule(FindRule findRule, IRuleParameter parameter)
13+
public ReplaceRule(PlaceholderLogicalRule findRule, IRuleParameter parameter)
1414
{
1515
FindRule = findRule;
1616
Parameter = parameter;

0 commit comments

Comments
 (0)