Skip to content

Commit 9777ff5

Browse files
committed
Revert "refact"
This reverts commit 94dba19.
1 parent 94dba19 commit 9777ff5

File tree

85 files changed

+265
-269
lines changed

Some content is hidden

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

85 files changed

+265
-269
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Expr.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Identifier(string name)
1919
}
2020

2121
public bool Equals(IExpr? other)
22-
=> other is Identifier i && Name == i.Name;
22+
=> other is Identifier i && this.Name == i.Name;
2323

2424
public double Invoke()
2525
{
@@ -37,7 +37,7 @@ public Literal(double value)
3737
}
3838

3939
public bool Equals(IExpr? other)
40-
=> other is Literal l && Value == l.Value;
40+
=> other is Literal l && this.Value == l.Value;
4141

4242
public double Invoke()
4343
{
@@ -58,8 +58,8 @@ public Call(IExpr expr, ImmutableArray<IExpr> arguments)
5858

5959
public bool Equals(IExpr? other)
6060
=> other is Call c
61-
&& ((Object)Expr).Equals(c.Expr)
62-
&& Arguments.SequenceEqual(c.Arguments);
61+
&& ((Object)this.Expr).Equals(c.Expr)
62+
&& this.Arguments.SequenceEqual(c.Arguments);
6363

6464
public double Invoke()
6565
{
@@ -87,8 +87,8 @@ public UnaryOp(UnaryOperatorType type, IExpr expr)
8787

8888
public bool Equals(IExpr? other)
8989
=> other is UnaryOp u
90-
&& Type == u.Type
91-
&& ((Object)Expr).Equals(u.Expr);
90+
&& this.Type == u.Type
91+
&& ((Object)this.Expr).Equals(u.Expr);
9292

9393
public double Invoke()
9494
{
@@ -125,9 +125,9 @@ public BinaryOp(BinaryOperatorType type, IExpr left, IExpr right)
125125

126126
public bool Equals(IExpr? other)
127127
=> other is BinaryOp b
128-
&& Type == b.Type
129-
&& ((Object)Left).Equals(b.Left)
130-
&& ((Object)Right).Equals(b.Right);
128+
&& this.Type == b.Type
129+
&& ((Object)this.Left).Equals(b.Left)
130+
&& ((Object)this.Right).Equals(b.Right);
131131

132132
public double Invoke()
133133
{

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.Json;
5+
using System.Text.RegularExpressions;
26
using Pidgin;
7+
using SimpleStateMachine.StructuralSearch.Configurations;
8+
using SimpleStateMachine.StructuralSearch.Extensions;
9+
using SimpleStateMachine.StructuralSearch.Rules;
10+
using YamlDotNet.Serialization;
11+
using YamlDotNet.Serialization.NamingConventions;
312
using static Pidgin.Parser;
13+
using String = System.String;
414

515
namespace SimpleStateMachine.StructuralSearch.Sandbox
616
{
@@ -13,10 +23,10 @@ static void Main(string[] args)
1323

1424
var tr = Equals(t1, t2);
1525
//var tesds = ParametersParser.StringFormatParameter.ParseOrThrow("\"tfasdfa\\\"sd$var$.Lenght\"");
16-
var replaceRule = StructuralSearch.StructuralSearch.ParseReplaceRule("$var$ equals $var$ => $var$.Trim");
26+
var replaceRule = StructuralSearch.ParseReplaceRule("$var$ equals $var$ => $var$.Trim");
1727

18-
var rule = StructuralSearch.StructuralSearch.ParseFindRule("$var$ equals $var$.Lenght and Not StartsWith \"123\\\" $var$ \\\"\"");
19-
var rule2 = StructuralSearch.StructuralSearch.ParseFindRule("$var$ equals $var$.Offset.Start and Not StartsWith \"123\"");
28+
var rule = StructuralSearch.ParseFindRule("$var$ equals $var$.Lenght and Not StartsWith \"123\\\" $var$ \\\"\"");
29+
var rule2 = StructuralSearch.ParseFindRule("$var$ equals $var$.Offset.Start and Not StartsWith \"123\"");
2030
// var result1 = rule.Execute("test");
2131
// var result2 = rule.Execute("10");
2232
// var result3 = rule.Execute("5.3");

src/SimpleStateMachine.StructuralSearch.Tests/ConfigurationFileTests.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
3-
using System.Linq;
3+
using System.Text.Json;
4+
using Pidgin;
45
using SimpleStateMachine.StructuralSearch.Configurations;
56
using Xunit;
67
using YamlDotNet.Serialization;
@@ -29,7 +30,10 @@ private ConfigurationFile Mock()
2930
{
3031
var names = new[] { "AssignmentNullUnionOperator", "NullUnionOperator", "TernaryOperator"};
3132

32-
var configurations = new List<Configuration>();
33+
var configurationFile = new ConfigurationFile
34+
{
35+
Configurations = new List<Configuration>()
36+
};
3337

3438
foreach (var name in names)
3539
{
@@ -39,17 +43,17 @@ private ConfigurationFile Mock()
3943
var replaceTemplate = FileOrNull("ReplaceTemplate", fileName);
4044
var replaceRule = FileOrNull("ReplaceRule", fileName);
4145

42-
var fileRules = fileRule is null ? Enumerable.Empty<string>() : new List<string>{ fileRule };
43-
var replaceRules = replaceRule is null ? Enumerable.Empty<string>() : new List<string>{ replaceRule };
46+
var fileRules = fileRule is null ? null : new List<string>{ fileRule };
47+
var replaceRules = replaceRule is null ? null : new List<string>{ replaceRule };
4448
var config = new Configuration
45-
(
46-
findTemplate : findTemplate ?? string.Empty,
47-
findRules : fileRules,
48-
replaceTemplate : replaceTemplate ?? string.Empty,
49-
replaceRules : replaceRules
50-
);
49+
{
50+
FindTemplate = findTemplate,
51+
FindRules = fileRules,
52+
ReplaceTemplate = replaceTemplate,
53+
ReplaceRules = replaceRules
54+
};
5155

52-
configurations.Add(config);
56+
configurationFile.Configurations.Add(config);
5357
}
5458

5559
string? FileOrNull(string folder, string name)
@@ -62,7 +66,7 @@ private ConfigurationFile Mock()
6266
return file.Replace("\r\n", "\n");
6367
}
6468

65-
return new ConfigurationFile(configurations);
69+
return configurationFile;
6670
}
6771
}
6872
}

src/SimpleStateMachine.StructuralSearch.Tests/FindRuleParserTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Pidgin;
2-
using SimpleStateMachine.StructuralSearch.StructuralSearch;
1+
using System.Linq;
2+
using Pidgin;
33
using Xunit;
44

55
namespace SimpleStateMachine.StructuralSearch.Tests
@@ -16,9 +16,9 @@ public class FindRuleParserTests
1616
public void FindRuleParsingShouldBeSuccess(string ruleStr)
1717
{
1818
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
19-
var str = rule.ToString()?.ToLower();
19+
var _ruleStr = rule.ToString()?.ToLower();
2020
Assert.NotNull(rule);
21-
Assert.Equal(str, ruleStr.ToLower());
21+
Assert.Equal(_ruleStr, ruleStr.ToLower());
2222
}
2323
}
2424
}

src/SimpleStateMachine.StructuralSearch.Tests/FindTemplateTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using Pidgin;
23
using Xunit;
34

45
namespace SimpleStateMachine.StructuralSearch.Tests
@@ -13,7 +14,7 @@ public class FindTemplateTests
1314
public void TemplateParsingShouldBeSuccess(string templatePath)
1415
{
1516
var findTemplate = File.ReadAllText(templatePath);
16-
var template = StructuralSearch.StructuralSearch.ParseFindTemplate(findTemplate);
17+
var template = StructuralSearch.ParseFindTemplate(findTemplate);
1718

1819
Assert.NotNull(template);
1920
}
@@ -27,11 +28,12 @@ public void SourceParsingBeFindTemplateShouldBeSuccess(string templatePath, stri
2728
{
2829
var findTemplate = File.ReadAllText(templatePath);
2930
var source = File.ReadAllText(sourcePath);
30-
var findParser = StructuralSearch.StructuralSearch.ParseFindTemplate(findTemplate);
31+
var findParser = StructuralSearch.ParseFindTemplate(findTemplate);
3132
var parsingContext = new ParsingContext();
3233
var result = findParser.Parse(parsingContext, source);
3334

3435
Assert.NotNull(findParser);
36+
Assert.NotNull(result);
3537
Assert.NotNull(result.Value);
3638
Assert.Equal(result.Lenght, source.Length);
3739
}

src/SimpleStateMachine.StructuralSearch.Tests/Mock/EmptyParsingContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public class EmptyParsingContext : IParsingContext
44
{
5-
public bool TryGetPlaceholder(string name, out Placeholder.Placeholder? value)
5+
public bool TryGetPlaceholder(string name, out Placeholder value)
66
{
77
throw new System.NotImplementedException();
88
}
@@ -12,9 +12,9 @@ public void AddPlaceholder(string name, string value)
1212
throw new System.NotImplementedException();
1313
}
1414

15-
public Placeholder.Placeholder GetPlaceholder(string name)
15+
public Placeholder GetPlaceholder(string name)
1616
{
17-
return new Placeholder.Placeholder(this, name, string.Empty);
17+
return new Placeholder(this, name, string.Empty);
1818
}
1919
}
2020
}

src/SimpleStateMachine.StructuralSearch.Tests/PlaceholderParserTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class PlaceholderParserTests
88
[Fact]
99
public void FindTemplateShouldBeNotEmpty()
1010
{
11-
Assert.Throws<ParseException>(() => StructuralSearch.StructuralSearch.ParseFindTemplate(string.Empty));
11+
Assert.Throws<ParseException>(() => StructuralSearch.ParseFindTemplate(string.Empty));
1212
}
1313

1414
[Theory]
@@ -19,26 +19,26 @@ public void FindTemplateShouldBeNotEmpty()
1919
public void TemplateParsingShouldBeSuccess(string template, string source, string result)
2020
{
2121
var parsingContext = new ParsingContext();
22-
var templateParser = StructuralSearch.StructuralSearch.ParseFindTemplate(template);
23-
templateParser.Parse(parsingContext, source);
22+
var templateParser = StructuralSearch.ParseFindTemplate(template);
23+
var res = templateParser.Parse(parsingContext, source);
2424
var placeholder = parsingContext.GetPlaceholder("test");
2525

2626
Assert.Equal(placeholder.Value, result);
2727
}
2828

29-
// [Theory]
30-
// [InlineData("$var$;$var2$;", "test;;;test;;;", "value ")]
31-
// public void TemplateParsingShouldBeSuccess2(string template, string source, string result)
32-
// {
33-
// var parsingContext = new ParsingContext();
34-
// var templateParser = StructuralSearch.ParseFindTemplate(template);
35-
// var res = templateParser.Parse(parsingContext, source);
36-
//
37-
//
38-
// // var templateStr = File.ReadAllText(templatePath);
39-
// // var template = StructuralSearch.ParseTemplate(templateStr);
40-
// //
41-
// // Assert.NotNull(template);
42-
// }
29+
[Theory]
30+
[InlineData("$var$;$var2$;", "test;;;test;;;", "value ")]
31+
public void TemplateParsingShouldBeSuccess2(string template, string source, string result)
32+
{
33+
var parsingContext = new ParsingContext();
34+
var templateParser = StructuralSearch.ParseFindTemplate(template);
35+
var res = templateParser.Parse(parsingContext, source);
36+
37+
38+
// var templateStr = File.ReadAllText(templatePath);
39+
// var template = StructuralSearch.ParseTemplate(templateStr);
40+
//
41+
// Assert.NotNull(template);
42+
}
4343
}
4444
}

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceRuleParserTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Xunit;
1+
using System.Linq;
2+
using Pidgin;
3+
using Xunit;
24

35
namespace SimpleStateMachine.StructuralSearch.Tests
46
{
@@ -15,10 +17,10 @@ public void ReplaceRuleParsingShouldBeSuccess(string findRule, string replaceRul
1517
{
1618
var placeholder = "$var$";
1719
var replaceRuleStr = $"{placeholder} {findRule} => {replaceRule}";
18-
var rule = StructuralSearch.StructuralSearch.ParseReplaceRule(replaceRuleStr);
19-
var ruleStr = rule.ToString().ToLower();
20+
var rule = StructuralSearch.ParseReplaceRule(replaceRuleStr);
21+
var _ruleStr = rule.ToString().ToLower();
2022
Assert.NotNull(rule);
21-
Assert.Equal(ruleStr, replaceRuleStr.ToLower());
23+
Assert.Equal(_ruleStr, replaceRuleStr.ToLower());
2224
}
2325
}
2426
}

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using System.Linq;
34
using SimpleStateMachine.StructuralSearch.Tests.Mock;
45
using Xunit;
@@ -14,7 +15,7 @@ public class ReplaceTemplateTests
1415
public void TemplateParsingShouldHaveStepCount(string templatePath, int stepsCount)
1516
{
1617
var replaceTemplate = File.ReadAllText(templatePath);
17-
var replaceBuilder = StructuralSearch.StructuralSearch.ParseReplaceTemplate(replaceTemplate);
18+
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
1819
var result = replaceBuilder.Build(new EmptyParsingContext());
1920

2021
Assert.NotNull(replaceTemplate);
@@ -35,7 +36,7 @@ public void ReplaceBuildShouldBeSuccess(string templatePath, string resultPath,
3536
{
3637
var replaceTemplate = File.ReadAllText(templatePath);
3738
var replaceResult = File.ReadAllText(resultPath);
38-
var replaceBuilder = StructuralSearch.StructuralSearch.ParseReplaceTemplate(replaceTemplate);
39+
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
3940

4041
var parsingContext = new ParsingContext();
4142
for (int i = 0; i < keys.Length; i++)

src/SimpleStateMachine.StructuralSearch.Tests/Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using YamlDotNet.Serialization;
2+
using System.Text.RegularExpressions;
23

34
namespace SimpleStateMachine.StructuralSearch.Tests
45
{

0 commit comments

Comments
 (0)