Files
OpenNest/OpenNest.IO.Tests/CutFirstPersistenceTests.cs
T
ajandClaude Opus 5.5 42d99f296c feat(sequencing): add per-drawing Cut first priority
Drawings flagged CutFirst (e.g. test squares) are sequenced ahead of
every other part: they get their own route with the chosen method, then
the remaining parts follow. Cutoffs crossing a cut-first part still
precede it. The flag is editable in Edit Drawing, persists in .nest as
`cutFirst` (omitted when false) and is kept by split pieces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 22:19:03 -04:00

39 lines
1.3 KiB
C#

using System.IO.Compression;
using System.Text;
using System.Text.Json.Nodes;
namespace OpenNest.IO.Tests;
public class CutFirstPersistenceTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CutFirst_RoundTrips_AndIsOmittedWhenFalse(bool cutFirst)
{
var drawing = DrawingPackageFixture.Build();
drawing.CutFirst = cutFirst;
var nest = new Nest(drawing.Name);
nest.Drawings.Add(drawing);
using var stream = new MemoryStream();
Assert.True(new NestWriter(nest).Write(stream));
var bytes = stream.ToArray();
var reader = new NestReader(new MemoryStream(bytes));
var copy = Assert.Single(reader.Read().Drawings);
Assert.Empty(reader.Warnings);
Assert.Equal(cutFirst, copy.CutFirst);
var json = DrawingJson(bytes);
Assert.Equal(cutFirst, json.ContainsKey("cutFirst"));
}
private static JsonObject DrawingJson(byte[] archive)
{
using var zip = new ZipArchive(new MemoryStream(archive), ZipArchiveMode.Read);
using var reader = new StreamReader(zip.GetEntry("nest.json")!.Open(), Encoding.UTF8);
var nest = JsonNode.Parse(reader.ReadToEnd())!.AsObject();
return nest["drawings"]!.AsArray().Single()!.AsObject();
}
}