Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 22, 2024
1 parent 6316136 commit aaab5b4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/ApprovalsTest.cs
@@ -1,7 +1,7 @@
[TestFixture]
public class ApprovalsTest
{
static readonly string[] text = {"abc", "123", "!@#"};
static readonly string[] text = ["abc", "123", "!@#"];

// begin-snippet: simple_verify
[Test]
Expand Down
8 changes: 4 additions & 4 deletions src/ApprovalTests.Tests/LockDownTests.cs
Expand Up @@ -10,21 +10,21 @@ public class LockDownTests
[Test]
public void TestLockDown()
{
int[] n = {1, 2};
int[] n = [1, 2];
CombinationApprovals.VerifyAllCombinations((a, b, c, d, e, f, g, h, i) => Echo(a, b, c, d, e, f, g, h, i), n, n, n, n, n, n, n, n, n);
}

[Test]
public void TestLockDown8()
{
int[] n = {1, 2};
int[] n = [1, 2];
CombinationApprovals.VerifyAllCombinations((a, b, c, d, e, f, g, h) => Echo(a, b, c, d, e, f, g, h), n, n, n, n, n, n, n, n);
}

[Test]
public void TestLockDown2()
{
int[] n = {1, 2};
int[] n = [1, 2];
CombinationApprovals.VerifyAllCombinations((a, b) => Echo(a, b), n, n);
}

Expand All @@ -34,7 +34,7 @@ public void TestExceptions()
{
using (ApprovalResults.UniqueForOs())
{
int[] n = {0, 2};
int[] n = [0, 2];
CombinationApprovals.VerifyAllCombinations((a, b) => a / b, n, n);
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/ApprovalTests/Approvers/FileApprover.cs
Expand Up @@ -4,22 +4,16 @@

namespace ApprovalTests.Approvers;

public class FileApprover : IApprovalApprover
public class FileApprover(IApprovalWriter writer, IApprovalNamer namer, bool normalizeLineEndingsForTextFiles = false)
: IApprovalApprover
{
public readonly IApprovalNamer namer;
public readonly bool normalizeLineEndingsForTextFiles;
public readonly IApprovalWriter writer;
public readonly IApprovalNamer namer = namer;
public readonly bool normalizeLineEndingsForTextFiles = normalizeLineEndingsForTextFiles;
public readonly IApprovalWriter writer = writer;
public string approved;
public ApprovalException failure;
public string received;

public FileApprover(IApprovalWriter writer, IApprovalNamer namer, bool normalizeLineEndingsForTextFiles = false)
{
this.writer = writer;
this.namer = namer;
this.normalizeLineEndingsForTextFiles = normalizeLineEndingsForTextFiles;
}

public virtual bool Approve()
{
var basename = Path.Combine(namer.SourcePath, namer.Name);
Expand All @@ -38,7 +32,7 @@ public virtual ApprovalException Approve(string approvedPath, string receivedPat
return new ApprovalMissingException(receivedPath, approvedPath);
}

if (normalizeLineEndingsForTextFiles && FileExtensions.IsText(approvedPath))
if (normalizeLineEndingsForTextFiles && FileExtensions.IsTextFile(approvedPath))
{
var receivedText = File.ReadAllText(receivedPath).Replace("\r\n", "\n");
var approvedText = File.ReadAllText(approvedPath).Replace("\r\n", "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests/Combinations/CombinationApprovals.cs
Expand Up @@ -5,7 +5,7 @@ namespace ApprovalTests.Combinations;

public static class CombinationApprovals
{
static readonly object[] EMPTY = {null};
static readonly object[] EMPTY = [null];

public static void VerifyAllCombinations<A>(Func<A, object> processCall, IEnumerable<A> aList) =>
VerifyAllCombinations((a, _, _, _, _, _, _, _, _) =>
Expand Down
4 changes: 2 additions & 2 deletions src/ApprovalTests/ExceptionalExceptions/Exceptional.cs
Expand Up @@ -14,8 +14,8 @@ public static T Create<T>(Exception causedBy, string formattableMessage, params
Func<string, Exception, T> reflectiveConstructor = (m, e) =>
{
var type = typeof(T);
var constructorInfo = type.GetConstructor(new[] {typeof(string), typeof(Exception)});
var instance = (T) constructorInfo.Invoke(new object[] {m, e});
var constructorInfo = type.GetConstructor([typeof(string), typeof(Exception)]);
var instance = (T) constructorInfo.Invoke([m, e]);
return instance;
};
return Create(reflectiveConstructor, causedBy, formattableMessage, messageParameters);
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests/Namers/ApprovalResults.cs
Expand Up @@ -82,7 +82,7 @@ public static string GetFullOsName()

public static string TransformEasyOsName(string captionName)
{
string[] known = {"XP", "2000", "Vista", "7", "8", "Server 2003", "Server 2008", "Server 2012"};
string[] known = ["XP", "2000", "Vista", "7", "8", "Server 2003", "Server 2008", "Server 2012"];
var matched = known.FirstOrDefault(s => captionName.StartsWith("Microsoft Windows " + s));
if (matched != null)
{
Expand Down
8 changes: 7 additions & 1 deletion src/ApprovalTests/Reporters/ExecutableQueryFailure.cs
Expand Up @@ -7,7 +7,13 @@ public class ExecutableQueryFailure(IExecutableQuery query, IApprovalFailureRepo
IApprovalFailureReporter, IApprovalReporterWithCleanUp
{
const string FileNameSuffix = ".queryresults.txt";
const string Header = "\t\tDo NOT approve\n\t\tThis File will be Deleted\n\t\tit is for feedback purposes only.\n\t\tAn additional file has been opened with only the query which you can approve.\n";
const string Header = """
Do NOT approve
This File will be Deleted
it is for feedback purposes only.
An additional file has been opened with only the query which you can approve.

""";

public void CleanUp(string approved, string received)
{
Expand Down

0 comments on commit aaab5b4

Please sign in to comment.