Skip to content

Encode dictionary keys in deterministic order#25

Merged
mattt merged 3 commits intomainfrom
mattt/deterministic-dictionary-ordering
Feb 6, 2026
Merged

Encode dictionary keys in deterministic order#25
mattt merged 3 commits intomainfrom
mattt/deterministic-dictionary-ordering

Conversation

@mattt
Copy link
Copy Markdown
Collaborator

@mattt mattt commented Feb 6, 2026

Linked Issue

Alternative to #22

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Changes Made

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected:
  • Spec version:

Testing

  • All existing tests pass
  • Added new tests for changes
  • Tests cover edge cases and spec compliance

Pre-submission Checklist

  • My code follows the project's coding standards
  • I have run code formatting/linting tools
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed
  • I have reviewed the TOON specification for relevant sections

Breaking Changes

  • No breaking changes
  • Breaking changes (describe migration path below)

Additional Context

@mattt mattt requested a review from Copilot February 6, 2026 13:44
@mattt mattt changed the title Mattt/deterministic dictionary ordering Encode dictionary keys in deterministic order Feb 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to ensure deterministic output when encoding Swift Dictionary values with TOONEncoder, aligning behavior with the linked spec-compliance issue/PR (#22).

Changes:

  • Sort encoded dictionary keys lexicographically to make output deterministic.
  • Add tests to validate deterministic dictionary ordering and to validate the DictionaryCodingKey-based detection heuristic.
  • Document object key ordering behavior in the README.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
Tests/ToonFormatTests/EncoderTests.swift Adds regression tests for deterministic dictionary ordering and the dictionary-key heuristic.
Sources/ToonFormat/Encoder.swift Implements dictionary detection heuristic and uses sorted keys for dictionary encoding.
Sources/ToonFormat/Value.swift Removes unused Value.from(_:) factory logic.
README.md Documents preserved struct field ordering and lexicographic sorting for dictionary keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mattt mattt merged commit e89441e into main Feb 6, 2026
6 checks passed
@mattt mattt deleted the mattt/deterministic-dictionary-ordering branch February 6, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants