forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request unoplatform#15417 from Youssef1313/issues/15416
fix: Properly handle `{x:Null}` in an attached DP
- Loading branch information
Showing
10 changed files
with
472 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...eGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MarkupExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Uno.UI.SourceGenerators.Tests.Verifiers; | ||
|
||
namespace Uno.UI.SourceGenerators.Tests.XamlCodeGeneratorTests; | ||
|
||
using Verify = XamlSourceGeneratorVerifier; | ||
|
||
[TestClass] | ||
public class Given_MarkupExtension | ||
{ | ||
[TestMethod] | ||
public async Task TestNullMarkupExtensionInRegularProperty() | ||
{ | ||
var xamlFile = new XamlFile("MainPage.xaml", """ | ||
<Page | ||
x:Class="TestRepro.MainPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:TestRepro" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<Grid> | ||
<TextBox Text="{x:Null}" /> | ||
</Grid> | ||
</Page> | ||
"""); | ||
|
||
var test = new Verify.Test(xamlFile) | ||
{ | ||
TestState = | ||
{ | ||
Sources = | ||
{ | ||
""" | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
namespace TestRepro | ||
{ | ||
public sealed partial class MainPage : Page | ||
{ | ||
public MainPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} | ||
""" | ||
} | ||
} | ||
}.AddGeneratedSources(); | ||
|
||
await test.RunAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestNullMarkupExtensionInAttachedProperty() | ||
{ | ||
var xamlFile = new XamlFile("MainPage.xaml", """ | ||
<Page | ||
x:Class="TestRepro.MainPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:TestRepro" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<Grid> | ||
<TextBox ToolTipService.ToolTip="{x:Null}" /> | ||
</Grid> | ||
</Page> | ||
"""); | ||
|
||
var test = new Verify.Test(xamlFile) | ||
{ | ||
TestState = | ||
{ | ||
Sources = | ||
{ | ||
""" | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
namespace TestRepro | ||
{ | ||
public sealed partial class MainPage : Page | ||
{ | ||
public MainPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} | ||
""" | ||
} | ||
} | ||
}.AddGeneratedSources(); | ||
|
||
await test.RunAsync(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ators.Tests/XamlCodeGeneratorTests/Out/TNMEIAP/XamlCodeGenerator_GlobalStaticResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <autogenerated /> | ||
#if __WASM__ | ||
#error invalid internal source generator state. The __WASM__ DefineConstant was not propagated properly. | ||
#endif | ||
namespace MyProject | ||
{ | ||
/// <summary> | ||
/// Contains all the static resources defined for the application | ||
/// </summary> | ||
public sealed partial class GlobalStaticResources | ||
{ | ||
static bool _initialized; | ||
private static bool _stylesRegistered; | ||
private static bool _dictionariesRegistered; | ||
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ {get; } = new global::Uno.UI.Xaml.XamlParseContext() | ||
{ | ||
AssemblyName = "TestProject", | ||
} | ||
; | ||
|
||
static GlobalStaticResources() | ||
{ | ||
Initialize(); | ||
} | ||
public static void Initialize() | ||
{ | ||
if (!_initialized) | ||
{ | ||
_initialized = true; | ||
global::Uno.UI.GlobalStaticResources.Initialize(); | ||
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles(); | ||
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource(); | ||
} | ||
} | ||
public static void RegisterDefaultStyles() | ||
{ | ||
if(!_stylesRegistered) | ||
{ | ||
_stylesRegistered = true; | ||
RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources | ||
public static void RegisterResourceDictionariesBySource() | ||
{ | ||
if(!_dictionariesRegistered) | ||
{ | ||
_dictionariesRegistered = true; | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources | ||
internal static void RegisterResourceDictionariesBySourceLocal() | ||
{ | ||
} | ||
static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); | ||
|
||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...ators.Tests/XamlCodeGeneratorTests/Out/TNMEIAP/XamlCodeGenerator_LocalizationResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// <auto-generated /> | ||
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")] |
122 changes: 122 additions & 0 deletions
122
...GeneratorTests/Out/TNMEIAP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// <autogenerated /> | ||
#pragma warning disable CS0114 | ||
#pragma warning disable CS0108 | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Uno.UI; | ||
using Uno.UI.Xaml; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Documents; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Media.Animation; | ||
using Microsoft.UI.Xaml.Shapes; | ||
using Windows.UI.Text; | ||
using Uno.Extensions; | ||
using Uno; | ||
using Uno.UI.Helpers; | ||
using Uno.UI.Helpers.Xaml; | ||
using MyProject; | ||
|
||
#if __ANDROID__ | ||
using _View = Android.Views.View; | ||
#elif __IOS__ | ||
using _View = UIKit.UIView; | ||
#elif __MACOS__ | ||
using _View = AppKit.NSView; | ||
#else | ||
using _View = Microsoft.UI.Xaml.UIElement; | ||
#endif | ||
|
||
namespace TestRepro | ||
{ | ||
partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page | ||
{ | ||
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; | ||
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; | ||
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); | ||
private void InitializeComponent() | ||
{ | ||
NameScope.SetNameScope(this, __nameScope); | ||
var __that = this; | ||
base.IsParsing = true; | ||
// Source 0\MainPage.xaml (Line 1:2) | ||
base.Content = | ||
new global::Microsoft.UI.Xaml.Controls.Grid | ||
{ | ||
IsParsing = true, | ||
// Source 0\MainPage.xaml (Line 10:3) | ||
Children = | ||
{ | ||
new global::Microsoft.UI.Xaml.Controls.TextBox | ||
{ | ||
IsParsing = true, | ||
// Source 0\MainPage.xaml (Line 11:4) | ||
} | ||
.MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler0)(c0 => | ||
{ | ||
global::Microsoft.UI.Xaml.Controls.ToolTipService.SetToolTip(c0, | ||
null ); | ||
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c0, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); | ||
c0.CreationComplete(); | ||
} | ||
)) | ||
, | ||
} | ||
} | ||
.MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler1)(c1 => | ||
{ | ||
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c1, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); | ||
c1.CreationComplete(); | ||
} | ||
)) | ||
; | ||
|
||
this | ||
.GenericApply(((c2) => | ||
{ | ||
// Source 0\MainPage.xaml (Line 1:2) | ||
|
||
// WARNING Property c2.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}Page, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator | ||
} | ||
)) | ||
.GenericApply(((c3) => | ||
{ | ||
// Class TestRepro.MainPage | ||
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c3, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); | ||
c3.CreationComplete(); | ||
} | ||
)) | ||
; | ||
OnInitializeCompleted(); | ||
|
||
} | ||
partial void OnInitializeCompleted(); | ||
} | ||
} | ||
namespace MyProject | ||
{ | ||
static class MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions | ||
{ | ||
public delegate void XamlApplyHandler0(global::Microsoft.UI.Xaml.Controls.TextBox instance); | ||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] | ||
public static global::Microsoft.UI.Xaml.Controls.TextBox MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.TextBox instance, XamlApplyHandler0 handler) | ||
{ | ||
handler(instance); | ||
return instance; | ||
} | ||
public delegate void XamlApplyHandler1(global::Microsoft.UI.Xaml.Controls.Grid instance); | ||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] | ||
public static global::Microsoft.UI.Xaml.Controls.Grid MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.Grid instance, XamlApplyHandler1 handler) | ||
{ | ||
handler(instance); | ||
return instance; | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ators.Tests/XamlCodeGeneratorTests/Out/TNMEIRP/XamlCodeGenerator_GlobalStaticResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <autogenerated /> | ||
#if __WASM__ | ||
#error invalid internal source generator state. The __WASM__ DefineConstant was not propagated properly. | ||
#endif | ||
namespace MyProject | ||
{ | ||
/// <summary> | ||
/// Contains all the static resources defined for the application | ||
/// </summary> | ||
public sealed partial class GlobalStaticResources | ||
{ | ||
static bool _initialized; | ||
private static bool _stylesRegistered; | ||
private static bool _dictionariesRegistered; | ||
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ {get; } = new global::Uno.UI.Xaml.XamlParseContext() | ||
{ | ||
AssemblyName = "TestProject", | ||
} | ||
; | ||
|
||
static GlobalStaticResources() | ||
{ | ||
Initialize(); | ||
} | ||
public static void Initialize() | ||
{ | ||
if (!_initialized) | ||
{ | ||
_initialized = true; | ||
global::Uno.UI.GlobalStaticResources.Initialize(); | ||
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles(); | ||
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource(); | ||
} | ||
} | ||
public static void RegisterDefaultStyles() | ||
{ | ||
if(!_stylesRegistered) | ||
{ | ||
_stylesRegistered = true; | ||
RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources | ||
public static void RegisterResourceDictionariesBySource() | ||
{ | ||
if(!_dictionariesRegistered) | ||
{ | ||
_dictionariesRegistered = true; | ||
} | ||
} | ||
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources | ||
internal static void RegisterResourceDictionariesBySourceLocal() | ||
{ | ||
} | ||
static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); | ||
|
||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...ators.Tests/XamlCodeGeneratorTests/Out/TNMEIRP/XamlCodeGenerator_LocalizationResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// <auto-generated /> | ||
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")] |
Oops, something went wrong.