Remove packaged runtime repository dependency
This commit is contained in:
@@ -4,6 +4,21 @@ using Xunit;
|
||||
|
||||
public class OpcodeTableTests
|
||||
{
|
||||
[Fact]
|
||||
public void LoadsFromCallerOwnedStreamWithoutClosingIt()
|
||||
{
|
||||
using var source = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(
|
||||
"""
|
||||
{"opcodes":[{"op":"0x55","label":"mov","argc":2}]}
|
||||
"""));
|
||||
|
||||
OpcodeTable table = OpcodeTableJson.Load(source);
|
||||
|
||||
Assert.True(source.CanRead);
|
||||
Assert.Equal("mov", table.Label(0x55));
|
||||
Assert.Equal(2, table.Argc(0x55));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadsCompleteAgeCatalog()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,14 @@ public static class OpcodeTableJson
|
||||
{
|
||||
public static OpcodeTable Load(string path)
|
||||
{
|
||||
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||
using FileStream stream = File.OpenRead(path);
|
||||
return Load(stream);
|
||||
}
|
||||
|
||||
public static OpcodeTable Load(Stream stream)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(stream);
|
||||
using var doc = JsonDocument.Parse(stream);
|
||||
var dict = new Dictionary<int, (string, int)>();
|
||||
foreach (var e in doc.RootElement.GetProperty("opcodes").EnumerateArray())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user