Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 28, 2023
1 parent 0ebf92a commit 987fc2b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 97 deletions.
18 changes: 5 additions & 13 deletions src/Verify/FilePair.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
namespace VerifyTests;

public readonly struct FilePair
public readonly struct FilePair(string extension, string receivedPath, string verifiedPath)
{
public string Extension { get; }
public string ReceivedPath { get; }
public string VerifiedPath { get; }
public bool IsText { get; }

public FilePair(string extension, string receivedPath, string verifiedPath)
{
Extension = extension;
ReceivedPath = receivedPath;
VerifiedPath = verifiedPath;
IsText = FileExtensions.IsText(extension);
}
public string Extension { get; } = extension;
public string ReceivedPath { get; } = receivedPath;
public string VerifiedPath { get; } = verifiedPath;
public bool IsText { get; } = FileExtensions.IsText(extension);
}
12 changes: 3 additions & 9 deletions src/Verify/Naming/FrameworkNameVersion.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
class FrameworkNameVersion
class FrameworkNameVersion(string name, string nameAndVersion)
{
public string Name { get; }
public string NameAndVersion { get; }

public FrameworkNameVersion(string name, string nameAndVersion)
{
Name = name;
NameAndVersion = nameAndVersion;
}
public string Name { get; } = name;
public string NameAndVersion { get; } = nameAndVersion;
}
12 changes: 3 additions & 9 deletions src/Verify/Serialization/AsStringResult.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
namespace VerifyTests;

public readonly struct AsStringResult
public readonly struct AsStringResult(string value, string? extension = null)
{
public string Value { get; }
public string? Extension { get; }

public AsStringResult(string value, string? extension = null)
{
Value = value;
Extension = extension;
}
public string Value { get; } = value;
public string? Extension { get; } = extension;

public static implicit operator AsStringResult(string value) =>
new(value);
Expand Down
37 changes: 12 additions & 25 deletions src/Verify/Serialization/CustomValueProvider.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
class CustomValueProvider :
class CustomValueProvider(IValueProvider inner,
Type type,
Func<Exception, bool> ignoreException,
ConvertTargetMember? converter,
SerializationSettings settings) :
IValueProvider
{
IValueProvider inner;
Type memberType;
Func<Exception, bool> shouldIgnoreException;
ConvertTargetMember? membersConverter;
SerializationSettings settings;

public CustomValueProvider(IValueProvider inner,
Type memberType,
Func<Exception, bool> shouldIgnoreException,
ConvertTargetMember? membersConverter,
SerializationSettings settings)
{
this.inner = inner;
this.memberType = memberType;
this.shouldIgnoreException = shouldIgnoreException;
this.membersConverter = membersConverter;
this.settings = settings;
}

public void SetValue(object target, object? value) =>
throw new NotImplementedException();

public object? GetValue(object target)
{
if (membersConverter is not null)
if (converter is not null)
{
var value = inner.GetValue(target);
return membersConverter(target, value);
return converter(target, value);
}

try
Expand All @@ -41,11 +26,13 @@ public void SetValue(object target, object? value) =>
{
return null;
}

if (scrubOrIgnore == ScrubOrIgnore.Scrub)
{
return "{Scrubbed}";
}
}

return value;
}
catch (Exception exception)
Expand All @@ -56,7 +43,7 @@ public void SetValue(object target, object? value) =>
throw;
}

if (shouldIgnoreException(innerException))
if (ignoreException(innerException))
{
return GetDefault();
}
Expand All @@ -67,9 +54,9 @@ public void SetValue(object target, object? value) =>

object? GetDefault()
{
if (memberType.IsValueType)
if (type.IsValueType)
{
return Activator.CreateInstance(memberType);
return Activator.CreateInstance(type);
}

return null;
Expand Down
7 changes: 1 addition & 6 deletions src/Verify/Serialization/TypeNameProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
class TypeNameProvider :
class TypeNameProvider(Type type) :
IValueProvider
{
Type type;

public TypeNameProvider(Type type) =>
this.type = type;

public void SetValue(object target, object? value) =>
throw new NotImplementedException();

Expand Down
18 changes: 5 additions & 13 deletions src/Verify/Verifier/EqualityResult.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
readonly struct EqualityResult
readonly struct EqualityResult(Equality equality, string? message, StringBuilder? receivedText, StringBuilder? verifiedText)
{
public Equality Equality { get; }
public string? Message { get; }
public StringBuilder? ReceivedText { get; }
public StringBuilder? VerifiedText { get; }

public EqualityResult(Equality equality, string? message, StringBuilder? receivedText, StringBuilder? verifiedText)
{
Equality = equality;
Message = message;
ReceivedText = receivedText;
VerifiedText = verifiedText;
}
public Equality Equality { get; } = equality;
public string? Message { get; } = message;
public StringBuilder? ReceivedText { get; } = receivedText;
public StringBuilder? VerifiedText { get; } = verifiedText;
}
12 changes: 3 additions & 9 deletions src/Verify/Verifier/NewResult.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
readonly struct NewResult
readonly struct NewResult(FilePair file, StringBuilder? receivedText)
{
public FilePair File { get; }
public StringBuilder? ReceivedText { get; }

public NewResult(FilePair file, StringBuilder? receivedText)
{
File = file;
ReceivedText = receivedText;
}
public FilePair File { get; } = file;
public StringBuilder? ReceivedText { get; } = receivedText;
}
18 changes: 5 additions & 13 deletions src/Verify/Verifier/NotEqualResult.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
readonly struct NotEqualResult
readonly struct NotEqualResult(FilePair file, string? message, StringBuilder? receivedText, StringBuilder? verifiedText)
{
public FilePair File { get; }
public string? Message { get; }
public StringBuilder? ReceivedText { get; }
public StringBuilder? VerifiedText { get; }

public NotEqualResult(FilePair file, string? message, StringBuilder? receivedText, StringBuilder? verifiedText)
{
File = file;
Message = message;
ReceivedText = receivedText;
VerifiedText = verifiedText;
}
public FilePair File { get; } = file;
public string? Message { get; } = message;
public StringBuilder? ReceivedText { get; } = receivedText;
public StringBuilder? VerifiedText { get; } = verifiedText;
}

0 comments on commit 987fc2b

Please sign in to comment.