Skip to content

Commit b0cce27

Browse files
committed
ConfigurationFile tests
1 parent 27798f2 commit b0cce27

25 files changed

+189
-83
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text.Json;
45
using System.Text.RegularExpressions;
@@ -17,6 +18,10 @@ internal static class Program
1718
{
1819
static void Main(string[] args)
1920
{
21+
var t1 = new List<string> { "test" };
22+
var t2 = new List<string> { "test" };
23+
24+
var tr = Equals(t1, t2);
2025
//var tesds = ParametersParser.StringFormatParameter.ParseOrThrow("\"tfasdfa\\\"sd$var$.Lenght\"");
2126
var replaceRule = StructuralSearch.ParseReplaceRule("$var$ equals $var$ => $var$.Trim");
2227

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: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,55 @@ public void ConfigurationFileParsingShouldBeSuccess(string filePath)
1818
{
1919
var yml = File.ReadAllText(filePath);
2020
var deserializer = new DeserializerBuilder()
21-
.WithNamingConvention(PascalCaseNamingConvention.Instance)
21+
.WithNamingConvention(PascalCaseNamingConvention.Instance)
2222
.Build();
2323

2424
var cfg = deserializer.Deserialize<ConfigurationsFile>(yml);
25+
var mock = Mock();
26+
Assert.Equal(mock, cfg);
2527
}
2628

27-
// private ConfigurationsFile Mock()
28-
// {
29-
// var ifElseFindTemplate = "FindTemplate/IfElse.txt";
30-
// var ifValueIsNullFindTemplate = "FindTemplate/IfValueIsNull.txt";
31-
// var ternaryOperatorFindTemplate = "FindTemplate/TernaryOperator.txt";
32-
//
33-
// var configurationFile = new ConfigurationsFile();
34-
//
35-
// }
29+
private ConfigurationsFile Mock()
30+
{
31+
var names = new[] { "AssignmentNullUnionOperator", "NullUnionOperator", "TernaryOperator"};
32+
33+
var configurationFile = new ConfigurationsFile
34+
{
35+
Configurations = new List<Configuration>()
36+
};
37+
38+
foreach (var name in names)
39+
{
40+
var fileName = $"{name}.txt";
41+
var findTemplate = FileOrNull("FindTemplate", fileName);
42+
var fileRule = FileOrNull("FindRule", fileName) ;
43+
var replaceTemplate = FileOrNull("ReplaceTemplate", fileName);
44+
var replaceRule = FileOrNull("ReplaceRule", fileName);
45+
46+
var fileRules = fileRule is null ? null : new List<string>{ fileRule };
47+
var replaceRules = replaceRule is null ? null : new List<string>{ replaceRule };
48+
var config = new Configuration
49+
{
50+
FindTemplate = findTemplate,
51+
FindRules = fileRules,
52+
ReplaceTemplate = replaceTemplate,
53+
ReplaceRules = replaceRules
54+
};
55+
56+
configurationFile.Configurations.Add(config);
57+
}
58+
59+
string? FileOrNull(string folder, string name)
60+
{
61+
var path = Path.Combine(folder, name);
62+
if (!File.Exists(path))
63+
return null;
64+
65+
var file = File.ReadAllText(path);
66+
return file.Replace("\r\n", "\n");
67+
}
68+
69+
return configurationFile;
70+
}
3671
}
3772
}
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/IfValueIsNull.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")
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+
}

src/SimpleStateMachine.StructuralSearch.Tests/FindTemplate/IfValueIsNull.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/SimpleStateMachine.StructuralSearch.Tests/FindTemplate/IfElse.txt renamed to src/SimpleStateMachine.StructuralSearch.Tests/FindTemplate/NullUnionOperator.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
if($var1$ $sign$ $some1$)
1+
if($value1$ $sign$ null)
22
{
3-
$var$ = $value1$;
3+
$var$ = $value2$;
44
}
55
else
66
{
7-
$var$ = $value2$;
7+
$var$ = $value1$;
88
}

0 commit comments

Comments
 (0)