Files
ZuneUIXTools/libs/UIX.Test/Assembly.cs
T

85 lines
1.9 KiB
C#
Raw Normal View History

2024-01-29 21:42:06 -06:00
using Sprache;
using Microsoft.Iris.Asm;
2024-01-29 22:09:51 -06:00
using Xunit.Abstractions;
2024-01-30 23:30:42 -06:00
using Microsoft.Iris.Markup;
using UIX.Test.Fixtures;
2024-02-03 20:51:54 -06:00
using Microsoft.Iris;
2024-01-29 21:42:06 -06:00
namespace UIX.Test;
[Collection(MarkupSystemCollection.Name)]
2024-01-29 22:09:51 -06:00
public class Assembly(ITestOutputHelper output)
2024-01-29 21:42:06 -06:00
{
[Fact]
2024-01-31 19:51:55 -06:00
public void Parse()
2024-01-29 21:42:06 -06:00
{
const string code =
"""
2024-02-08 13:50:51 -06:00
.export main 0 UI
2024-01-30 23:30:42 -06:00
.import-ns Me as me
.import-ns assembly://UIX/Microsoft.Iris as iris
2024-02-08 13:50:51 -06:00
.import-type iris:Command
2024-01-29 21:42:06 -06:00
2024-02-05 09:23:46 -06:00
.section data
.section object
2024-01-29 21:42:06 -06:00
main:
COBJ 2
PSHC 0
PINI 1
PSHC 1
PINI 2
PINI 0
RETV
RETV
""";
var ast = Lexer.Program.Parse(code);
2024-01-29 22:09:51 -06:00
output.WriteLine(ast.ToString());
2024-01-29 21:42:06 -06:00
Assert.NotNull(ast);
2024-02-08 13:50:51 -06:00
Assert.Equal(3 + 1 + 2, ast.Directives.Count());
Assert.Equal(9, ast.Body.Count());
2024-01-29 21:42:06 -06:00
}
2024-01-30 23:30:42 -06:00
2024-02-03 20:51:54 -06:00
[Fact]
public async Task Assemble()
{
using TempFile tempFile = new("testA.uixa", ".uixa");
await tempFile.InitAsync();
CompilerInput[] compilerInputs = [
new()
{
SourceFileName = tempFile.Path,
OutputFileName = Path.ChangeExtension(tempFile.Path, ".uib")
}
];
foreach (var compilerInput in compilerInputs)
output.WriteLine(compilerInput.OutputFileName);
MarkupCompiler.Compile(compilerInputs, default);
}
[Theory]
[InlineData("text.uib")]
[InlineData("text.uix")]
[InlineData("testA.uix")]
[InlineData("testB.uix")]
2024-01-31 20:07:01 -06:00
public async Task Disassemble(string testResourceName)
2024-01-30 23:30:42 -06:00
{
2024-01-31 20:07:01 -06:00
using TempFile tempFile = new(testResourceName);
await tempFile.InitAsync();
2024-01-30 23:30:42 -06:00
2024-01-31 20:07:01 -06:00
string uri = "file://" + tempFile.Path;
2024-01-30 23:30:42 -06:00
var sourceLoadResult = MarkupSystem.ResolveLoadResult(uri, MarkupSystem.RootIslandId);
var dis = Disassembler.Load(sourceLoadResult as MarkupLoadResult);
var disText = dis.Write();
output.WriteLine(disText);
2024-01-30 23:30:42 -06:00
}
2024-01-29 21:42:06 -06:00
}