Skip to content

[10/11] Add len exact-length checker - #236

Merged
cinar merged 1 commit into
mainfrom
p1-10-len
Sep 5, 2026
Merged

[10/11] Add len exact-length checker#236
cinar merged 1 commit into
mainfrom
p1-10-len

Conversation

@cinar

@cinar cinar commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Replaces #233, which GitHub auto-closed (rather than retargeted) when its base branch (p1-09-contains-family) was deleted after #232 merged. Same content, rebased onto current main.

Problem

min-len/max-len exist but there was no single-tag way to require an exact length — phone numbers, fixed-width codes, postal codes.

Fix

Add len, mirroring min_len.go exactly:

  • The generic Len[T any] signature is usable standalone with any Len()-able type, and uses the same v.Len() (byte length, not rune count) semantics already used by min-len/max-len — kept consistent with its siblings rather than introducing a rune-counting discrepancy between the three.
  • Registered in maker.go.
  • Mapped in schema_maker.go to matching Min/Max pairs (MinLength=MaxLength, MinItems=MaxItems, or MinProperties=MaxProperties, depending on kind), since an exact length is just min=max.
  • NOT_LEN message added to all 23 locale files plus en-US.
  • Documented in the README's checker table.

Testing

  • len_test.go: standalone generic usage, string/slice struct-tag valid/invalid, bad-param panic, non-Len()-able-type panic.
  • TestJSONSchemaLenExactLength covering string/slice/map, plus a bad-param panic test.
  • Full suite passes, 100% coverage maintained.
  • go vet, gosec, revive clean.

Fixes #207

🤖 Generated with Claude Code

https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i

min-len/max-len exist but there was no single-tag way to require an
exact length -- phone numbers, fixed-width codes, postal codes.

- len.go mirrors min_len.go exactly, including the generic Len[T any]
  signature usable standalone with any Len()-able type, and the same
  v.Len() (byte length, not rune count) semantics already used by
  min-len/max-len -- kept consistent with its siblings rather than
  introducing a rune-counting discrepancy between the three.
- Registered in maker.go.
- Mapped in schema_maker.go to matching Min/Max pairs (MinLength=
  MaxLength, MinItems=MaxItems, or MinProperties=MaxProperties,
  depending on kind), since an exact length is just min=max.
- NOT_LEN message added to all 23 locale files plus en-US.
- Documented in the README's checker table.

Fixes #207

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ca5b02f) to head (cc57f04).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #236   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        64    +1     
  Lines         1163      1196   +33     
=========================================
+ Hits          1163      1196   +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cinar
cinar merged commit fde13bb into main Sep 5, 2026
8 checks passed
@cinar
cinar deleted the p1-10-len branch September 5, 2026 17:57
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.

Add len checker for exact length

1 participant