From d35228e40be7766c4221fec8d351344485de20a6 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Sun, 14 Dec 2025 12:32:05 +0100 Subject: [PATCH] feature: Add tests for automatic DATA_END flag insertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added tests to verify the encoder correctly handles pattern termination: - Test that DATA_END flag is added to last stitch even without END flag - Test that DATA_END flag is added when input has explicit END flag This ensures patterns are always properly terminated in PEN format, regardless of whether the input stitches have an END marker. All 29 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/formats/pen/encoder.test.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/formats/pen/encoder.test.ts b/src/formats/pen/encoder.test.ts index 5ecb553..0d7f6cb 100644 --- a/src/formats/pen/encoder.test.ts +++ b/src/formats/pen/encoder.test.ts @@ -601,4 +601,43 @@ describe('encodeStitchesToPen', () => { expect(result.bounds.maxY).toBe(10); // END stitches update bounds (they're not MOVE stitches) }); + + it('should add DATA_END flag to last stitch even without END flag in input', () => { + // Test that the encoder automatically marks the last stitch with DATA_END + // even if the input stitches don't have an END flag + const stitches = [ + [0, 0, STITCH, 0], + [10, 0, STITCH, 0], + [20, 0, STITCH, 0], // Last stitch - NO END flag + ]; + + const result = encodeStitchesToPen(stitches); + const decoded = decodeAllPenStitches(result.penBytes); + + // First two stitches should NOT have DATA_END flag + expect(decoded[0].isDataEnd).toBe(false); + expect(decoded[1].isDataEnd).toBe(false); + + // Last stitch SHOULD have DATA_END flag automatically added + expect(decoded[2].isDataEnd).toBe(true); + expect(decoded[2].x).toBe(20); + expect(decoded[2].y).toBe(0); + }); + + it('should add DATA_END flag when input has explicit END flag', () => { + // Verify that END flag in input also results in DATA_END flag in output + const stitches = [ + [0, 0, STITCH, 0], + [10, 0, STITCH, 0], + [20, 0, STITCH | END, 0], // Explicit END flag + ]; + + const result = encodeStitchesToPen(stitches); + const decoded = decodeAllPenStitches(result.penBytes); + + // Last stitch should have DATA_END flag + expect(decoded[2].isDataEnd).toBe(true); + expect(decoded[2].x).toBe(20); + expect(decoded[2].y).toBe(0); + }); });