From ebb41f03849b7f45d174efd1489ffd6336a4151a Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Sat, 20 Sep 2025 11:52:28 -0500 Subject: [PATCH] Add if-elseif-else decomp test --- libs/UIX.Test/DecompileControlFlow.cs | 53 +++++++++++++++++++ .../UIX.Test/Resources/cfa_if-elseif-else.uix | 32 +++++++++++ libs/UIX.Test/TestResources.Designer.cs | 10 ++++ libs/UIX.Test/TestResources.resx | 3 ++ libs/UIX.Test/UIX.Test.csproj | 1 + 5 files changed, 99 insertions(+) create mode 100644 libs/UIX.Test/DecompileControlFlow.cs create mode 100644 libs/UIX.Test/Resources/cfa_if-elseif-else.uix diff --git a/libs/UIX.Test/DecompileControlFlow.cs b/libs/UIX.Test/DecompileControlFlow.cs new file mode 100644 index 0000000..ac994c4 --- /dev/null +++ b/libs/UIX.Test/DecompileControlFlow.cs @@ -0,0 +1,53 @@ +using Microsoft.Iris; +using Microsoft.Iris.DecompXml; +using Microsoft.Iris.Markup; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UIX.Test.Fixtures; +using Xunit.Abstractions; + +namespace UIX.Test; + +[Collection(MarkupSystemCollection.Name)] +public class DecompileControlFlow +{ + private readonly ITestOutputHelper _output; + + public DecompileControlFlow(ITestOutputHelper output, MarkupSystemFixture markupSystemFixture) + { + _output = output; + markupSystemFixture.SetupDebug(output); + } + + [Fact] + public async Task IfElseIfElse() + { + using TempFile uixFile = new($"cfa_if-elseif-else.uix", ".uix"); + await uixFile.InitAsync(); + + var uibPathEx = Path.ChangeExtension(uixFile.Path, ".uib"); + + // Compile the UIX source + CompilerInput uixCompilerInput = new() + { + SourceFileName = uixFile.Path, + OutputFileName = uibPathEx + }; + var uixSuccess = MarkupCompiler.Compile([uixCompilerInput], default); + Assert.True(uixSuccess); + + // Decompile the compiled UIX + var sourceLoadResult = MarkupSystem.ResolveLoadResult($"file://{uixFile.Path}", MarkupSystem.RootIslandId); + var decompiler = Decompiler.Load(sourceLoadResult); + var uixDocAc = decompiler.Decompile(); + + var uixScriptAc = uixDocAc.Descendants() + .Where(e => e.Name.LocalName == "Script") + .FirstOrDefault()?.Value; + Assert.NotNull(uixScriptAc); + _output.WriteLine(uixScriptAc); + } +} diff --git a/libs/UIX.Test/Resources/cfa_if-elseif-else.uix b/libs/UIX.Test/Resources/cfa_if-elseif-else.uix new file mode 100644 index 0000000..3dae19e --- /dev/null +++ b/libs/UIX.Test/Resources/cfa_if-elseif-else.uix @@ -0,0 +1,32 @@ + + + + + + + + Howdy from Microsoft.Iris! + + + + + + + + \ No newline at end of file diff --git a/libs/UIX.Test/TestResources.Designer.cs b/libs/UIX.Test/TestResources.Designer.cs index d8f47ef..7e1d91b 100644 --- a/libs/UIX.Test/TestResources.Designer.cs +++ b/libs/UIX.Test/TestResources.Designer.cs @@ -60,6 +60,16 @@ namespace UIX.Test { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] cfa_if_elseif_else_uix { + get { + object obj = ResourceManager.GetObject("cfa_if-elseif-else.uix", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/libs/UIX.Test/TestResources.resx b/libs/UIX.Test/TestResources.resx index dbd2d7b..42e1224 100644 --- a/libs/UIX.Test/TestResources.resx +++ b/libs/UIX.Test/TestResources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Resources\cfa_if-elseif-else.uix;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Resources\testA.uix;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/libs/UIX.Test/UIX.Test.csproj b/libs/UIX.Test/UIX.Test.csproj index f504870..e9647c3 100644 --- a/libs/UIX.Test/UIX.Test.csproj +++ b/libs/UIX.Test/UIX.Test.csproj @@ -25,6 +25,7 @@ +