Skip to content

Commit

Permalink
extracted binding id calculation into separate variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jkurdek committed Jun 18, 2024
1 parent 56f9cd7 commit d233998
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public void GenerateSimpleBinding()
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());

AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
$$"""
Expand All @@ -39,7 +41,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 3, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<string, int> getter,
Expand Down Expand Up @@ -107,6 +109,7 @@ public class B
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());
AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
$$"""
Expand All @@ -132,7 +135,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 6, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.A?, int> getter,
Expand Down Expand Up @@ -209,6 +212,7 @@ public class B
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());
AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
$$"""
Expand All @@ -234,7 +238,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 7, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.A?, int> getter,
Expand Down Expand Up @@ -416,6 +420,7 @@ public class C
public void GenerateSimpleBindingWhenNullableDisabledAndPropertyNullable(string source)
{
var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());
AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
$$"""
Expand All @@ -441,7 +446,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 7, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.A?, global::MyNamespace.C?> getter,
Expand Down Expand Up @@ -532,6 +537,7 @@ public class D {
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());
AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
$$"""
Expand All @@ -557,7 +563,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 7, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.A?, global::MyNamespace.D?> getter,
Expand Down Expand Up @@ -648,6 +654,7 @@ public class MyPropertyClass
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());

AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
Expand All @@ -674,7 +681,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 4, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.MySourceClass, global::MyNamespace.MyPropertyClass?> getter,
Expand Down Expand Up @@ -770,6 +777,7 @@ public class MyPropertyClass
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());

AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
Expand All @@ -796,7 +804,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 4, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.MySourceClass, global::MyNamespace.MyPropertyClass> getter,
Expand Down Expand Up @@ -879,6 +887,7 @@ public class Wrapper
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());

AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
Expand All @@ -904,7 +913,7 @@ internal static partial class GeneratedBindableObjectExtensions
{
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 3, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.A, int> getter,
Expand Down Expand Up @@ -984,6 +993,7 @@ public class MyPropertyClass
""";

var result = SourceGenHelpers.Run(source);
var id = Math.Abs(result.Binding!.Location.GetHashCode());

AssertExtensions.AssertNoDiagnostics(result);
AssertExtensions.CodeIsEqual(
Expand All @@ -1010,7 +1020,7 @@ internal static partial class GeneratedBindableObjectExtensions
{{BindingCodeWriter.GeneratedCodeAttribute}}
[InterceptsLocationAttribute(@"Path\To\Program.cs", 6, 7)]
public static void SetBinding{{Math.Abs(result.Binding!.Location.GetHashCode())}}(
public static void SetBinding{{id}}(
this BindableObject bindableObject,
BindableProperty bindableProperty,
Func<global::MyNamespace.MySourceClass, global::MyNamespace.MyPropertyClass?> getter,
Expand Down

0 comments on commit d233998

Please sign in to comment.