Skip to content

Commit e93282c

Browse files
Merge pull request #6 from SimpleStateMachine/dev
Dev
2 parents 4fdac03 + c5bf3e7 commit e93282c

File tree

79 files changed

+753
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+753
-381
lines changed
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text.Json;
45
using System.Text.RegularExpressions;
56
using Pidgin;
67
using SimpleStateMachine.StructuralSearch.Configurations;
78
using SimpleStateMachine.StructuralSearch.Extensions;
9+
using SimpleStateMachine.StructuralSearch.Helper;
810
using SimpleStateMachine.StructuralSearch.Rules;
911
using YamlDotNet.Serialization;
1012
using YamlDotNet.Serialization.NamingConventions;
@@ -17,38 +19,13 @@ internal static class Program
1719
{
1820
static void Main(string[] args)
1921
{
20-
//var tesds = ParametersParser.StringFormatParameter.ParseOrThrow("\"tfasdfa\\\"sd$var$.Lenght\"");
21-
var replaceRule = StructuralSearch.ParseReplaceRule("$var$ equals $var$ => $var$.Trim");
22-
23-
var rule = StructuralSearch.ParseFindRule("$var$ equals $var$.Lenght and Not StartsWith \"123\\\" $var$ \\\"\"");
24-
var rule2 = StructuralSearch.ParseFindRule("$var$ equals $var$.Offset.Start and Not StartsWith \"123\"");
25-
// var result1 = rule.Execute("test");
26-
// var result2 = rule.Execute("10");
27-
// var result3 = rule.Execute("5.3");
28-
29-
var t = ExprParser.ParseOrThrow("2 + 2 + 2");
30-
var resw = t.Invoke();
31-
var test = String("return ")
32-
.Then(AnyCharExcept(';').ManyString())
33-
.Then(Char(';').AtLeastOnceString())
34-
.Before(Char(';'));
35-
36-
// var template = StructuralSearch.ParseTemplate("");
37-
// var test = Parser.OneOf(String("Test"), CommonParser.Empty);
38-
var res = test.ParseOrThrow("return 125;;;;");
39-
40-
41-
// var lookahead = Parser.Lookahead(Char(';').Then(End).Try());
42-
// var t = Parser.String("return ").Then(Any.AtLeastOnceAsStringUntilNot(lookahead));
43-
// var res = t.ParseOrThrow("return 124;;");
44-
// var testTempalte = "if($test$)";
45-
// var testText = "if((value1)&&(value2))";
46-
// var testTextForMatch = "fdjkfnafdjankfjnafkajndaif((value1)&&(value2))";
47-
// var testTempalte2 = "return $value$;";
48-
// var testText2 = "return 125;;;;";
22+
// var config = YmlHelper.Parse(
23+
// @"C:\Users\roman\GitHub\SimpleStateMachine.StructuralSearch\src\SimpleStateMachine.StructuralSearch.Tests\ConfigurationFile\FullConfig.yml");
4924
//
50-
// var parser = StructuralSearch.ParseTemplate(template3);
51-
// var result = parser.ParseOrThrow(example3);
25+
// var parsers = config.Configurations
26+
// .Select(x => new StructuralSearchParser(x));
27+
//
28+
// parsers.
5229
}
5330
}
5431
}

src/SimpleStateMachine.StructuralSearch.Sandbox/SimpleStateMachine.StructuralSearch.Sandbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Pidgin" Version="3.0.0" />
12+
<PackageReference Include="Pidgin" Version="3.0.1" />
1313
<PackageReference Include="YamlDotNet" Version="11.2.1" />
1414
</ItemGroup>
1515

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
Configurations:
2+
# AssignmentNullUnionOperator
23
- FindTemplate: |-
34
if($var$ $sign$ null)
45
{
56
$var$ = $value$;
67
}
78
FindRules:
8-
- $sign$ In ("Is", "==")
9+
- $sign$ In ("Is", "==", "!=", "is not")
910
ReplaceTemplate: |-
1011
$var$ ??= $value$;
1112
ReplaceRules:
12-
13-
14-
15-
- FindTemplate: |-
16-
if($condition$)
17-
return $value1$;
18-
else
19-
return $value2$;
20-
FindRules:
21-
ReplaceTemplate: |-
22-
return $condition$? $value1$ : $value2$;
23-
ReplaceRules:
24-
25-
2613
14+
# NullUnionOperator
15+
2716
- FindTemplate: |-
2817
if($value1$ $sign$ null)
2918
{
30-
$var$ = $value1$;
19+
$var$ = $value2$;
3120
}
3221
else
3322
{
34-
$var$ = $value2$;
23+
$var$ = $value1$;
3524
}
3625
FindRules:
37-
- $sign$ In ("Is", "==")
26+
- $sign$ In ("Is", "==", "!=", "is not")
3827
ReplaceTemplate: |-
39-
$var$ = $value1$ ?? $value2$;
28+
$var$ = $value1$ ?? $value2$;
29+
ReplaceRules:
30+
31+
# TernaryOperator
32+
33+
- FindTemplate: |-
34+
if($condition$)
35+
return $value1$;
36+
else
37+
return $value2$;
38+
FindRules:
39+
ReplaceTemplate: |-
40+
return $condition$? $value1$ : $value2$;
4041
ReplaceRules:
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
Configurations:
2+
# AssignmentNullUnionOperator
23
- FindTemplate: |-
34
if($var$ $sign$ null)
45
{
56
$var$ = $value$;
67
}
78
FindRules:
8-
- $sign$ In ("Is", "==")
9+
- $sign$ In ("Is", "==", "!=", "is not")
910
ReplaceTemplate: |-
1011
$var$ ??= $value$;
11-
12-
13-
14-
- FindTemplate: |-
15-
if($condition$)
16-
return $value1$;
17-
else
18-
return $value2$;
19-
ReplaceTemplate: |-
20-
return $condition$? $value1$ : $value2$;
21-
22-
23-
12+
13+
# NullUnionOperator
14+
2415
- FindTemplate: |-
2516
if($value1$ $sign$ null)
2617
{
27-
$var$ = $value1$;
18+
$var$ = $value2$;
2819
}
2920
else
3021
{
31-
$var$ = $value2$;
22+
$var$ = $value1$;
3223
}
3324
FindRules:
34-
- $sign$ In ("Is", "==")
25+
- $sign$ In ("Is", "==", "!=", "is not")
26+
ReplaceTemplate: |-
27+
$var$ = $value1$ ?? $value2$;
28+
29+
# TernaryOperator
30+
31+
- FindTemplate: |-
32+
if($condition$)
33+
return $value1$;
34+
else
35+
return $value2$;
3536
ReplaceTemplate: |-
36-
$var$ = $value1$ ?? $value2$;
37+
return $condition$? $value1$ : $value2$;

src/SimpleStateMachine.StructuralSearch.Tests/ConfigurationFileTests.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Text.Json;
44
using Pidgin;
55
using SimpleStateMachine.StructuralSearch.Configurations;
6+
using SimpleStateMachine.StructuralSearch.Helper;
7+
using SimpleStateMachine.StructuralSearch.Tests.Mock;
68
using Xunit;
79
using YamlDotNet.Serialization;
810
using YamlDotNet.Serialization.NamingConventions;
@@ -16,18 +18,27 @@ public class ConfigurationFileTests
1618
[InlineData("ConfigurationFile/FullConfig.yml")]
1719
public void ConfigurationFileParsingShouldBeSuccess(string filePath)
1820
{
19-
var yml = File.ReadAllText(filePath);
20-
var deserializer = new DeserializerBuilder()
21-
.WithNamingConvention(PascalCaseNamingConvention.Instance)
22-
.Build();
23-
24-
var cfg = deserializer.Deserialize<ConfigurationsFile>(yml);
21+
var cfg = YmlHelper.Parse(filePath);
22+
var mock = Mock();
23+
Assert.Equal(mock, cfg);
2524
}
2625

27-
// private ConfigurationsFile Mock()
28-
// {
29-
// var configurationFile = new ConfigurationsFile();
30-
//
31-
// }
26+
private ConfigurationFile Mock()
27+
{
28+
var names = new[] { "AssignmentNullUnionOperator", "NullUnionOperator", "TernaryOperator"};
29+
30+
var configurationFile = new ConfigurationFile
31+
{
32+
Configurations = new List<Configuration>()
33+
};
34+
35+
foreach (var name in names)
36+
{
37+
var config = ConfigurationMock.GetConfigurationFromFiles(name);
38+
configurationFile.Configurations.Add(config);
39+
}
40+
41+
return configurationFile;
42+
}
3243
}
3344
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$sign$ In ("Is", "==", "!=", "is not")

src/SimpleStateMachine.StructuralSearch.Tests/FindRule/IfValueIsNullFindRule.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$sign$ In ("Is", "==", "!=", "is not")

src/SimpleStateMachine.StructuralSearch.Tests/FindRuleParserTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using System.Linq;
1+
using System;
2+
using System.IO;
3+
using System.Linq;
24
using Pidgin;
5+
using SimpleStateMachine.StructuralSearch.Rules;
36
using Xunit;
47

58
namespace SimpleStateMachine.StructuralSearch.Tests
@@ -13,12 +16,45 @@ public class FindRuleParserTests
1316
[InlineData("Not equals $var$.offset.Start")]
1417
[InlineData("equals $var$.Lenght and Not StartsWith \"123\"")]
1518
[InlineData("equals $var$.Lenght and Not StartsWith \"\\\"Test\"")]
16-
public void FindRuleParsingShouldBeSuccess(string ruleStr)
19+
[InlineData("Contains $var$.Lenght")]
20+
[InlineData("Contains \"123\"")]
21+
[InlineData("StartsWith $var$.Lenght")]
22+
[InlineData("StartsWith \"123\"")]
23+
[InlineData("EndsWith $var$.Lenght")]
24+
[InlineData("EndsWith \"123\"")]
25+
[InlineData("Match $var$.Lenght")]
26+
[InlineData("Is Int")]
27+
[InlineData("Is DateTime")]
28+
29+
public void FindRuleExprParsingShouldBeSuccess(string ruleStr)
1730
{
1831
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
1932
var _ruleStr = rule.ToString()?.ToLower();
2033
Assert.NotNull(rule);
2134
Assert.Equal(_ruleStr, ruleStr.ToLower());
2235
}
36+
37+
[Theory]
38+
[InlineData("In \"Is\", \"==\", \"!=\", \"is not\"", "In \"Is\",\"==\",\"!=\",\"is not\"")]
39+
[InlineData("In (\"Is\", \"==\", \"!=\", \"is not\")", "In \"Is\",\"==\",\"!=\",\"is not\"")]
40+
public void FindRuleExprParsingShouldBeEqualsCustomResult(string ruleStr, string customResult)
41+
{
42+
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
43+
var _ruleStr = rule.ToString()?.ToLower();
44+
Assert.NotNull(rule);
45+
Assert.Equal(_ruleStr, customResult.ToLower());
46+
}
47+
48+
[Theory]
49+
[InlineData("FindRule/NullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"")]
50+
[InlineData("FindRule/AssignmentNullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"")]
51+
public void FindRuleParsingFromFileShouldBeSuccess(string filePath, string customResult)
52+
{
53+
var ruleStr = File.ReadAllText(filePath);
54+
var rule = StructuralSearch.ParseFindRule(ruleStr);
55+
var _ruleStr = rule.ToString()?.ToLower();
56+
Assert.NotNull(rule);
57+
Assert.Equal(_ruleStr, customResult.ToLower());
58+
}
2359
}
2460
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if($var$ $sign$ null)
2+
{
3+
$var$ = $value$;
4+
}

0 commit comments

Comments
 (0)