Repository navigation
Description
Summary
Add missing positive and negative tests for §15.4 f-string format specifications. Most of the implementation exists: parser support, sema validation, and runtime formatting are wired, but several grammar and validation corners are only manually verified. This issue should close the coverage gap after #438/#440 fix the float formatter.
Spec
§15.4 defines f-string grammar, escaped braces, format spec grammar, fill/align parsing, width, precision, mode validation, and compile-time errors for invalid type/mode combinations (docs/with-specification.md:7611-7805). Key rules from this issue's requirements:
- literal
{and}are written as{{and}}(docs/with-specification.md:7634-7638); - fill is recognized only when followed by
<,>, or^(docs/with-specification.md:7672-7674); - strings support width/alignment and precision truncation (
docs/with-specification.md:7745-7759); - numeric modes on strings are compile-time errors (
docs/with-specification.md:7790-7798).
Current state
src/Parser.w:3465-3570parses f-string segments and escaped braces.src/Parser.w:3642-3698parses[[fill]align][sign]['#']['0'][width]['.' precision][mode].src/SemaCheck.w:3643-3692validates mode/type compatibility, precision, alternate form, and sign rules.test/behavior/behav_fstring_spec.w:5-28covers integer hex, binary, octal, width, zero padding, sign, and alternate hex.test/behavior/behav_fstring_float_spec.w:5-24covers float precision and sign, but not explicit:f/:e(f-string float modes: :e scientific and bare :f (§15.4.4) #440) or the default float bug (Bug: default float display prints 'inf' for most values (§15.4) #438).- Existing negative tests cover several type/mode failures:
err_fstring_spec_float_mode_on_int.w,err_fstring_spec_int_mode_on_float.w,err_fstring_spec_precision_on_int.w,err_fstring_spec_sign_on_str.w, anderr_fstring_spec_str_mode_on_int.w. - Coverage gaps from
out/req-campaign/g09.tsv: brace escaping, fill parsing, align parsing, fill-align rule, fallback parse behavior, and numeric-mode-on-str negative coverage.
Implementation plan
- Add a behavior test
test/behavior/behav_fstring_spec_edges.wfor implemented f-string formatting edges:- escaped braces
{{and}}; - bare align
<,>,^; - custom fill align such as
:_>8and:.<8; - string precision truncation such as
f"{w:.5}"; - fallback parse where a colon belongs to the expression rather than the format spec, if a current valid expression covers that parser branch.
- escaped braces
- Add missing compile-error tests:
- numeric mode on string (
f"{\"hi\":d}", expectingformat mode requires integer type); - invalid alternate/sign/precision combinations if not already covered.
- numeric mode on string (
- After Bug: default float display prints 'inf' for most values (§15.4) #438/f-string float modes: :e scientific and bare :f (§15.4.4) #440, extend float mode coverage to include explicit
:f,:e, and:g. Until then, document those test cases as blocked by the formatter bug rather than checking current wrong output. - If any test reveals a real implementation bug, fix the parser/sema/runtime root cause. Do not weaken the spec or make the coverage accept current wrong behavior.
- Update
test/coverage_manifest.txtif this project requires manual coverage entries for new spec tests.
Test plan
test/behavior/behav_fstring_spec_edges.wwith//! expect-stdout: ok:f"set = {{{42}}}" == "set = {42}";f"{42:<8}",f"{42:>8}",f"{42:^8}";f"{42:_>8}" == "______42";f"{\"hello world\":.5}" == "hello";- string left/right alignment examples from §15.4.5.
test/compile_errors/err_fstring_spec_numeric_mode_on_str.w:f"{\"hi\":d}"expectsformat mode requires integer type.
test/compile_errors/err_fstring_spec_float_mode_on_str.w:f"{\"hi\":f}"expectsformat mode requires float type.
- Add float explicit mode behavior after Bug: default float display prints 'inf' for most values (§15.4) #438/f-string float modes: :e scientific and bare :f (§15.4.4) #440 lands.
Acceptance criteria
- Escaped braces have committed behavior coverage
- Bare align and custom fill+align have committed behavior coverage
- String precision/truncation has committed behavior coverage
- Numeric/float modes on strings are rejected by compile-error tests
- Float mode tests are added once Bug: default float display prints 'inf' for most values (§15.4) #438/f-string float modes: :e scientific and bare :f (§15.4.4) #440 provide correct behavior
-
with build && with build :fixpoint && with build :testpass
Dependencies
Depends on #438 and #440 for complete float-mode coverage. Related to #441 for the nested f-string negative rule.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 15.4.1.11, 15.4.1.20, 15.4.1.21, 15.4.1.28, 15.4.1.29, 15.4.5.2, 15.4.6.2, 15.4.6.3, 15.4.8.4, 15.4.8.5, 15.4.8.6.
Activity
ehartford commentedon Jun 11, 2026
Progress note from Phase 1 work: commit b6ed50b fixes a real lexer bug for escaped literal braces where
f"{{"andf"{x} {{"were lexed as unterminated interpolation holes.test/behavior/behav_fstring_parser.wnow covers standalone{{, standalone}}, interpolation followed by literal{, and the spec example{{{x}}}. Leaving this issue open because its broader f-string spec-edge checklist still includes fill/alignment, string precision, and negative mode coverage.ehartford commentedon Jul 3, 2026
Closing — f-string alignment/fill/string-precision (behav_fstring_spec_edges) + numeric-format-mode-on-str rejection (err_fstring_numeric_mode_on_str) pinned (bfe7865); escaped braces already covered by behav_fstring_parser. §15.
Fix #530 tailrec verifier + coverage-sweep batch 3 (#498 #508 #517 #523