Skip to content

Commit e7e0edb

Browse files
committed
Progress on #71 -- Factory methods
1 parent c80f093 commit e7e0edb

5 files changed

Lines changed: 48 additions & 109 deletions

File tree

Tests.Common/Constructed/MakeDefault.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,10 @@ namespace ExpressionToString.Tests {
66
public partial class ConstructedBase {
77
[Fact]
88
[Trait("Category", Defaults)]
9-
public void MakeDefaultRefType() => RunTest(
10-
Default(typeof(string)),
11-
"default(string)",
12-
"CType(Nothing, String)",
13-
@"Default(
14-
typeof(string)
15-
)"
16-
);
9+
public void MakeDefaultRefType() => PreRunTest();
1710

1811
[Fact]
1912
[Trait("Category", Defaults)]
20-
public void MakeDefaultValueType() => RunTest(
21-
Default(typeof(int)),
22-
"default(int)",
23-
"CType(Nothing, Integer)",
24-
@"Default(
25-
typeof(int)
26-
)"
27-
);
13+
public void MakeDefaultValueType() => PreRunTest();
2814
}
2915
}
Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
11
using Xunit;
2-
using static System.Linq.Expressions.Expression;
32
using static ExpressionToString.Tests.Categories;
43

54
namespace ExpressionToString.Tests {
65
public partial class ConstructedBase {
76
[Fact]
87
[Trait("Category", Loops)]
9-
public void EmptyLoop() => RunTest(
10-
Loop(Constant(true)),
11-
@"while (true) {
12-
true;
13-
}",
14-
@"Do
15-
True
16-
Loop",
17-
@"Loop(
18-
Constant(true)
19-
)"
20-
);
8+
public void EmptyLoop() => PreRunTest();
219

2210
[Fact]
2311
[Trait("Category", Loops)]
24-
public void EmptyLoop1() => RunTest(
25-
Loop(
26-
Block(
27-
Constant(true),
28-
Constant(true)
29-
)
30-
),
31-
@"while (true) {
32-
true;
33-
true;
34-
}",
35-
@"Do
36-
True
37-
True
38-
Loop",
39-
@"Loop(
40-
Block(
41-
Constant(true),
42-
Constant(true)
43-
)
44-
)"
45-
);
46-
12+
public void EmptyLoop1() => PreRunTest();
4713
}
4814
}
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
1-
using System.Linq;
2-
using Xunit;
3-
using static System.Linq.Expressions.Expression;
1+
using Xunit;
42
using static ExpressionToString.Tests.Categories;
53

64
namespace ExpressionToString.Tests {
75
public partial class ConstructedBase {
86
[Fact]
97
[Trait("Category",Member)]
10-
public void InstanceMember() => RunTest(
11-
MakeMemberAccess(Constant(""), typeof(string).GetMember("Length").Single()),
12-
"\"\".Length",
13-
"\"\".Length",
14-
@"MakeMemberAccess(
15-
Constant(""""),
16-
typeof(string).GetProperty(""Length"")
17-
)"
18-
);
8+
public void InstanceMember() => PreRunTest();
199

2010
[Fact]
21-
[Trait("Category", MemberBindings)]
22-
public void StaticMember() => RunTest(
23-
MakeMemberAccess(null, typeof(string).GetMember("Empty").Single()),
24-
"string.Empty",
25-
"String.Empty",
26-
@"MakeMemberAccess(null,
27-
typeof(string).GetField(""Empty"")
28-
)"
29-
);
11+
[Trait("Category", Member)]
12+
public void StaticMember() => PreRunTest();
3013
}
3114
}
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
using Xunit;
2-
using static ExpressionToString.Tests.Globals;
3-
using static System.Linq.Expressions.Expression;
42
using static ExpressionToString.Tests.Categories;
53

64
namespace ExpressionToString.Tests {
75
public partial class ConstructedBase {
86
[Fact]
97
[Trait("Category", RuntimeVars)]
10-
public void ConstructRuntimeVariables() => RunTest(
11-
RuntimeVariables(x, s1),
12-
"// variables -- double x, string s1",
13-
"' Variables -- x As Double, s1 As String",
14-
"RuntimeVariables(x, s1)"
15-
);
8+
public void ConstructRuntimeVariables() => PreRunTest();
169

1710
[Fact]
1811
[Trait("Category", RuntimeVars)]
19-
public void RuntimeVariablesWithinBlock() => RunTest(
20-
Block(
21-
new[] { s2 }, //forces an explicit block
22-
Constant(true),
23-
RuntimeVariables(x, s1)
24-
),
25-
@"(
26-
string s2,
27-
true
28-
// variables -- double x, string s1
29-
)",
30-
@"Block
31-
Dim s2 As String
32-
True
33-
' Variables -- x As Double, s1 As String
34-
End Block",
35-
@"Block(new[] { s2 },
36-
Constant(true),
37-
RuntimeVariables(x, s1)
38-
)"
39-
);
12+
public void RuntimeVariablesWithinBlock() => PreRunTest();
4013
}
4114
}

Tests.Common/Objects/FactoryMethods/FactoryMethods.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Linq.Expressions;
7-
using static ExpressionToString.Tests.Functions;
1+
using System.Linq.Expressions;
82
using static ExpressionToString.Tests.Categories;
93
using static System.Linq.Expressions.Expression;
104
using static ExpressionToString.Tests.Globals;
5+
using System.Linq;
116

127
namespace ExpressionToString.Tests.Objects {
138
public static partial class FactoryMethods {
@@ -31,5 +26,41 @@ public static partial class FactoryMethods {
3126

3227
[Category(DebugInfos)]
3328
public static readonly Expression MakeClearDebugInfo = ClearDebugInfo(document);
29+
30+
[Category(Loops)]
31+
public static readonly Expression EmptyLoop = Loop(Constant(true));
32+
33+
[Category(Loops)]
34+
public static readonly Expression EmptyLoop1 = Loop(
35+
Block(
36+
Constant(true),
37+
Constant(true)
38+
)
39+
);
40+
41+
[Category(Member)]
42+
public static readonly Expression InstanceMember = MakeMemberAccess(
43+
Constant(""),
44+
typeof(string).GetMember("Length").Single()
45+
);
46+
47+
[Category(Member)]
48+
public static readonly Expression StaticMember = MakeMemberAccess(null, typeof(string).GetMember("Empty").Single());
49+
50+
[Category(RuntimeVars)]
51+
public static readonly Expression ConstructRuntimeVariables = RuntimeVariables(x, s1);
52+
53+
[Category(RuntimeVars)]
54+
public static readonly Expression RuntimeVariablesWithinBlock = Block(
55+
new[] { s2 }, //forces an explicit block
56+
Constant(true),
57+
RuntimeVariables(x, s1)
58+
);
59+
60+
[Category(Defaults)]
61+
public static readonly Expression MakeDefaultRefType = Default(typeof(string));
62+
63+
[Category(Defaults)]
64+
public static readonly Expression MakeDefaultValueType = Default(typeof(int));
3465
}
3566
}

0 commit comments

Comments
 (0)