Skip to content

feat: add T command (branch on no-substitution)#448

Open
MukundaKatta wants to merge 2 commits into
uutils:mainfrom
MukundaKatta:codex/add-T-command
Open

feat: add T command (branch on no-substitution)#448
MukundaKatta wants to merge 2 commits into
uutils:mainfrom
MukundaKatta:codex/add-T-command

Conversation

@MukundaKatta
Copy link
Copy Markdown
Contributor

Summary

Implements the GNU T LABEL command (issue #395): branch to LABEL if no s/// substitution has succeeded since the last input line was read or the last t/T was taken. It is the inverse of t.

Before:

$ echo a | ./target/release/sed -n 'Tend; p; :end'
sed: <script argument 1>:1:1: error: invalid command code `T'

After:

$ echo a | ./target/release/sed -n 'Tend; p; :end'      # no s/// -> T branches over p
$ echo a | ./target/release/sed -n 's/a/X/; Tend; p; :end'
X                                                        # s/// ran -> T does not branch

Implementation

  • get_cmd_spec: accept T alongside b/t (2 addresses, compile_label_command). Label parsing is already code-agnostic.
  • resolve_branch_targets: include T when converting Label -> BranchTarget.
  • Processor: T branches when !substitution_made; in both the branch and no-branch arms the flag is reset on evaluation, matching t.

Testing

  • cargo test: full suite green (282 unit + 183 integration).
  • cargo clippy --all-targets -- -D warnings and cargo fmt --check: clean.
  • New branch_no_sub_simple (selective branch) and branch_no_sub_clears (proves T clears the substitution flag) integration tests, plus a get_cmd_spec unit test covering b/t/T.

Closes #395

Implements the GNU `T LABEL` command: branch to LABEL if no s///
substitution has succeeded since the last input line was read or the
last t/T was taken. It is the inverse of `t` and shares the same
address and label parsing.

Wires 'T' into get_cmd_spec, resolve_branch_targets, and the processor
branch logic, resetting the substitution flag on evaluation just like
't'. Adds integration tests (simple branch + flag-clear) and a cmd-spec
unit test.

Closes uutils#395
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 42.10526% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.13%. Comparing base (7c6cbf9) to head (8903013).

Files with missing lines Patch % Lines
src/sed/processor.rs 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #448      +/-   ##
==========================================
- Coverage   82.20%   82.13%   -0.08%     
==========================================
  Files          13       13              
  Lines        5542     5559      +17     
  Branches      310      312       +2     
==========================================
+ Hits         4556     4566      +10     
- Misses        983      990       +7     
  Partials        3        3              
Flag Coverage Δ
macos_latest 82.82% <42.10%> (-0.08%) ⬇️
ubuntu_latest 82.92% <42.10%> (-0.08%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

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 T command (branch on no-substitution)

1 participant