Skip to content

feat(phase-16): Complete string.format with width/precision#136

Merged
davydog187 merged 2 commits intomainfrom
phase-16-string-format
Feb 12, 2026
Merged

feat(phase-16): Complete string.format with width/precision#136
davydog187 merged 2 commits intomainfrom
phase-16-string-format

Conversation

@davydog187
Copy link
Contributor

Summary

  • Full format specifier parsing: %[flags][width][.precision]specifier
  • New specifiers: %g/%G (general), %e/%E (scientific), %u (unsigned)
  • Width/precision: %5d, %-10s, %.2f, %05d, %02x
  • Zero-padding with negative numbers handled correctly

Test plan

  • Existing string.format tests pass
  • 16 new tests for width/precision/flags/new specifiers

🤖 Generated with Claude Code

Dave Lucia and others added 2 commits February 12, 2026 06:41
Rewrite string.format to support full Lua 5.3 format specifiers:
- Flags: -, +, space, 0, #
- Width and precision modifiers
- New specifiers: %g, %G, %e, %E, %u

Implements Phase 16 from plan.md
Add 15 property tests covering string.format:

Integer formatting:
- %d produces correct integer strings
- %d truncates floats to integers
- %x produces valid lowercase hex (round-trips through Integer.parse)
- %X produces valid uppercase hex (round-trips through Integer.parse)
- %o produces valid octal (round-trips through Integer.parse)

String/char formatting:
- %s returns the original string
- %c produces single byte for values 0-127
- %% always produces literal percent
- %.ns truncates string to at most n characters

Width/precision:
- Width specifier pads to at least width characters
- Left-justify flag makes result left-aligned
- Zero-pad flag fills with zeros
- %.nf produces exactly n decimal places

Scientific notation:
- %e always contains e+/e- notation
- %E always contains E+/E- notation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davydog187 davydog187 force-pushed the phase-16-string-format branch from 4c6644f to 21ca3f2 Compare February 12, 2026 14:43
@davydog187 davydog187 merged commit 56ef6b2 into main Feb 12, 2026
2 checks passed
@davydog187 davydog187 deleted the phase-16-string-format branch February 12, 2026 15:13
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.

1 participant