Add if-elseif-else decomp test

This commit is contained in:
Yoshi Askharoun
2025-09-20 11:52:28 -05:00
parent e2b880f5c4
commit ebb41f0384
5 changed files with 99 additions and 0 deletions
+53
View File
@@ -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);
}
}
@@ -0,0 +1,32 @@
<UIX xmlns="http://schemas.microsoft.com/2007/uix"
xmlns:iris="assembly://UIX/Microsoft.Iris">
<UI Name="Default">
<Locals>
<iris:Command Name="SelectCommand"/>
</Locals>
<Content>
<Text Color="Red">
<Content>Howdy from Microsoft.Iris!</Content>
</Text>
</Content>
<Scripts>
<Script>
int x = 5;
if (x &lt; 10)
{
x = x + 1;
}
else if (x &lt; 20)
{
x = x + 2;
}
else
{
x = x + 3;
}
</Script>
</Scripts>
</UI>
</UIX>
+10
View File
@@ -60,6 +60,16 @@ namespace UIX.Test {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] cfa_if_elseif_else_uix {
get {
object obj = ResourceManager.GetObject("cfa_if-elseif-else.uix", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
+3
View File
@@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="cfa_if-elseif-else.uix" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\cfa_if-elseif-else.uix;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="testA.uix" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\testA.uix;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
+1
View File
@@ -25,6 +25,7 @@
<ItemGroup>
<ProjectReference Include="..\UIX.Asm\UIX.Asm.csproj" />
<ProjectReference Include="..\UIX.DecompXml\UIX.DecompXml.csproj" />
</ItemGroup>
<ItemGroup>