From 132bb07bc98cf122b8a94bcf577af665486b84a9 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 30 Sep 2026 01:29:11 -0400 Subject: [PATCH] test(editor): make control assertions handle-state independent and order-proving Quality review of 50884da found the unshown RichTextBox oracle compared cached CRLF text against the highlighted editor's native LF-normalized text, which would fail on first Windows execution. Compare generated text with normalized line endings on both sides instead, capture the status label and preview state inside the ProgramChanged handler to prove fallback-before-notify ordering, document the HighlightSpan UTF-16 and rule-index contract, and pin the null-text argument check. --- OpenNest.Core/CNC/ProgramHighlighting.cs | 9 +++++ .../CNC/ProgramHighlightingTests.cs | 5 +++ .../Controls/ProgramEditorControlTests.cs | 39 +++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/OpenNest.Core/CNC/ProgramHighlighting.cs b/OpenNest.Core/CNC/ProgramHighlighting.cs index 1aeffe6..2fda4d7 100644 --- a/OpenNest.Core/CNC/ProgramHighlighting.cs +++ b/OpenNest.Core/CNC/ProgramHighlighting.cs @@ -4,6 +4,15 @@ using System.Text.RegularExpressions; namespace OpenNest.CNC; +/// +/// A character range in generated G-code assigned by one highlighting rule. +/// +/// Zero-based UTF-16 index of the first colored character. +/// Number of UTF-16 characters to color. +/// +/// Zero-based rule index: 0 comments, 1 motion modes (G90/G91), 2 rapid moves (G00), +/// 3 linear moves (G01), 4 arcs (G02/G03). +/// public readonly record struct HighlightSpan(int Index, int Length, int RuleIndex); /// Computes cosmetic G-code highlight spans without changing the generated text. diff --git a/OpenNest.Tests/CNC/ProgramHighlightingTests.cs b/OpenNest.Tests/CNC/ProgramHighlightingTests.cs index c142b55..ee1ebb4 100644 --- a/OpenNest.Tests/CNC/ProgramHighlightingTests.cs +++ b/OpenNest.Tests/CNC/ProgramHighlightingTests.cs @@ -9,6 +9,11 @@ namespace OpenNest.Tests.CNC; public class ProgramHighlightingTests { + [Fact] + public void ComputeSpans_RejectsNullText() + { + Assert.Throws(() => ProgramHighlighting.ComputeSpans(null)); + } [Theory] [InlineData("G00", 2, 3)] [InlineData("G000", -1, 0)] diff --git a/OpenNest.WinForms.Tests/Controls/ProgramEditorControlTests.cs b/OpenNest.WinForms.Tests/Controls/ProgramEditorControlTests.cs index 903a510..a37773b 100644 --- a/OpenNest.WinForms.Tests/Controls/ProgramEditorControlTests.cs +++ b/OpenNest.WinForms.Tests/Controls/ProgramEditorControlTests.cs @@ -44,8 +44,17 @@ public class ProgramEditorControlTests control.Dock = DockStyle.Fill; form.Controls.Add(control); form.Show(); + var status = GetControl