Skip to content

Commit

Permalink
test: use more readable newlines and fields with varied lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Apr 13, 2024
1 parent 07ad3a9 commit dadd054
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions tests/Diffract.CSharp.Tests/CustomDiffers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,66 @@ public class CustomDiffers
[Fact]
public void NoCustomDiffer()
{
var expectedDiff = "D.X Expect = \"a\"\n Actual = \"b\"\n";
var expectedDiff = @"DDDDD.XXX Expect = ""a""
Actual = ""b""
";
var expected = new Container(new CustomDiffable("a"));
var actual = new Container(new CustomDiffable("b"));
var actualDiff = Differ.ToString(expected, actual);
Assert.Equal(expectedDiff, actualDiff);
AssertStr(expectedDiff, actualDiff);
}

[Fact]
public void CustomDiffer()
{
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
var expectedDiff = @"DDDDD Expect = ""a""
Actual = ""b""
";
var expected = new Container(new CustomDiffable("a"));
var actual = new Container(new CustomDiffable("b"));
var actualDiff = MyDiffer.Get<Container>().ToString(expected, actual);
Assert.Equal(expectedDiff, actualDiff);
AssertStr(expectedDiff, actualDiff);
}

[Fact]
public void CustomDifferWithCombinators()
{
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
var expectedDiff = @"DDDDD Expect = ""a""
Actual = ""b""
";
var expected = new Container(new CustomDiffable("a"));
var actual = new Container(new CustomDiffable("b"));
var actualDiff = MyDifferWithCombinators.Get<Container>().ToString(expected, actual);
Assert.Equal(expectedDiff, actualDiff);
AssertStr(expectedDiff, actualDiff);
}

[Fact]
public void CustomDifferWithMap()
{
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
var expectedDiff = @"DDDDD Expect = ""a""
Actual = ""b""
";
var expected = new Container(new CustomDiffable("a"));
var actual = new Container(new CustomDiffable("b"));
var actualDiff = MyDifferWithMap.Get<Container>().ToString(expected, actual);
Assert.Equal(expectedDiff, actualDiff);
AssertStr(expectedDiff, actualDiff);
}

[Fact]
public void CustomDifferWithMapToAnonymousObject()
{
var expectedDiff = "D.v Expect = \"a\"\n Actual = \"b\"\n";
var expectedDiff = @"DDDDD.v Expect = ""a""
Actual = ""b""
";
var expected = new Container(new CustomDiffable("a"));
var actual = new Container(new CustomDiffable("b"));
var actualDiff = MyDifferWithMapToAnonymousObject.Get<Container>().ToString(expected, actual);
Assert.Equal(expectedDiff, actualDiff);
AssertStr(expectedDiff, actualDiff);
}

public record CustomDiffable(string X);
public record CustomDiffable(string XXX);

public record Container(CustomDiffable D);
public record Container(CustomDiffable DDDDD);

public class MyDiffer : IDiffer<CustomDiffable>
{
Expand All @@ -70,7 +80,7 @@ public MyDiffer(IDifferFactory differFactory)
}

public FSharpOption<Diff> Diff(CustomDiffable x1, CustomDiffable x2) =>
_stringDiffer.Diff(x1.X, x2.X);
_stringDiffer.Diff(x1.XXX, x2.XXX);

public static IDiffer<T> Get<T>() => Singleton<T>.Instance;

Expand Down Expand Up @@ -101,7 +111,7 @@ private static class Singleton<T>
CustomDiffer<CustomDiffable>.Build(factory =>
{
var stringDiffer = factory.GetDiffer<string>();
return (x1, x2) => stringDiffer.Diff(x1.X, x2.X);
return (x1, x2) => stringDiffer.Diff(x1.XXX, x2.XXX);
});
}

Expand All @@ -115,7 +125,7 @@ private static class Singleton<T>
}

private static readonly ICustomDiffer CustomDiffer =
CustomDiffer<CustomDiffable>.Map(x => x.X);
CustomDiffer<CustomDiffable>.Map(x => x.XXX);
}

public static class MyDifferWithMapToAnonymousObject
Expand All @@ -128,7 +138,12 @@ private static class Singleton<T>
}

private static readonly ICustomDiffer CustomDiffer =
CustomDiffer<CustomDiffable>.Map(x => new { v = x.X });
CustomDiffer<CustomDiffable>.Map(x => new { v = x.XXX });
}

private void AssertStr(string expected, string actual)
{
Assert.Equal(expected.Replace("\r\n", "\n"), actual);
}
}
}

0 comments on commit dadd054

Please sign in to comment.