Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions SimpleStateMachine.StructuralSearch.Action/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;
using SimpleStateMachine.StructuralSearch.Action;
using System.Web;
using SimpleStateMachine.StructuralSearch.Action;
using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileSystemGlobbing;
Expand Down
4 changes: 1 addition & 3 deletions src/SimpleStateMachine.StructuralSearch.Sandbox/Expr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Collections.Immutable;

namespace SimpleStateMachine.StructuralSearch.Sandbox
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Pidgin;
using Pidgin;
using Pidgin.Expression;
using static Pidgin.Parser;

Expand Down
14 changes: 1 addition & 13 deletions src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Pidgin;
using SimpleStateMachine.StructuralSearch.Configurations;
using Pidgin;
using SimpleStateMachine.StructuralSearch.Extensions;
using SimpleStateMachine.StructuralSearch.Helper;
using SimpleStateMachine.StructuralSearch.Rules;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using static Pidgin.Parser;
using String = System.String;

namespace SimpleStateMachine.StructuralSearch.Sandbox
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$var$ = $value$;
}
FindRules:
- $sign$ In ("Is", "==", "!=", "is not")
- $sign$ In ("is", "==", "!=", "is not")
ReplaceTemplate: |-
$var$ ??= $value$;
ReplaceRules:
Expand All @@ -19,12 +19,12 @@
else
$var$ = $value1$;
FindRules:
- $sign$ In ("Is", "==", "!=", "is not")
- $value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")
- $sign$ In ("is", "==", "!=", "is not")
- $value$ In ($value1$, $value2$)
ReplaceTemplate: |-
$var$ = $value1$ ?? $value2$;
ReplaceRules:
- $sign$ In ("!=", "is not") then $var2$ => $var1$, $var1$ => $var2$
ReplaceRules:
- $sign$ In ("!=", "is not") then $value2$ => $value1$, $value1$ => $value2$

# TernaryOperator

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Configurations:
- FindTemplate: if($var1$ == $var2$)
FindRules:
- $var1$ Is Var
- $var2$ is Var
ReplaceTemplate: $var1$, $var2$
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$var$ = $value$;
}
FindRules:
- $sign$ In ("Is", "==", "!=", "is not")
- $sign$ In ("is", "==", "!=", "is not")
ReplaceTemplate: |-
$var$ ??= $value$;

Expand All @@ -18,12 +18,13 @@
else
$var$ = $value1$;
FindRules:
- $sign$ In ("Is", "==", "!=", "is not")
- $value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")
- $sign$ In ("is", "==", "!=", "is not")
- $value$ In ($value1$, $value2$)
ReplaceTemplate: |-
$var$ = $value1$ ?? $value2$;
ReplaceRules:
- $sign$ In ("!=", "is not") then $var2$ => $var1$, $var1$ => $var2$
ReplaceRules:
- $sign$ In ("!=", "is not") then $value2$ => $value1$, $value1$ => $value2$

# TernaryOperator

- FindTemplate: |-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Pidgin;
using SimpleStateMachine.StructuralSearch.Configurations;
using SimpleStateMachine.StructuralSearch.Helper;
using SimpleStateMachine.StructuralSearch.Tests.Mock;
using Xunit;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace SimpleStateMachine.StructuralSearch.Tests
{
public class ConfigurationFileTests
public class ConfigurationFileParserTests
{
[Theory]
[InlineData("ConfigurationFile/ShortConfig.yml")]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Text.Json;

namespace SimpleStateMachine.StructuralSearch.Tests.Examples;
namespace SimpleStateMachine.StructuralSearch.Tests.Examples;

public class Common
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Text.Json;

namespace SimpleStateMachine.StructuralSearch.Tests.Examples;
namespace SimpleStateMachine.StructuralSearch.Tests.Examples;

public class Common2
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace SimpleStateMachine.StructuralSearch.Tests.ExamplesInput;

public class NullUnionOperator
{
public void Test1()
{
int? result;
int? temp1 = 5;
int? temp2 = 5;

if(temp1 is null)
result = temp2;
else
result = temp1;
}

public void Test2()
{

int? result;
int? temp1 = 6;
int? temp2 = 7;
if(temp1 is not null)
result = temp2;
else
result = temp1;
}

public int Test3()
{
int? temp3 = 5;

if(temp3 is null)
return 7;
else if (temp3 == 8)
return 9;
else
return 10;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace SimpleStateMachine.StructuralSearch.Tests.Examples
namespace SimpleStateMachine.StructuralSearch.Tests.ExamplesInput
{
public class TernaryOperator
{
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace SimpleStateMachine.StructuralSearch.Tests.ExamplesOutput;

public class NullUnionOperator
{
public void Test1()
{
int? result;
int? temp1 = 5;
int? temp2 = 5;

result = temp1 ?? temp2;
}

public void Test2()
{

int? result;
int? temp1 = 6;
int? temp2 = 7;
result = temp2 ?? temp1;
}

public int Test3()
{
int? temp3 = 5;

if(temp3 is null)
return 7;
else if (temp3 == 8)
return 9;
else
return 10;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;

namespace SimpleStateMachine.StructuralSearch.Tests.ExamplesInput
{
public class TernaryOperator
{
public int Test1()
{
var temp = 1;

return temp == 2? 3 : 4;
}

public int Test2()
{
var temp = 5;

return temp == 6? 7 : 8;
}

public int Test3()
{
var temp2 = 1;

return temp2 == 2? 3 : 4;
}

public int Test4()
{
var temp3 = 5;

if(temp3 == 6)
return 7;
else if (temp3 == 8)
return 9;
else
return 10;
}

public void Test5()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$sign$ In ("Is", "==", "!=", "is not")
$sign$ In ("is", "==", "!=", "is not")
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$sign$ In ("Is", "==", "!=", "is not")
$value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")
$sign$ In ("is", "==", "!=", "is not")
$value$ In ($value1$, $value2$)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using System.IO;
using System.Linq;
using Pidgin;
using SimpleStateMachine.StructuralSearch.Rules;
using Xunit;

namespace SimpleStateMachine.StructuralSearch.Tests
Expand All @@ -25,9 +23,11 @@ public class FindRuleParserTests
[InlineData("$var$ StartsWith \"123\"")]
[InlineData("$var$ EndsWith $var$.Lenght")]
[InlineData("$var$ EndsWith \"123\"")]
[InlineData("$var$ Match $var$.Lenght")]
// [InlineData("$var$ Match $var$.Lenght")]
[InlineData("$var$ Is Int")]
[InlineData("$var$ Is DateTime")]
[InlineData("$var$ equals $var1$ or $var2$ equals $var1$")]
[InlineData("$var$ match \"[a-b]+\"")]
public void FindRuleExprParsingShouldBeSuccess(string ruleStr)
{
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
Expand Down Expand Up @@ -62,8 +62,8 @@ public void FindRuleExprParsingShouldBeEqualsCustomResult(int number, string rul
Assert.Equal(_ruleStr, customResult.ToLower());
}
[Theory]
[InlineData("FindRule/NullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"", "$value$ In $value1$,\"$value1$\\.Value\",$value2$,\"$value2$\\.Value\"")]
[InlineData("FindRule/AssignmentNullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"")]
[InlineData("FindRule/NullUnionOperator.txt", "$sign$ In \"is\",\"==\",\"!=\",\"is not\"", "$value$ In $value1$,$value2$")]
[InlineData("FindRule/AssignmentNullUnionOperator.txt", "$sign$ In \"is\",\"==\",\"!=\",\"is not\"")]
public void FindRuleParsingFromFileShouldBeSuccess(string filePath, params string[] customResult)
{
var ruleStr = File.ReadAllText(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ public void StringFormatParameterParsingShouldBeFail(string str)
{
Assert.Throws<ParseException>(() => ParametersParser.StringFormatParameter.ParseOrThrow(str));
}

[Theory]
[InlineData("$var$")]
[InlineData("$var$.Trim")]
[InlineData("$var$.Lenght")]
[InlineData("$var$.Lenght.Trim")]
[InlineData("$var$.RemoveSubStr(\"123\")")]
[InlineData("$var$.Lenght.RemoveSubStr(\"123\")")]
[InlineData("$var$.Lenght.Trim.RemoveSubStr(\"123\")")]
public void ParameterParsingShouldBeSuccess(string str)
{
var parameter = ParametersParser.Parameter.ParseOrThrow(str);
var parameterStr = parameter.ToString().ToLower();
Assert.Equal(parameterStr.ToLower(), str.ToLower());
}

}
Loading