Skip to content

Commit

Permalink
Regenerate test files
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Nov 20, 2023
1 parent 3217885 commit d259502
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 74 deletions.
42 changes: 22 additions & 20 deletions test/Riok.Mapperly.Tests/Mapping/ObjectPropertyFlatteningTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public void AutoFlattenedPropertyNullablePath()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.ValueId = source.Value.Id;
target.ValueId = sourceValue.Id;
}
return target;
"""
Expand All @@ -160,10 +160,10 @@ public void AutoFlattenedMultiplePropertiesNullablePath()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.ValueId = source.Value.Id.ToString();
target.ValueName = source.Value.Name;
target.ValueId = sourceValue.Id.ToString();
target.ValueName = sourceValue.Name;
}
return target;
"""
Expand All @@ -186,9 +186,9 @@ public void AutoFlattenedPropertyNullableValueTypePath()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Id.Value != null)
if (source.Id.Value is { } sourceIdValue)
{
target.IdValue = source.Id.Value.Value;
target.IdValue = sourceIdValue;
}
return target;
"""
Expand All @@ -211,9 +211,9 @@ public void AutoFlattenedPropertyNullableValueTypePathShouldResolve()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Prop != null)
if (source.Prop is { } sourceProp)
{
target.PropInteger = source.Prop.Value.Integer.ToString();
target.PropInteger = sourceProp.Integer.ToString();
}
return target;
"""
Expand Down Expand Up @@ -260,9 +260,9 @@ public void AutoFlattenedMultiplePropertiesPathDisabledNullable()
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.ValueId = source.Value.Id.ToString();
target.ValueId = sourceValue.Id.ToString();
}
target.ValueName = source.Value?.Name;
return target;
Expand Down Expand Up @@ -489,10 +489,12 @@ public Task ManualUnflattenedPropertyTargetPropertyNotFoundShouldDiagnostic()
public void ManualNestedPropertyNullablePath()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"[MapProperty(\"Value1.Value1.Id1\", \"Value2.Value2.Id2\")]"
+ "[MapProperty(\"Value1.Value1.Id10\", \"Value2.Value2.Id20\")]"
+ "[MapProperty(new[] { \"Value1\", \"Id100\" }, new[] { \"Value2\", \"Id200\" })]"
+ "partial B Map(A source);",
"""
[MapProperty("Value1.Value1.Id1", "Value2.Value2.Id2")]
[MapProperty("Value1.Value1.Id10", "Value2.Value2.Id20")]
[MapProperty(new[] { "Value1", "Id100" }, new[] { "Value2", "Id200" })]
partial B Map(A source);
""",
"class A { public C? Value1 { get; set; } }",
"class B { public E? Value2 { get; set; } }",
"class C { public D? Value1 { get; set; } public string Id100 { get; set; } }",
Expand All @@ -507,16 +509,16 @@ public void ManualNestedPropertyNullablePath()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value1 != null)
if (source.Value1 is { } sourceValue1)
{
target.Value2 ??= new();
if (source.Value1.Value1 != null)
if (sourceValue1.Value1 is { } sourceValue1Value1)
{
target.Value2.Value2 ??= new();
target.Value2.Value2.Id2 = source.Value1.Value1.Id1;
target.Value2.Value2.Id20 = source.Value1.Value1.Id10;
target.Value2.Value2.Id2 = sourceValue1Value1.Id1;
target.Value2.Value2.Id20 = sourceValue1Value1.Id10;
}
target.Value2.Id200 = source.Value1.Id100;
target.Value2.Id200 = sourceValue1.Id100;
}
return target;
"""
Expand Down
56 changes: 28 additions & 28 deletions test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void NullableIntToNonNullableIntProperty()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value.Value;
target.Value = sourceValue;
}
return target;
"""
Expand All @@ -70,9 +70,9 @@ TestSourceBuilderOptions.Default with
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value.Value;
target.Value = sourceValue;
}
return target;
"""
Expand Down Expand Up @@ -100,9 +100,9 @@ TestSourceBuilderOptions.Default with
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value.Value;
target.Value = sourceValue;
}
else
{
Expand All @@ -129,9 +129,9 @@ public void NullableStringToNonNullableStringProperty()
.HaveSingleMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value;
target.Value = sourceValue;
}
return target;
"""
Expand All @@ -156,9 +156,9 @@ public void NullableClassToNonNullableClassProperty()
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
"""
Expand Down Expand Up @@ -207,9 +207,9 @@ TestSourceBuilderOptions.Default with
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value;
target.Value = sourceValue;
}
return target;
"""
Expand Down Expand Up @@ -237,9 +237,9 @@ TestSourceBuilderOptions.Default with
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = source.Value;
target.Value = sourceValue;
}
else
{
Expand Down Expand Up @@ -315,9 +315,9 @@ public void NullableClassToNullableClassProperty()
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
"""
Expand Down Expand Up @@ -346,9 +346,9 @@ TestSourceBuilderOptions.Default with
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
"""
Expand Down Expand Up @@ -378,9 +378,9 @@ TestSourceBuilderOptions.Default with
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
else
{
Expand Down Expand Up @@ -409,9 +409,9 @@ public void DisabledNullableClassPropertyToNonNullableProperty()
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
"""
Expand All @@ -436,9 +436,9 @@ public void NullableClassPropertyToDisabledNullableProperty()
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
"""
Expand Down Expand Up @@ -467,9 +467,9 @@ TestSourceBuilderOptions.Default with
.HaveMapMethodBody(
"""
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
else
{
Expand Down Expand Up @@ -569,9 +569,9 @@ public void ShouldUseUserImplementedMappingWithNonNullableValueType()
if (y == null)
return default;
var target = new global::NotNullableType();
if (y.Test != null)
if (y.Test is { } yTest)
{
target.Test = Map(y.Test.Value);
target.Test = Map(yTest);
}
return target;
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public partial class Mapper
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToICollection(source.Value);
target.Value = MapToICollection(sourceValue);
}
return target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public partial class Mapper
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToIReadOnlyCollection(source.Value);
target.Value = MapToIReadOnlyCollection(sourceValue);
}
return target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public partial class Mapper
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToIReadOnlyCollection(source.Value);
target.Value = MapToIReadOnlyCollection(sourceValue);
}
return target;
}
Expand All @@ -26,4 +26,4 @@ public partial class Mapper
}
return target;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public partial class Mapper
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToDArray(source.Value);
target.Value = MapToDArray(sourceValue);
}
return target;
}
Expand All @@ -33,4 +33,4 @@ public partial class Mapper
}
return target;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ public partial class Mapper
private partial global::B Map(global::A source)
{
var target = new global::B();
if (source.Nested != null)
if (source.Nested is { } sourceNested)
{
if (source.Nested.Value2 != null)
if (sourceNested.Value2 is { } sourceNestedValue2)
{
target.NestedValue2 = source.Nested.Value2.Value;
target.NestedValue2 = sourceNestedValue2;
}
target.Nested = MapToD(source.Nested);
target.Nested = MapToD(sourceNested);
}
return target;
}

private global::D MapToD(global::C source)
{
var target = new global::D();
if (source.Value1 != null)
if (source.Value1 is { } sourceValue1)
{
target.Value1 = source.Value1.Value;
target.Value1 = sourceValue1;
}
return target;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public partial class Mapper
if (source == null)
return default;
var target = new global::B();
if (source.Value != null)
if (source.Value is { } sourceValue)
{
target.Value = MapToD(source.Value);
target.Value = MapToD(sourceValue);
}
return target;
}
Expand All @@ -21,4 +21,4 @@ public partial class Mapper
target.Value = source.Value;
return target;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public partial class Mapper
private partial global::B Map(global::A source)
{
var target = new global::B();
if (source.Nested?.Nested2 != null)
if (source.Nested?.Nested2 is { } sourceNestedNested2)
{
target.NestedValue4 = source.Nested.Nested2.Value3;
target.NestedValue4 = sourceNestedNested2.Value3;
}
return target;
}
}
}
Loading

0 comments on commit d259502

Please sign in to comment.