This commit is contained in:
Simon Cropp 2024-09-15 20:14:27 +10:00
Родитель 37bf73d0a1
Коммит b88f8e254d
17 изменённых файлов: 88 добавлений и 104 удалений

Просмотреть файл

@ -42,7 +42,7 @@ public Task ScrubbingExample()
return Verify(target);
}
```
<sup><a href='/src/Tests/Tests.cs#L25-L38' title='Snippet source file'>snippet source</a> | <a href='#snippet-Example' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L23-L36' title='Snippet source file'>snippet source</a> | <a href='#snippet-Example' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
Resulting in:
@ -74,7 +74,7 @@ public Task DisableExample()
.DontScrubNodaTimes();
}
```
<sup><a href='/src/Tests/Tests.cs#L40-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-Disable' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L38-L52' title='Snippet source file'>snippet source</a> | <a href='#snippet-Disable' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
Resulting in:

Просмотреть файл

@ -309,4 +309,14 @@ resharper_space_before_self_closing = true
ij_xml_space_inside_empty_tag = true
[*.json]
indent_size = 2
indent_size = 2
# Verify settings
[*.{received,verified}.{txt,xml,json,md,sql,csv,html}]
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false

Просмотреть файл

@ -8,7 +8,7 @@
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="27.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NodaTime" Version="3.1.12" />
<PackageVersion Include="Polyfill" Version="6.6.3" />
<PackageVersion Include="Polyfill" Version="6.8.0" />
<PackageVersion Include="ProjectDefaults" Version="1.0.135" />
<PackageVersion Include="Verify" Version="26.4.5" />
<PackageVersion Include="Verify.DiffPlex" Version="3.1.0" />
@ -16,4 +16,4 @@
<PackageVersion Include="xunit.v3" Version="0.3.0-pre.18" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0-pre.30" />
</ItemGroup>
</Project>
</Project>

Просмотреть файл

@ -0,0 +1,3 @@
// Global using directives
global using NodaTime;

Просмотреть файл

@ -1,6 +1,4 @@
using NodaTime;
public class Tests
public class Tests
{
[Fact]
public Task DontScrub() =>

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class AnnualDateConverter :
class AnnualDateConverter :
WriteOnlyJsonConverter<AnnualDate>
{
public override void Write(VerifyJsonWriter writer, AnnualDate value)

Просмотреть файл

@ -1,9 +1,5 @@
namespace VerifyTests.Converters;
using Argon.NodaTime;
using NodaTime;
public class DateIntervalConverter : WriteOnlyJsonConverter<DateInterval>
public class DateIntervalConverter :
WriteOnlyJsonConverter<DateInterval>
{
public override void Write(VerifyJsonWriter writer, DateInterval value)
{

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class InstantConverter :
class InstantConverter :
WriteOnlyJsonConverter<Instant>
{
public override void Write(VerifyJsonWriter writer, Instant value)

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class LocalDateConverter :
class LocalDateConverter :
WriteOnlyJsonConverter<LocalDate>
{
public override void Write(VerifyJsonWriter writer, LocalDate value)

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class LocalDateTimeConverter :
class LocalDateTimeConverter :
WriteOnlyJsonConverter<LocalDateTime>
{
public override void Write(VerifyJsonWriter writer, LocalDateTime value)

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class OffsetDateConverter :
class OffsetDateConverter :
WriteOnlyJsonConverter<OffsetDate>
{
public override void Write(VerifyJsonWriter writer, OffsetDate value)

Просмотреть файл

@ -1,7 +1,4 @@
using NodaTime;
using Argon.NodaTime;
class OffsetDateTimeConverter :
class OffsetDateTimeConverter :
WriteOnlyJsonConverter<OffsetDateTime>
{
public override void Write(VerifyJsonWriter writer, OffsetDateTime value)

Просмотреть файл

@ -1,6 +1,4 @@
using NodaTime;
class YearMonthConverter :
class YearMonthConverter :
WriteOnlyJsonConverter<YearMonth>
{
public override void Write(VerifyJsonWriter writer, YearMonth value)

Просмотреть файл

@ -1,8 +1,4 @@
using Argon;
using NodaTime;
using Argon.NodaTime;
class ZonedDateTimeConverter :
class ZonedDateTimeConverter :
WriteOnlyJsonConverter<ZonedDateTime>
{
JsonConverter zonedDateTimeConverter = NodaConverters.CreateZonedDateTimeConverter(DateTimeZoneProviders.Tzdb);

Просмотреть файл

@ -1,77 +1,75 @@
 using NodaTime;
 class CounterContext
{
static AsyncLocal<CounterContext?> local = new();
class CounterContext
{
static AsyncLocal<CounterContext?> local = new();
ConcurrentDictionary<YearMonth, int> yearMonthCache = [];
int currentYearMonth;
ConcurrentDictionary<YearMonth, int> yearMonthCache = [];
int currentYearMonth;
public int Next(YearMonth input) =>
yearMonthCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentYearMonth));
public int Next(YearMonth input) =>
yearMonthCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentYearMonth));
ConcurrentDictionary<ZonedDateTime, int> zonedDateTimeCache = [];
int currentZonedDateTime;
ConcurrentDictionary<ZonedDateTime, int> zonedDateTimeCache = [];
int currentZonedDateTime;
public int Next(ZonedDateTime input) =>
zonedDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentZonedDateTime));
public int Next(ZonedDateTime input) =>
zonedDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentZonedDateTime));
ConcurrentDictionary<OffsetDateTime, int> offsetDateTimeCache = [];
int currentOffsetDateTime;
ConcurrentDictionary<OffsetDateTime, int> offsetDateTimeCache = [];
int currentOffsetDateTime;
public int Next(OffsetDateTime input) =>
offsetDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentOffsetDateTime));
public int Next(OffsetDateTime input) =>
offsetDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentOffsetDateTime));
ConcurrentDictionary<OffsetDate, int> offsetDateCache = [];
int currentOffsetDate;
ConcurrentDictionary<OffsetDate, int> offsetDateCache = [];
int currentOffsetDate;
public int Next(OffsetDate input) =>
offsetDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentOffsetDate));
public int Next(OffsetDate input) =>
offsetDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentOffsetDate));
ConcurrentDictionary<LocalDateTime, int> localDateTimeCache = [];
int currentLocalDateTime;
ConcurrentDictionary<LocalDateTime, int> localDateTimeCache = [];
int currentLocalDateTime;
public int Next(LocalDateTime input) =>
localDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentLocalDateTime));
public int Next(LocalDateTime input) =>
localDateTimeCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentLocalDateTime));
ConcurrentDictionary<LocalDate, int> localDateCache = [];
int currentLocalDate;
ConcurrentDictionary<LocalDate, int> localDateCache = [];
int currentLocalDate;
public int Next(LocalDate input) =>
localDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentLocalDate));
public int Next(LocalDate input) =>
localDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentLocalDate));
ConcurrentDictionary<Instant, int> instantCache = [];
int currentInstant;
ConcurrentDictionary<Instant, int> instantCache = [];
int currentInstant;
public int Next(Instant input) =>
instantCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentInstant));
public int Next(Instant input) =>
instantCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentInstant));
ConcurrentDictionary<AnnualDate, int> annualDateCache = [];
int currentAnnualDate;
ConcurrentDictionary<AnnualDate, int> annualDateCache = [];
int currentAnnualDate;
public int Next(AnnualDate input) =>
annualDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentAnnualDate));
public int Next(AnnualDate input) =>
annualDateCache.GetOrAdd(input, _ => Interlocked.Increment(ref currentAnnualDate));
public static void Init() =>
VerifierSettings.OnVerify(Start, Stop);
public static void Init() =>
VerifierSettings.OnVerify(Start, Stop);
public static CounterContext Current
{
get
{
var context = local.Value;
if (context == null)
{
throw new("No current context");
}
public static CounterContext Current
{
get
{
var context = local.Value;
if (context == null)
{
throw new("No current context");
}
return context;
}
}
return context;
}
}
static void Start() =>
local.Value = new();
static void Start() =>
local.Value = new();
static void Stop() =>
local.Value = null;
}
static void Stop() =>
local.Value = null;
}

Просмотреть файл

@ -0,0 +1,5 @@
// Global using directives
global using Argon;
global using Argon.NodaTime;
global using NodaTime;

Просмотреть файл

@ -1,7 +1,5 @@
namespace VerifyTests;
using Converters;
public static class VerifyNodaTime
{
public static bool Initialized { get; private set; }