Skip to content

Tests: fstring spec coverage (§15) #503

Closed

Description

@ehartford

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-3570 parses f-string segments and escaped braces.
  • src/Parser.w:3642-3698 parses [[fill]align][sign]['#']['0'][width]['.' precision][mode].
  • src/SemaCheck.w:3643-3692 validates mode/type compatibility, precision, alternate form, and sign rules.
  • test/behavior/behav_fstring_spec.w:5-28 covers integer hex, binary, octal, width, zero padding, sign, and alternate hex.
  • test/behavior/behav_fstring_float_spec.w:5-24 covers 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, and err_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

  1. Add a behavior test test/behavior/behav_fstring_spec_edges.w for implemented f-string formatting edges:
    • escaped braces {{ and }};
    • bare align <, >, ^;
    • custom fill align such as :_>8 and :.<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.
  2. Add missing compile-error tests:
    • numeric mode on string (f"{\"hi\":d}", expecting format mode requires integer type);
    • invalid alternate/sign/precision combinations if not already covered.
  3. 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.
  4. 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.
  5. Update test/coverage_manifest.txt if this project requires manual coverage entries for new spec tests.

Test plan

Acceptance criteria

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

  1. ehartford commented on Jun 11, 2026

    @ehartford
    ContributorAuthor

    Progress note from Phase 1 work: commit b6ed50b fixes a real lexer bug for escaped literal braces where f"{{" and f"{x} {{" were lexed as unterminated interpolation holes. test/behavior/behav_fstring_parser.w now 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.

  2. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

  3. added a commit that references this issue on Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions