Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Aug 22, 2023
1 parent 73195a9 commit 0ed8965
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -5397,6 +5397,36 @@ public class MyType
Assert.Collection(result.Diagnostics, d => { Assert.Equal("CS0411", d.Id); });
}

[Fact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48526")]
public void EventCallbackOfT_Array()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components.Forms;
namespace Test;
public class MyComponent<TItem> : InputBase<TItem[]>
{
protected override bool TryParseValueFromString(string value, out TItem[] result, out string validationErrorMessage) => throw null;
}
"""));

// Act
var generated = CompileToCSharp("""
<MyComponent @bind-Value="Selected" />
@code {
string[] Selected { get; set; } = Array.Empty<string>();
}
""");

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

#endregion

#region Event Handlers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
var __typeInference_CreateMyComponent_0 = global::__Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(__builder, -1, -1,
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Selected

#line default
#line hidden
#nullable disable
, -1, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::TItem[]>(this,
global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => Selected = __value, Selected)), -1, () => Selected);
#pragma warning disable BL0005
__typeInference_CreateMyComponent_0.
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Value

#line default
#line hidden
#nullable disable
= default;
#pragma warning restore BL0005
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent<>);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"

string[] Selected { get; set; } = Array.Empty<string>();

#line default
#line hidden
#nullable disable
}
}
namespace __Blazor.Test.TestComponent
{
#line hidden
internal static class TypeInference
{
public static global::Test.MyComponent<TItem> CreateMyComponent_0<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, TItem[] __arg0, int __seq1, global::Microsoft.AspNetCore.Components.EventCallback<TItem[]> __arg1, int __seq2, global::System.Linq.Expressions.Expression<global::System.Func<TItem[]>> __arg2)
{
__builder.OpenComponent<global::Test.MyComponent<TItem>>(seq);
__builder.AddComponentParameter(__seq0, "Value", __arg0);
__builder.AddComponentParameter(__seq1, "ValueChanged", __arg1);
__builder.AddComponentParameter(__seq2, "ValueExpression", __arg2);
__builder.CloseComponent();
return default;
}
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [38] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value - AttributeStructure.DoubleQuotes
CSharpExpression -
LazyIntermediateToken - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Selected
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - ValueChanged - ValueChanged - AttributeStructure.DoubleQuotes
CSharpExpression -
IntermediateToken - - CSharp - global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this,
IntermediateToken - - CSharp - __value => Selected = __value
IntermediateToken - - CSharp - , Selected)
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - ValueExpression - ValueExpression - AttributeStructure.DoubleQuotes
CSharpExpression -
IntermediateToken - - CSharp - () => Selected
HtmlContent - (38:0,38 [4] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (38:0,38 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpCode - (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string[] Selected { get; set; } = Array.Empty<string>();\n
NamespaceDeclaration - - __Blazor.Test.TestComponent
ClassDeclaration - - internal static - TypeInference - -
ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Source Location: (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml)
|Selected|
Generated Location: (1072:25,26 [8] )
|Selected|

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1610:36,19 [5] )
|Value|

Source Location: (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml)
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Generated Location: (2025:54,7 [64] )
|
string[] Selected { get; set; } = Array.Empty<string>();
|

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
global::__Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(__builder, 0, 1,
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Selected

#line default
#line hidden
#nullable disable
, 2, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::TItem[]>(this, global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => Selected = __value, Selected)), 3, () => Selected);
}
#pragma warning restore 1998
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"

string[] Selected { get; set; } = Array.Empty<string>();

#line default
#line hidden
#nullable disable
}
}
namespace __Blazor.Test.TestComponent
{
#line hidden
internal static class TypeInference
{
public static void CreateMyComponent_0<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, TItem[] __arg0, int __seq1, global::Microsoft.AspNetCore.Components.EventCallback<TItem[]> __arg1, int __seq2, global::System.Linq.Expressions.Expression<global::System.Func<TItem[]>> __arg2)
{
__builder.OpenComponent<global::Test.MyComponent<TItem>>(seq);
__builder.AddComponentParameter(__seq0, "Value", __arg0);
__builder.AddComponentParameter(__seq1, "ValueChanged", __arg1);
__builder.AddComponentParameter(__seq2, "ValueExpression", __arg2);
__builder.CloseComponent();
}
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [22] ) - global::System
UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [27] ) - global::System.Linq
UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [38] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value - AttributeStructure.DoubleQuotes
CSharpExpression -
LazyIntermediateToken - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Selected
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - ValueChanged - ValueChanged - AttributeStructure.DoubleQuotes
CSharpExpression -
IntermediateToken - - CSharp - global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this,
IntermediateToken - - CSharp - __value => Selected = __value
IntermediateToken - - CSharp - , Selected)
ComponentAttribute - (26:0,26 [8] x:\dir\subdir\Test\TestComponent.cshtml) - ValueExpression - ValueExpression - AttributeStructure.DoubleQuotes
CSharpExpression -
IntermediateToken - - CSharp - () => Selected
CSharpCode - (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string[] Selected { get; set; } = Array.Empty<string>();\n
NamespaceDeclaration - - __Blazor.Test.TestComponent
ClassDeclaration - - internal static - TypeInference - -
ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Source Location: (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml)
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Generated Location: (1232:28,7 [64] )
|
string[] Selected { get; set; } = Array.Empty<string>();
|

0 comments on commit 0ed8965

Please sign in to comment.