A Neovim project exercise fixing a boundary error
On this page
This dependency-free Rust project demonstrates failure, diagnosis, editing, verification and review. Basic conditional logic is sufficient; the focus is connecting editor and project tools.
Install Cargo, Git and Neovim. LSP helps navigation but is not required for basic editing and testing.
Create an isolated project
From a practice directory where editor-lab does not exist:
For the learning configuration, replace the final command with NVIM_APPNAME=nvim-lab nvim src/lib.rs. Run subsequent shell commands from editor-lab.
The requirement is free shipping for an order total of at least 50, otherwise a fee of 5. Replace src/lib.rs with this complete example containing a deliberate boundary bug:
Save with :write. Integer amounts keep currency precision outside this exercise.
Understand the failure first
In another terminal pane:
Two tests should pass and at_threshold should fail: actual 5, expected 0. The program compiles and has no type error, so LSP need not flag the bug.
Read the requirement and assertion before changing code. Follow the test call to the function using LSP or /shipping_fee. The condition total > 50 excludes exactly 50.
Preserve this known failing exercise as a local baseline. In this practice repository only:
After reviewing staged content:
No remote push is involved. If Git lacks an author identity, configure your own identity before continuing.
Make the smallest repair
Replace only the original condition with this line:
if total >= 50
Save, then run the boundary test:
After it passes, run all tests and a format check:
Expect three passing tests and no formatting differences. If formatting fails, check project conventions before running cargo fmt and reviewing its edits.
Connect test execution to the editor
Use another Zellij pane or open :terminal in Neovim. The default terminal-to-normal sequence is Ctrl+\ followed by Ctrl+n; a distribution may add alternatives.
Always check working directory and save state. Cargo reads files on disk, not unsaved buffers. Once the routine is stable, a project justfile can give terminal and editor a shared entry point; see the CLI toolbox.
Review before finishing
The behavioural change should be only > to >=. Explain any whole-file reformatting, line-ending changes or unrelated files before keeping them. Passing tests do not replace diff review.
Stage and commit the repair separately after checking it. The important result is a clear relationship between the failing baseline and the minimal fix.
What a debugger would show
This bug is simple enough to diagnose from tests. For more complex logic, stop at the condition while running at_threshold and inspect total = 50 and the selected branch.
After enabling DAP core and Rust debugging dependencies, use the Rust extra's debuggables entry to select the test target. If no target appears, first ensure Cargo builds it, then inspect adapter, artifacts and debug symbols.
You should be able to explain why valid types did not ensure correct behaviour, why all three boundary tests matter, and which line aligned implementation with the requirement.