Skip to content

Commit

Permalink
Add regression testing for the v8 source generator. (#95352)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis authored Nov 29, 2023
1 parent 0a1adcd commit 642c868
Show file tree
Hide file tree
Showing 16 changed files with 1,285 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Source files represent a source generated JsonSerializerContext as produced by the .NET 8 SDK.
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components.
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests.

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Text.Json.Tests.SourceGenRegressionTests.Net80
{
public partial class Net80GeneratedContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter>? _ClassWithCustomConverter;

/// <summary>
/// Defines the source generated JSON serialization contract metadata for a given type.
/// </summary>
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter> ClassWithCustomConverter
{
get => _ClassWithCustomConverter ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter>)Options.GetTypeInfo(typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter));
}

private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter> Create_ClassWithCustomConverter(global::System.Text.Json.JsonSerializerOptions options)
{
if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter> jsonTypeInfo))
{
global::System.Text.Json.Serialization.JsonConverter converter = ExpandConverter(typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter), new global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter.CustomConverter(), options);
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter> (options, converter);
}

jsonTypeInfo.OriginatingResolver = this;
return jsonTypeInfo;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Source files represent a source generated JsonSerializerContext as produced by the .NET 8 SDK.
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components.
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests.

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Text.Json.Tests.SourceGenRegressionTests.Net80
{
public partial class Net80GeneratedContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset>? _DateTimeOffset;

/// <summary>
/// Defines the source generated JSON serialization contract metadata for a given type.
/// </summary>
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset> DateTimeOffset
{
get => _DateTimeOffset ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset>)Options.GetTypeInfo(typeof(global::System.DateTimeOffset));
}

private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset> Create_DateTimeOffset(global::System.Text.Json.JsonSerializerOptions options)
{
if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.DateTimeOffset>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.DateTimeOffset> jsonTypeInfo))
{
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::System.DateTimeOffset>(options, global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.DateTimeOffsetConverter);
}

jsonTypeInfo.OriginatingResolver = this;
return jsonTypeInfo;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Source files represent a source generated JsonSerializerContext as produced by the .NET 8 SDK.
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components.
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests.

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Text.Json.Tests.SourceGenRegressionTests.Net80
{
public partial class Net80GeneratedContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>>? _DictionaryStringHighLowTemps;

/// <summary>
/// Defines the source generated JSON serialization contract metadata for a given type.
/// </summary>
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>> DictionaryStringHighLowTemps
{
get => _DictionaryStringHighLowTemps ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>>)Options.GetTypeInfo(typeof(global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>));
}

private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>> Create_DictionaryStringHighLowTemps(global::System.Text.Json.JsonSerializerOptions options)
{
if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>> jsonTypeInfo))
{
var info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>>
{
ObjectCreator = () => new global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>(),
SerializeHandler = DictionaryStringHighLowTempsSerializeHandler
};

jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateDictionaryInfo<global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>, string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>(options, info);
jsonTypeInfo.NumberHandling = null;
}

jsonTypeInfo.OriginatingResolver = this;
return jsonTypeInfo;
}

// Intentionally not a static method because we create a delegate to it. Invoking delegates to instance
// methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk.
private void DictionaryStringHighLowTempsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>? value)
{
if (value == null)
{
writer.WriteNullValue();
return;
}

writer.WriteStartObject();

foreach (global::System.Collections.Generic.KeyValuePair<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps> entry in value)
{
writer.WritePropertyName(entry.Key);
HighLowTempsSerializeHandler(writer, entry.Value);
}

writer.WriteEndObject();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Source files represent a source generated JsonSerializerContext as produced by the .NET 8 SDK.
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components.
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests.

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Text.Json.Tests.SourceGenRegressionTests.Net80
{
public partial class Net80GeneratedContext : global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver
{
/// <inheritdoc/>
public override global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(global::System.Type type)
{
Options.TryGetTypeInfo(type, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? typeInfo);
return typeInfo;
}

global::System.Text.Json.Serialization.Metadata.JsonTypeInfo? global::System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.GetTypeInfo(global::System.Type type, global::System.Text.Json.JsonSerializerOptions options)
{
if (type == typeof(global::System.Collections.Generic.Dictionary<string, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>))
{
return Create_DictionaryStringHighLowTemps(options);
}
if (type == typeof(global::System.Collections.Generic.List<global::System.DateTimeOffset>))
{
return Create_ListDateTimeOffset(options);
}
if (type == typeof(global::System.DateTimeOffset))
{
return Create_DateTimeOffset(options);
}
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.ClassWithCustomConverter))
{
return Create_ClassWithCustomConverter(options);
}
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps))
{
return Create_HighLowTemps(options);
}
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.MyLinkedList))
{
return Create_MyLinkedList(options);
}
if (type == typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.WeatherForecastWithPOCOs))
{
return Create_WeatherForecastWithPOCOs(options);
}
if (type == typeof(int))
{
return Create_Int32(options);
}
if (type == typeof(string))
{
return Create_String(options);
}
if (type == typeof(string[]))
{
return Create_StringArray(options);
}
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Source files represent a source generated JsonSerializerContext as produced by the .NET 8 SDK.
// Used to validate correctness of contexts generated by previous SDKs against the current System.Text.Json runtime components.
// Unless absolutely necessary DO NOT MODIFY any of these files -- it would invalidate the purpose of the regression tests.

// <auto-generated/>

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618

namespace System.Text.Json.Tests.SourceGenRegressionTests.Net80
{
public partial class Net80GeneratedContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>? _HighLowTemps;

/// <summary>
/// Defines the source generated JSON serialization contract metadata for a given type.
/// </summary>
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps> HighLowTemps
{
get => _HighLowTemps ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>)Options.GetTypeInfo(typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps));
}

private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps> Create_HighLowTemps(global::System.Text.Json.JsonSerializerOptions options)
{
if (!TryGetTypeInfoForRuntimeCustomConverter<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps> jsonTypeInfo))
{
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>
{
ObjectCreator = () => new global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps(),
ObjectWithParameterizedConstructorCreator = null,
PropertyMetadataInitializer = _ => HighLowTempsPropInit(options),
ConstructorParameterMetadataInitializer = null,
SerializeHandler = HighLowTempsSerializeHandler
};

jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps>(options, objectInfo);
jsonTypeInfo.NumberHandling = null;
}

jsonTypeInfo.OriginatingResolver = this;
return jsonTypeInfo;
}

private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] HighLowTempsPropInit(global::System.Text.Json.JsonSerializerOptions options)
{
var properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2];

var info0 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<int>
{
IsProperty = true,
IsPublic = true,
IsVirtual = false,
DeclaringType = typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps),
Converter = null,
Getter = static obj => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)obj).High,
Setter = static (obj, value) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)obj).High = value!,
IgnoreCondition = null,
HasJsonInclude = false,
IsExtensionData = false,
NumberHandling = null,
PropertyName = "High",
JsonPropertyName = null
};

properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<int>(options, info0);

var info1 = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfoValues<int>
{
IsProperty = true,
IsPublic = true,
IsVirtual = false,
DeclaringType = typeof(global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps),
Converter = null,
Getter = static obj => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)obj).Low,
Setter = static (obj, value) => ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)obj).Low = value!,
IgnoreCondition = null,
HasJsonInclude = false,
IsExtensionData = false,
NumberHandling = null,
PropertyName = "Low",
JsonPropertyName = null
};

properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<int>(options, info1);

return properties;
}

// Intentionally not a static method because we create a delegate to it. Invoking delegates to instance
// methods is almost as fast as virtual calls. Static methods need to go through a shuffle thunk.
private void HighLowTempsSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps? value)
{
if (value == null)
{
writer.WriteNullValue();
return;
}

writer.WriteStartObject();

writer.WriteNumber(PropName_High, ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)value).High);
writer.WriteNumber(PropName_Low, ((global::System.Text.Json.Tests.SourceGenRegressionTests.Net80.HighLowTemps)value).Low);

writer.WriteEndObject();
}
}
}
Loading

0 comments on commit 642c868

Please sign in to comment.