Skip to content

Commit 94dba19

Browse files
committed
refact
1 parent 54de6d1 commit 94dba19

File tree

85 files changed

+269
-265
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

+269
-265
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 && this.Name == i.Name;
22+
=> other is Identifier i && 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 && this.Value == l.Value;
40+
=> other is Literal l && 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)this.Expr).Equals(c.Expr)
62-
&& this.Arguments.SequenceEqual(c.Arguments);
61+
&& ((Object)Expr).Equals(c.Expr)
62+
&& 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-
&& this.Type == u.Type
91-
&& ((Object)this.Expr).Equals(u.Expr);
90+
&& Type == u.Type
91+
&& ((Object)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-
&& this.Type == b.Type
129-
&& ((Object)this.Left).Equals(b.Left)
130-
&& ((Object)this.Right).Equals(b.Right);
128+
&& Type == b.Type
129+
&& ((Object)Left).Equals(b.Left)
130+
&& ((Object)Right).Equals(b.Right);
131131

132132
public double Invoke()
133133
{

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text.Json;
5-
using System.Text.RegularExpressions;
1+
using System.Collections.Generic;
62
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;
123
using static Pidgin.Parser;
13-
using String = System.String;
144

155
namespace SimpleStateMachine.StructuralSearch.Sandbox
166
{
@@ -23,10 +13,10 @@ static void Main(string[] args)
2313

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

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\"");
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\"");
3020
// var result1 = rule.Execute("test");
3121
// var result2 = rule.Execute("10");
3222
// var result3 = rule.Execute("5.3");

src/SimpleStateMachine.StructuralSearch.Tests/ConfigurationFileTests.cs

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

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

3834
foreach (var name in names)
3935
{
@@ -43,17 +39,17 @@ private ConfigurationFile Mock()
4339
var replaceTemplate = FileOrNull("ReplaceTemplate", fileName);
4440
var replaceRule = FileOrNull("ReplaceRule", fileName);
4541

46-
var fileRules = fileRule is null ? null : new List<string>{ fileRule };
47-
var replaceRules = replaceRule is null ? null : new List<string>{ replaceRule };
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 };
4844
var config = new Configuration
49-
{
50-
FindTemplate = findTemplate,
51-
FindRules = fileRules,
52-
ReplaceTemplate = replaceTemplate,
53-
ReplaceRules = replaceRules
54-
};
45+
(
46+
findTemplate : findTemplate ?? string.Empty,
47+
findRules : fileRules,
48+
replaceTemplate : replaceTemplate ?? string.Empty,
49+
replaceRules : replaceRules
50+
);
5551

56-
configurationFile.Configurations.Add(config);
52+
configurations.Add(config);
5753
}
5854

5955
string? FileOrNull(string folder, string name)
@@ -66,7 +62,7 @@ private ConfigurationFile Mock()
6662
return file.Replace("\r\n", "\n");
6763
}
6864

69-
return configurationFile;
65+
return new ConfigurationFile(configurations);
7066
}
7167
}
7268
}

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 System.Linq;
2-
using Pidgin;
1+
using Pidgin;
2+
using SimpleStateMachine.StructuralSearch.StructuralSearch;
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 _ruleStr = rule.ToString()?.ToLower();
19+
var str = rule.ToString()?.ToLower();
2020
Assert.NotNull(rule);
21-
Assert.Equal(_ruleStr, ruleStr.ToLower());
21+
Assert.Equal(str, ruleStr.ToLower());
2222
}
2323
}
2424
}

src/SimpleStateMachine.StructuralSearch.Tests/FindTemplateTests.cs

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

54
namespace SimpleStateMachine.StructuralSearch.Tests
@@ -14,7 +13,7 @@ public class FindTemplateTests
1413
public void TemplateParsingShouldBeSuccess(string templatePath)
1514
{
1615
var findTemplate = File.ReadAllText(templatePath);
17-
var template = StructuralSearch.ParseFindTemplate(findTemplate);
16+
var template = StructuralSearch.StructuralSearch.ParseFindTemplate(findTemplate);
1817

1918
Assert.NotNull(template);
2019
}
@@ -28,12 +27,11 @@ public void SourceParsingBeFindTemplateShouldBeSuccess(string templatePath, stri
2827
{
2928
var findTemplate = File.ReadAllText(templatePath);
3029
var source = File.ReadAllText(sourcePath);
31-
var findParser = StructuralSearch.ParseFindTemplate(findTemplate);
30+
var findParser = StructuralSearch.StructuralSearch.ParseFindTemplate(findTemplate);
3231
var parsingContext = new ParsingContext();
3332
var result = findParser.Parse(parsingContext, source);
3433

3534
Assert.NotNull(findParser);
36-
Assert.NotNull(result);
3735
Assert.NotNull(result.Value);
3836
Assert.Equal(result.Lenght, source.Length);
3937
}

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 value)
5+
public bool TryGetPlaceholder(string name, out Placeholder.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 GetPlaceholder(string name)
15+
public Placeholder.Placeholder GetPlaceholder(string name)
1616
{
17-
return new Placeholder(this, name, string.Empty);
17+
return new Placeholder.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.ParseFindTemplate(string.Empty));
11+
Assert.Throws<ParseException>(() => StructuralSearch.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.ParseFindTemplate(template);
23-
var res = templateParser.Parse(parsingContext, source);
22+
var templateParser = StructuralSearch.StructuralSearch.ParseFindTemplate(template);
23+
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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Linq;
2-
using Pidgin;
3-
using Xunit;
1+
using Xunit;
42

53
namespace SimpleStateMachine.StructuralSearch.Tests
64
{
@@ -17,10 +15,10 @@ public void ReplaceRuleParsingShouldBeSuccess(string findRule, string replaceRul
1715
{
1816
var placeholder = "$var$";
1917
var replaceRuleStr = $"{placeholder} {findRule} => {replaceRule}";
20-
var rule = StructuralSearch.ParseReplaceRule(replaceRuleStr);
21-
var _ruleStr = rule.ToString().ToLower();
18+
var rule = StructuralSearch.StructuralSearch.ParseReplaceRule(replaceRuleStr);
19+
var ruleStr = rule.ToString().ToLower();
2220
Assert.NotNull(rule);
23-
Assert.Equal(_ruleStr, replaceRuleStr.ToLower());
21+
Assert.Equal(ruleStr, replaceRuleStr.ToLower());
2422
}
2523
}
2624
}

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.IO;
1+
using System.IO;
32
using System.Linq;
43
using SimpleStateMachine.StructuralSearch.Tests.Mock;
54
using Xunit;
@@ -15,7 +14,7 @@ public class ReplaceTemplateTests
1514
public void TemplateParsingShouldHaveStepCount(string templatePath, int stepsCount)
1615
{
1716
var replaceTemplate = File.ReadAllText(templatePath);
18-
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
17+
var replaceBuilder = StructuralSearch.StructuralSearch.ParseReplaceTemplate(replaceTemplate);
1918
var result = replaceBuilder.Build(new EmptyParsingContext());
2019

2120
Assert.NotNull(replaceTemplate);
@@ -36,7 +35,7 @@ public void ReplaceBuildShouldBeSuccess(string templatePath, string resultPath,
3635
{
3736
var replaceTemplate = File.ReadAllText(templatePath);
3837
var replaceResult = File.ReadAllText(resultPath);
39-
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
38+
var replaceBuilder = StructuralSearch.StructuralSearch.ParseReplaceTemplate(replaceTemplate);
4039

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

src/SimpleStateMachine.StructuralSearch.Tests/Test.cs

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

43
namespace SimpleStateMachine.StructuralSearch.Tests
54
{

0 commit comments

Comments
 (0)