feature: Add tests for automatic DATA_END flag insertion

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 <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik 2025-12-14 12:32:05 +01:00
parent ba380723c0
commit d35228e40b

View file

@ -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);
});
});