---
title: A Neovim project exercise fixing a boundary error
url: https://doc.liz6.com/en/tools/nvim/05-project-workflow
locale: en
area: tools
tags:
- Neovim
- Developer tools
date: 2026-09-15
modified: 2026-09-15
description: Follow a small Rust shipping-fee function through failing tests, navigation, a minimal fix, formatting checks and Git review.
---

# A Neovim project exercise fixing a boundary error

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:

```bash
cargo new --lib --vcs git editor-lab
cd editor-lab
nvim src/lib.rs
```

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:

```rust
pub fn shipping_fee(total: u32) -> u32 {
    if total > 50 {
        0
    } else {
        5
    }
}

#[cfg(test)]
mod tests {
    use super::shipping_fee;

    #[test]
    fn below_threshold() {
        assert_eq!(shipping_fee(49), 5);
    }

    #[test]
    fn at_threshold() {
        assert_eq!(shipping_fee(50), 0);
    }

    #[test]
    fn above_threshold() {
        assert_eq!(shipping_fee(51), 0);
    }
}
```

Save with `:write`. Integer amounts keep currency precision outside this exercise.

## Understand the failure first

In another terminal pane:

```bash
cargo test
```

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:

```bash
git add Cargo.toml Cargo.lock src/lib.rs .gitignore
git diff --cached
```

After reviewing staged content:

```bash
git commit -m 'Add shipping fee boundary exercise'
```

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:

```rust
if total >= 50 {
```

Save, then run the boundary test:

```bash
cargo test at_threshold
```

After it passes, run all tests and a format check:

```bash
cargo test
cargo fmt --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](../cli-toolbox.md).

## Review before finishing

```bash
git diff -- src/lib.rs
git diff --check
git status --short
```

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.
