Skip to content

Commit dadd054

Browse files
committed
test: use more readable newlines and fields with varied lengths
1 parent 07ad3a9 commit dadd054

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

tests/Diffract.CSharp.Tests/CustomDiffers.cs

+31-16
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,66 @@ public class CustomDiffers
99
[Fact]
1010
public void NoCustomDiffer()
1111
{
12-
var expectedDiff = "D.X Expect = \"a\"\n Actual = \"b\"\n";
12+
var expectedDiff = @"DDDDD.XXX Expect = ""a""
13+
Actual = ""b""
14+
";
1315
var expected = new Container(new CustomDiffable("a"));
1416
var actual = new Container(new CustomDiffable("b"));
1517
var actualDiff = Differ.ToString(expected, actual);
16-
Assert.Equal(expectedDiff, actualDiff);
18+
AssertStr(expectedDiff, actualDiff);
1719
}
1820

1921
[Fact]
2022
public void CustomDiffer()
2123
{
22-
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
24+
var expectedDiff = @"DDDDD Expect = ""a""
25+
Actual = ""b""
26+
";
2327
var expected = new Container(new CustomDiffable("a"));
2428
var actual = new Container(new CustomDiffable("b"));
2529
var actualDiff = MyDiffer.Get<Container>().ToString(expected, actual);
26-
Assert.Equal(expectedDiff, actualDiff);
30+
AssertStr(expectedDiff, actualDiff);
2731
}
2832

2933
[Fact]
3034
public void CustomDifferWithCombinators()
3135
{
32-
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
36+
var expectedDiff = @"DDDDD Expect = ""a""
37+
Actual = ""b""
38+
";
3339
var expected = new Container(new CustomDiffable("a"));
3440
var actual = new Container(new CustomDiffable("b"));
3541
var actualDiff = MyDifferWithCombinators.Get<Container>().ToString(expected, actual);
36-
Assert.Equal(expectedDiff, actualDiff);
42+
AssertStr(expectedDiff, actualDiff);
3743
}
3844

3945
[Fact]
4046
public void CustomDifferWithMap()
4147
{
42-
var expectedDiff = "D Expect = \"a\"\n Actual = \"b\"\n";
48+
var expectedDiff = @"DDDDD Expect = ""a""
49+
Actual = ""b""
50+
";
4351
var expected = new Container(new CustomDiffable("a"));
4452
var actual = new Container(new CustomDiffable("b"));
4553
var actualDiff = MyDifferWithMap.Get<Container>().ToString(expected, actual);
46-
Assert.Equal(expectedDiff, actualDiff);
54+
AssertStr(expectedDiff, actualDiff);
4755
}
4856

4957
[Fact]
5058
public void CustomDifferWithMapToAnonymousObject()
5159
{
52-
var expectedDiff = "D.v Expect = \"a\"\n Actual = \"b\"\n";
60+
var expectedDiff = @"DDDDD.v Expect = ""a""
61+
Actual = ""b""
62+
";
5363
var expected = new Container(new CustomDiffable("a"));
5464
var actual = new Container(new CustomDiffable("b"));
5565
var actualDiff = MyDifferWithMapToAnonymousObject.Get<Container>().ToString(expected, actual);
56-
Assert.Equal(expectedDiff, actualDiff);
66+
AssertStr(expectedDiff, actualDiff);
5767
}
5868

59-
public record CustomDiffable(string X);
69+
public record CustomDiffable(string XXX);
6070

61-
public record Container(CustomDiffable D);
71+
public record Container(CustomDiffable DDDDD);
6272

6373
public class MyDiffer : IDiffer<CustomDiffable>
6474
{
@@ -70,7 +80,7 @@ public MyDiffer(IDifferFactory differFactory)
7080
}
7181

7282
public FSharpOption<Diff> Diff(CustomDiffable x1, CustomDiffable x2) =>
73-
_stringDiffer.Diff(x1.X, x2.X);
83+
_stringDiffer.Diff(x1.XXX, x2.XXX);
7484

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

@@ -101,7 +111,7 @@ private static class Singleton<T>
101111
CustomDiffer<CustomDiffable>.Build(factory =>
102112
{
103113
var stringDiffer = factory.GetDiffer<string>();
104-
return (x1, x2) => stringDiffer.Diff(x1.X, x2.X);
114+
return (x1, x2) => stringDiffer.Diff(x1.XXX, x2.XXX);
105115
});
106116
}
107117

@@ -115,7 +125,7 @@ private static class Singleton<T>
115125
}
116126

117127
private static readonly ICustomDiffer CustomDiffer =
118-
CustomDiffer<CustomDiffable>.Map(x => x.X);
128+
CustomDiffer<CustomDiffable>.Map(x => x.XXX);
119129
}
120130

121131
public static class MyDifferWithMapToAnonymousObject
@@ -128,7 +138,12 @@ private static class Singleton<T>
128138
}
129139

130140
private static readonly ICustomDiffer CustomDiffer =
131-
CustomDiffer<CustomDiffable>.Map(x => new { v = x.X });
141+
CustomDiffer<CustomDiffable>.Map(x => new { v = x.XXX });
142+
}
143+
144+
private void AssertStr(string expected, string actual)
145+
{
146+
Assert.Equal(expected.Replace("\r\n", "\n"), actual);
132147
}
133148
}
134149
}

0 commit comments

Comments
 (0)