Skip to content

Commit

Permalink
Initial work on #71
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Aug 1, 2019
1 parent d9aa9b7 commit f233fae
Show file tree
Hide file tree
Showing 26 changed files with 12,581 additions and 71 deletions.
2 changes: 2 additions & 0 deletions Shared/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static class FormatterNames {
public const string VisualBasic = "Visual Basic";
public const string FactoryMethods = "Factory methods";
public const string ObjectNotation = "Object notation";
public const string DebugView = "DebugView";
public const string ToStringName = "ToString";
}

public static class Globals {
Expand Down
2 changes: 2 additions & 0 deletions Shared/Util/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,7 @@ public static object ResolvePath(object o, string path) {
}
return o;
}

public static string NewLines(int count = 2) => Enumerable.Repeat(Environment.NewLine, count).Joined("");
}
}
11 changes: 1 addition & 10 deletions Tests.Common/CompilerGenerated/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ namespace ExpressionToString.Tests {
public partial class CompilerGeneratedBase {
[Fact]
[Trait("Category", Binary)]
public void Add() {
double x = 0, y = 0;
RunTest(
() => x + y,
"() => x + y",
"Function() x + y",
@"Lambda(
Add(x, y)
)");
}
public void Add() => PreRunTest();

[Fact]
[Trait("Category", Binary)]
Expand Down
5 changes: 3 additions & 2 deletions Tests.Common/CompilerGenerated/Default.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Xunit;
using static ExpressionToString.Tests.Categories;
using ExpressionToString.Tests.Objects;

namespace ExpressionToString.Tests {
public partial class CompilerGeneratedBase {
[Fact]
[Trait("Category", Defaults)]
public void DefaultRefType() => RunTest(
() => default(string),
CSCompiler.DefaultRefType,
"() => null",
"Function() Nothing",
@"Lambda(
Expand All @@ -19,7 +20,7 @@ public void DefaultRefType() => RunTest(
[Fact]
[Trait("Category", Defaults)]
public void DefaultValueType() => RunTest(
() => default(int),
CSCompiler.DefaultValueType,
"() => 0",
"Function() 0",
@"Lambda(
Expand Down
13 changes: 7 additions & 6 deletions Tests.Common/CompilerGenerated/Indexer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Collections.Generic;
using Xunit;
using static ExpressionToString.Tests.Categories;
using ExpressionToString.Tests.Objects;

namespace ExpressionToString.Tests {
public partial class CompilerGeneratedBase {
[Fact]
[Trait("Category",Indexer)]
public void ArraySingleIndex() {
var arr = new string[] { };
//var arr = new string[] { };
RunTest(
() => arr[5],
CSCompiler.ArraySingleIndex,
"() => arr[5]",
"Function() arr(5)",
@"Lambda(
Expand All @@ -23,9 +24,9 @@ public void ArraySingleIndex() {
[Fact]
[Trait("Category", Indexer)]
public void ArrayMultipleIndex() {
var arr = new string[,] { };
//var arr = new string[,] { };
RunTest(
() => arr[5, 6],
CSCompiler.ArrayMultipleIndex,
"() => arr[5, 6]",
"Function() arr(5, 6)",
@"Lambda(
Expand All @@ -40,9 +41,9 @@ public void ArrayMultipleIndex() {
[Fact]
[Trait("Category", Indexer)]
public void TypeIndexer() {
var lst = new List<string>();
//var lst = new List<string>();
RunTest(
() => lst[3],
CSCompiler.TypeIndexer,
"() => lst[3]",
"Function() lst(3)",
@"Lambda(
Expand Down
11 changes: 6 additions & 5 deletions Tests.Common/CompilerGenerated/Member.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Xunit;
using static ExpressionToString.Tests.Categories;
using ExpressionToString.Tests.Objects;

namespace ExpressionToString.Tests {
public partial class CompilerGeneratedBase {
[Fact]
[Trait("Category", Member)]
public void InstanceMember() {
var s = "";
//var s = "";
RunTest(
() => s.Length,
CSCompiler.InstanceMember,
"() => s.Length",
"Function() s.Length",
@"Lambda(
Expand All @@ -22,9 +23,9 @@ public void InstanceMember() {
[Fact]
[Trait("Category", Member)]
public void ClosedVariable() {
var s = "";
//var s = "";
RunTest(
() => s,
CSCompiler.ClosedVariable,
"() => s",
"Function() s",
"Lambda(s)"
Expand All @@ -34,7 +35,7 @@ public void ClosedVariable() {
[Fact]
[Trait("Category", Member)]
public void StaticMember() => RunTest(
() => string.Empty,
CSCompiler.StaticMember,
"() => string.Empty",
"Function() String.Empty",
@"Lambda(
Expand Down
15 changes: 8 additions & 7 deletions Tests.Common/CompilerGenerated/Misc.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using Xunit;
using static ExpressionToString.Tests.Categories;
using ExpressionToString.Tests.Objects;

namespace ExpressionToString.Tests {
public partial class CompilerGeneratedBase {
[Fact]
[Trait("Category", Conditionals)]
public void Conditional() => RunTest(
(int i) => i > 10 ? i : i + 10,
CSCompiler.Conditional,
"(int i) => i > 10 ? i : i + 10",
"Function(i As Integer) If(i > 10, i, i + 10)",
@"Lambda(
Expand All @@ -29,9 +30,9 @@ public void Conditional() => RunTest(

[Fact]
public void TypeCheck() {
object o = "";
//object o = "";
RunTest(
() => o is string,
CSCompiler.TypeCheck,
"() => o is string",
"Function() TypeOf o Is String",
@"Lambda(
Expand All @@ -45,9 +46,9 @@ public void TypeCheck() {
[Fact]
[Trait("Category", Invocation)]
public void InvocationNoArguments() {
Func<int> del = () => DateTime.Now.Day;
//Func<int> del = () => DateTime.Now.Day;
RunTest(
() => del(),
CSCompiler.InvocationNoArguments,
"() => del()",
"Function() del()",
@"Lambda(
Expand All @@ -59,9 +60,9 @@ public void InvocationNoArguments() {
[Fact]
[Trait("Category", Invocation)]
public void InvocationOneArgument() {
Func<int, int> del = (int i) => DateTime.Now.Day;
//Func<int, int> del = (int i) => DateTime.Now.Day;
RunTest(
() => del(5),
CSCompiler.InvocationOneArgument,
"() => del(5)",
"Function() del(5)",
@"Lambda(
Expand Down
85 changes: 85 additions & 0 deletions Tests.Common/FormatterData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xunit.Sdk;

namespace Tests.Common {
public class FormatterData : DataAttribute {
private readonly string _fromatter;

public FormatterData(string Formatter) {
_fromatter = Formatter;
}

public override IEnumerable<object[]> GetData(MethodInfo testMethod) {
// resolve path from current dll + formatter name

// parse file
// for each line in File.ReadAllLines(path)
// if line.StartsWith("---") - new test
// (test name embedded in ---- lines)
// add to TheoryData<string, string, string>
// expression name
// formatter name
// result

// return TheoryData

throw new NotImplementedException();
}
}
}
/*
test objects
namespace: ExpressionToString.Tests.Objects
ExpressionToString.Tests.Common
CSCompiler
FactoryMethods
ExpressionToString.Tests.Common.VB
VBCompiler
spread across partial static classes/modules, based on category
decorate with category custom attribute
base abstract class
overridable RunTest
parameters - object to test, object name
protected PreRunTest
parameters - caller member name
resolve object from type of 'this' and member name
calls RunTest with object, object name
three abstract classes, by source
decorate class with source trait
each one spread across multiple files, using partial
each test method
decorate with category trait
corresponds to expression object
calls PreRunTest
formatter tests
static dictionary<string formatter, string objectName), string> with results
for each registered formatter, load from files
inherits three abstract classes
RunTest calls static RunToStringTest, passing in object name and object
get results + pathspans from ToString("Factory methods")
for each formatter
get expected using the formatter and the object name as a multipart key, against the static dictionary
get actual using ToString(formatter) on the object
if formatter == factory methods, use above
Assert.Equals
do pathspans checks against factory methods pathspans
visualizer data tests
inherits three abstract classes
RunTest calls static VisualizerDataTest, passing in object
static method creaates new VisualizerData from object
validation of test methods vs expressions - each expression object must have a corresponding test method
*/
20 changes: 20 additions & 0 deletions Tests.Common/Functions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionToString.Tests {
public static class Functions {
public static Expression Expr<T>(Expression<Func<T>> expr) => expr;
public static Expression Expr<T, T1>(Expression<Func<T, T1>> expr) => expr;
public static T IIFE<T>(Func<T> fn) => fn();
public static string GetFullFilename(string filename) {
string executable = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(executable), filename));
}
}
}
Loading

0 comments on commit f233fae

Please sign in to comment.