Skip to content

Add numeric normalization strategies#24

Merged
mattt merged 5 commits intomainfrom
mattt/number-normalization
Feb 6, 2026
Merged

Add numeric normalization strategies#24
mattt merged 5 commits intomainfrom
mattt/number-normalization

Conversation

@mattt
Copy link
Copy Markdown
Collaborator

@mattt mattt commented Feb 6, 2026

Linked Issue

Alternative to #23

Description

This PR implements JSONEncoder-style numeric strategies on TOONEncoder, adds validation for .throw, updates tests for defaults and custom behavior, and documents the configuration in the README.

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

^ See description

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected: 3. Encoding Normalization (Reference Encoder)
  • Spec version: 3.0.0

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

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 adds configurable numeric normalization strategies to TOONEncoder, providing JSONEncoder-style control over how negative zero and non-conforming floating-point values (NaN, Infinity, -Infinity) are encoded. It implements two separate strategies: NegativeZeroEncodingStrategy (normalize or preserve) and NonConformingFloatEncodingStrategy (null, throw, or convertToString). The changes maintain backward compatibility by keeping the default behaviors that match the TOON specification 3.0.

Changes:

  • Added NegativeZeroEncodingStrategy and NonConformingFloatEncodingStrategy public enums with associated encoding logic
  • Implemented validation function that recursively checks for non-conforming floats when .throw strategy is selected
  • Added tests for default behavior, negative zero preservation, and throw strategy
  • Updated README documentation with usage examples and updated feature description

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
Sources/ToonFormat/Encoder.swift Adds two strategy enums, validation function, and encoding logic for numeric normalization
Tests/ToonFormatTests/EncoderTests.swift Adds tests for new numeric encoding strategies including default behavior and error throwing
README.md Updates canonical number formatting note and adds new section documenting numeric normalization configuration

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

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


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

@mattt mattt merged commit b519ede into main Feb 6, 2026
6 checks passed
@mattt mattt deleted the mattt/number-normalization branch February 6, 2026 14:00
tomritzow

This comment was marked as off-topic.

tomritzow

This comment was marked as off-topic.

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.

3 participants