Skip to content

Commit

Permalink
add half support
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 23, 2020
1 parent fbd985a commit 7ca58c7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ The default mapping is:
{typeof(long), (target, settings) => ((long) target).ToString()},
{typeof(ulong), (target, settings) => ((ulong) target).ToString()},
{typeof(decimal), (target, settings) => ((decimal) target).ToString(CultureInfo.InvariantCulture)},
#if NET5_0
{typeof(Half), (target, settings) => ((Half) target).ToString(CultureInfo.InvariantCulture)},
#endif
{typeof(float), (target, settings) => ((float) target).ToString(CultureInfo.InvariantCulture)},
{typeof(double), (target, settings) => ((double) target).ToString(CultureInfo.InvariantCulture)},
{typeof(Guid), (target, settings) => ((Guid) target).ToString()},
Expand Down Expand Up @@ -751,7 +754,7 @@ The default mapping is:
}
}
```
<sup><a href='/src/Verify/Serialization/VerifierSettings.cs#L23-L69' title='File snippet `typetostringmapping` was extracted from'>snippet source</a> | <a href='#snippet-typetostringmapping' title='Navigate to start of snippet `typetostringmapping`'>anchor</a></sup>
<sup><a href='/src/Verify/Serialization/VerifierSettings.cs#L23-L72' title='File snippet `typetostringmapping` was extracted from'>snippet source</a> | <a href='#snippet-typetostringmapping' title='Navigate to start of snippet `typetostringmapping`'>anchor</a></sup>
<!-- endSnippet -->

This bypasses the Guid and DateTime scrubbing mentioned above.
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026</NoWarn>
<Version>6.18.0</Version>
<Version>6.19.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Json, Testing, Verify, Snapshot, Approvals</PackageTags>
<Description>Enables verification of complex models and documents.</Description>
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions src/Verify.Tests/SimpleTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public Task DateTimeWrappedInTask()
{
return Verifier.Verify(Task.FromResult(new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc)));
}

[Fact]
public Task Half()
{
return Verifier.Verify((Half)10);
}
#endif

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions src/Verify/Serialization/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static bool TryGetToString<T>(T target, out Func<object, VerifySettings,
{typeof(long), (target, settings) => ((long) target).ToString()},
{typeof(ulong), (target, settings) => ((ulong) target).ToString()},
{typeof(decimal), (target, settings) => ((decimal) target).ToString(CultureInfo.InvariantCulture)},
#if NET5_0
{typeof(Half), (target, settings) => ((Half) target).ToString(CultureInfo.InvariantCulture)},
#endif
{typeof(float), (target, settings) => ((float) target).ToString(CultureInfo.InvariantCulture)},
{typeof(double), (target, settings) => ((double) target).ToString(CultureInfo.InvariantCulture)},
{typeof(Guid), (target, settings) => ((Guid) target).ToString()},
Expand Down
2 changes: 1 addition & 1 deletion src/Verify/Verifier/InnerVerifier_Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task Verify<T>(T target, VerifySettings settings)
}

var appenders = VerifierSettings.GetJsonAppenders(settings);

await SerializeAndVerify(target, settings, appenders);
}

Expand Down

0 comments on commit 7ca58c7

Please sign in to comment.