Fix 1: replace 3 copy-paste meter blocks in VitalsTree_MetersHaveExpectedSliceIds
with a single table-driven loop — a 4th meter is now a one-liner and failures
name the failing meter id directly.
Fix 2: FixtureLoader now reads the fixture as bytes and strips the UTF-8 BOM
(EF BB BF) before passing the span to JsonSerializer, so a BOM-bearing fixture
file never causes a spurious JsonReaderException.
Fix 3: add [Trait("Category", "Conformance")] at the class level so conformance
tests are selectable by category filter.
Fix 4: add missing <param name="layoutId"> doc tag to LayoutImporter.ImportInfos.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.9 KiB
C#
43 lines
1.9 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using AcDream.App.UI.Layout;
|
|
|
|
namespace AcDream.App.Tests.UI.Layout;
|
|
|
|
/// <summary>
|
|
/// Loads the committed vitals ElementInfo fixture and builds the widget tree —
|
|
/// no dats required. The fixture was generated from layout <c>0x2100006C</c>
|
|
/// via the real portal.dat and serialized with <see cref="System.Text.Json"/>.
|
|
/// </summary>
|
|
public static class FixtureLoader
|
|
{
|
|
private static readonly JsonSerializerOptions _opts = new()
|
|
{
|
|
IncludeFields = true,
|
|
};
|
|
|
|
/// <summary>
|
|
/// Deserializes the committed <c>vitals_2100006C.json</c> fixture (copied to
|
|
/// the test output directory via the csproj <c>CopyToOutputDirectory</c> item)
|
|
/// into an <see cref="ElementInfo"/> tree, then builds and returns the
|
|
/// <see cref="ImportedLayout"/> using a null-returning sprite resolver and no
|
|
/// dat font — sufficient for conformance checks on tree structure and slice ids.
|
|
/// </summary>
|
|
public static ImportedLayout LoadVitals()
|
|
{
|
|
var fixturePath = Path.Combine(AppContext.BaseDirectory, "UI", "Layout", "fixtures", "vitals_2100006C.json");
|
|
if (!File.Exists(fixturePath))
|
|
throw new FileNotFoundException($"Vitals fixture not found at: {fixturePath}");
|
|
|
|
var bytes = File.ReadAllBytes(fixturePath);
|
|
// Strip UTF-8 BOM (EF BB BF) if present so JsonSerializer.Deserialize<T>(ReadOnlySpan<byte>)
|
|
// does not reject the first byte.
|
|
ReadOnlySpan<byte> span = bytes;
|
|
if (span.Length >= 3 && span[0] == 0xEF && span[1] == 0xBB && span[2] == 0xBF)
|
|
span = span[3..];
|
|
var root = JsonSerializer.Deserialize<AcDream.App.UI.Layout.ElementInfo>(span, _opts)
|
|
?? throw new InvalidOperationException($"fixture deserialized to null: {fixturePath}");
|
|
|
|
return LayoutImporter.Build(root, _ => (0u, 0, 0), null);
|
|
}
|
|
}
|