Skip to content

Commit f233fae

Browse files
committed
Initial work on #71
1 parent d9aa9b7 commit f233fae

26 files changed

Lines changed: 12581 additions & 71 deletions

Shared/Globals.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public static class FormatterNames {
1212
public const string VisualBasic = "Visual Basic";
1313
public const string FactoryMethods = "Factory methods";
1414
public const string ObjectNotation = "Object notation";
15+
public const string DebugView = "DebugView";
16+
public const string ToStringName = "ToString";
1517
}
1618

1719
public static class Globals {

Shared/Util/Functions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,7 @@ public static object ResolvePath(object o, string path) {
297297
}
298298
return o;
299299
}
300+
301+
public static string NewLines(int count = 2) => Enumerable.Repeat(Environment.NewLine, count).Joined("");
300302
}
301303
}

Tests.Common/CompilerGenerated/Binary.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ namespace ExpressionToString.Tests {
55
public partial class CompilerGeneratedBase {
66
[Fact]
77
[Trait("Category", Binary)]
8-
public void Add() {
9-
double x = 0, y = 0;
10-
RunTest(
11-
() => x + y,
12-
"() => x + y",
13-
"Function() x + y",
14-
@"Lambda(
15-
Add(x, y)
16-
)");
17-
}
8+
public void Add() => PreRunTest();
189

1910
[Fact]
2011
[Trait("Category", Binary)]

Tests.Common/CompilerGenerated/Default.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using Xunit;
22
using static ExpressionToString.Tests.Categories;
3+
using ExpressionToString.Tests.Objects;
34

45
namespace ExpressionToString.Tests {
56
public partial class CompilerGeneratedBase {
67
[Fact]
78
[Trait("Category", Defaults)]
89
public void DefaultRefType() => RunTest(
9-
() => default(string),
10+
CSCompiler.DefaultRefType,
1011
"() => null",
1112
"Function() Nothing",
1213
@"Lambda(
@@ -19,7 +20,7 @@ public void DefaultRefType() => RunTest(
1920
[Fact]
2021
[Trait("Category", Defaults)]
2122
public void DefaultValueType() => RunTest(
22-
() => default(int),
23+
CSCompiler.DefaultValueType,
2324
"() => 0",
2425
"Function() 0",
2526
@"Lambda(

Tests.Common/CompilerGenerated/Indexer.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System.Collections.Generic;
22
using Xunit;
33
using static ExpressionToString.Tests.Categories;
4+
using ExpressionToString.Tests.Objects;
45

56
namespace ExpressionToString.Tests {
67
public partial class CompilerGeneratedBase {
78
[Fact]
89
[Trait("Category",Indexer)]
910
public void ArraySingleIndex() {
10-
var arr = new string[] { };
11+
//var arr = new string[] { };
1112
RunTest(
12-
() => arr[5],
13+
CSCompiler.ArraySingleIndex,
1314
"() => arr[5]",
1415
"Function() arr(5)",
1516
@"Lambda(
@@ -23,9 +24,9 @@ public void ArraySingleIndex() {
2324
[Fact]
2425
[Trait("Category", Indexer)]
2526
public void ArrayMultipleIndex() {
26-
var arr = new string[,] { };
27+
//var arr = new string[,] { };
2728
RunTest(
28-
() => arr[5, 6],
29+
CSCompiler.ArrayMultipleIndex,
2930
"() => arr[5, 6]",
3031
"Function() arr(5, 6)",
3132
@"Lambda(
@@ -40,9 +41,9 @@ public void ArrayMultipleIndex() {
4041
[Fact]
4142
[Trait("Category", Indexer)]
4243
public void TypeIndexer() {
43-
var lst = new List<string>();
44+
//var lst = new List<string>();
4445
RunTest(
45-
() => lst[3],
46+
CSCompiler.TypeIndexer,
4647
"() => lst[3]",
4748
"Function() lst(3)",
4849
@"Lambda(

Tests.Common/CompilerGenerated/Member.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using Xunit;
22
using static ExpressionToString.Tests.Categories;
3+
using ExpressionToString.Tests.Objects;
34

45
namespace ExpressionToString.Tests {
56
public partial class CompilerGeneratedBase {
67
[Fact]
78
[Trait("Category", Member)]
89
public void InstanceMember() {
9-
var s = "";
10+
//var s = "";
1011
RunTest(
11-
() => s.Length,
12+
CSCompiler.InstanceMember,
1213
"() => s.Length",
1314
"Function() s.Length",
1415
@"Lambda(
@@ -22,9 +23,9 @@ public void InstanceMember() {
2223
[Fact]
2324
[Trait("Category", Member)]
2425
public void ClosedVariable() {
25-
var s = "";
26+
//var s = "";
2627
RunTest(
27-
() => s,
28+
CSCompiler.ClosedVariable,
2829
"() => s",
2930
"Function() s",
3031
"Lambda(s)"
@@ -34,7 +35,7 @@ public void ClosedVariable() {
3435
[Fact]
3536
[Trait("Category", Member)]
3637
public void StaticMember() => RunTest(
37-
() => string.Empty,
38+
CSCompiler.StaticMember,
3839
"() => string.Empty",
3940
"Function() String.Empty",
4041
@"Lambda(

Tests.Common/CompilerGenerated/Misc.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using Xunit;
33
using static ExpressionToString.Tests.Categories;
4+
using ExpressionToString.Tests.Objects;
45

56
namespace ExpressionToString.Tests {
67
public partial class CompilerGeneratedBase {
78
[Fact]
89
[Trait("Category", Conditionals)]
910
public void Conditional() => RunTest(
10-
(int i) => i > 10 ? i : i + 10,
11+
CSCompiler.Conditional,
1112
"(int i) => i > 10 ? i : i + 10",
1213
"Function(i As Integer) If(i > 10, i, i + 10)",
1314
@"Lambda(
@@ -29,9 +30,9 @@ public void Conditional() => RunTest(
2930

3031
[Fact]
3132
public void TypeCheck() {
32-
object o = "";
33+
//object o = "";
3334
RunTest(
34-
() => o is string,
35+
CSCompiler.TypeCheck,
3536
"() => o is string",
3637
"Function() TypeOf o Is String",
3738
@"Lambda(
@@ -45,9 +46,9 @@ public void TypeCheck() {
4546
[Fact]
4647
[Trait("Category", Invocation)]
4748
public void InvocationNoArguments() {
48-
Func<int> del = () => DateTime.Now.Day;
49+
//Func<int> del = () => DateTime.Now.Day;
4950
RunTest(
50-
() => del(),
51+
CSCompiler.InvocationNoArguments,
5152
"() => del()",
5253
"Function() del()",
5354
@"Lambda(
@@ -59,9 +60,9 @@ public void InvocationNoArguments() {
5960
[Fact]
6061
[Trait("Category", Invocation)]
6162
public void InvocationOneArgument() {
62-
Func<int, int> del = (int i) => DateTime.Now.Day;
63+
//Func<int, int> del = (int i) => DateTime.Now.Day;
6364
RunTest(
64-
() => del(5),
65+
CSCompiler.InvocationOneArgument,
6566
"() => del(5)",
6667
"Function() del(5)",
6768
@"Lambda(

Tests.Common/FormatterData.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Xunit.Sdk;
8+
9+
namespace Tests.Common {
10+
public class FormatterData : DataAttribute {
11+
private readonly string _fromatter;
12+
13+
public FormatterData(string Formatter) {
14+
_fromatter = Formatter;
15+
}
16+
17+
public override IEnumerable<object[]> GetData(MethodInfo testMethod) {
18+
// resolve path from current dll + formatter name
19+
20+
// parse file
21+
// for each line in File.ReadAllLines(path)
22+
// if line.StartsWith("---") - new test
23+
// (test name embedded in ---- lines)
24+
// add to TheoryData<string, string, string>
25+
// expression name
26+
// formatter name
27+
// result
28+
29+
// return TheoryData
30+
31+
throw new NotImplementedException();
32+
}
33+
}
34+
}
35+
/*
36+
test objects
37+
namespace: ExpressionToString.Tests.Objects
38+
ExpressionToString.Tests.Common
39+
CSCompiler
40+
FactoryMethods
41+
ExpressionToString.Tests.Common.VB
42+
VBCompiler
43+
spread across partial static classes/modules, based on category
44+
decorate with category custom attribute
45+
46+
base abstract class
47+
overridable RunTest
48+
parameters - object to test, object name
49+
protected PreRunTest
50+
parameters - caller member name
51+
resolve object from type of 'this' and member name
52+
calls RunTest with object, object name
53+
54+
three abstract classes, by source
55+
decorate class with source trait
56+
each one spread across multiple files, using partial
57+
each test method
58+
decorate with category trait
59+
corresponds to expression object
60+
calls PreRunTest
61+
62+
formatter tests
63+
static dictionary<string formatter, string objectName), string> with results
64+
for each registered formatter, load from files
65+
inherits three abstract classes
66+
RunTest calls static RunToStringTest, passing in object name and object
67+
68+
get results + pathspans from ToString("Factory methods")
69+
70+
for each formatter
71+
get expected using the formatter and the object name as a multipart key, against the static dictionary
72+
get actual using ToString(formatter) on the object
73+
if formatter == factory methods, use above
74+
Assert.Equals
75+
76+
do pathspans checks against factory methods pathspans
77+
78+
visualizer data tests
79+
inherits three abstract classes
80+
RunTest calls static VisualizerDataTest, passing in object
81+
static method creaates new VisualizerData from object
82+
83+
validation of test methods vs expressions - each expression object must have a corresponding test method
84+
85+
*/

Tests.Common/Functions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Linq.Expressions;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace ExpressionToString.Tests {
11+
public static class Functions {
12+
public static Expression Expr<T>(Expression<Func<T>> expr) => expr;
13+
public static Expression Expr<T, T1>(Expression<Func<T, T1>> expr) => expr;
14+
public static T IIFE<T>(Func<T> fn) => fn();
15+
public static string GetFullFilename(string filename) {
16+
string executable = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
17+
return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(executable), filename));
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)