mnml-rs 0.2.13

A NvChad-style terminal IDE in Rust — vim or standard editing, LSP, git, and an embedded HTTP client.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
//! Parsing `git diff` output. Right now: per-file *line signs* (added /
//! modified / removed) for the editor gutter, computed from
//! `git diff HEAD --unified=0`. (The diff-*pane* with hunk staging will reuse
//! the fuller hunk parser added later.)

use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::process::Command;

/// The kind of change a gutter sign marks.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SignKind {
    Added,
    Modified,
    Removed,
}

/// Per-file gutter signs, keyed by absolute path. Each `Vec` is sorted by line
/// (0-based). `Added`/`Modified` get one entry per affected line; `Removed` gets
/// one entry on the line just above where lines were deleted.
pub type LineSigns = HashMap<PathBuf, Vec<(usize, SignKind)>>;

/// Compute gutter signs for everything that differs from `HEAD`. Empty (never
/// errors) if `git` is missing, this isn't a repo, or there's no `HEAD` yet.
pub fn line_signs(workspace: &Path) -> LineSigns {
    let Ok(out) = Command::new("git")
        .args(["diff", "HEAD", "--unified=0", "--no-color", "--", "."])
        .current_dir(workspace)
        .output()
    else {
        return LineSigns::new();
    };
    if !out.status.success() {
        return LineSigns::new();
    }
    parse(&String::from_utf8_lossy(&out.stdout), workspace)
}

fn flush(signs: &mut LineSigns, path: &mut Option<PathBuf>, cur: &mut Vec<(usize, SignKind)>) {
    if let Some(p) = path.take() {
        let mut v = std::mem::take(cur);
        v.sort_unstable_by_key(|&(l, _)| l);
        v.dedup();
        if !v.is_empty() {
            signs.insert(p, v);
        }
    } else {
        cur.clear();
    }
}

fn parse(diff: &str, workspace: &Path) -> LineSigns {
    let mut signs: LineSigns = HashMap::new();
    let mut cur: Vec<(usize, SignKind)> = Vec::new();
    let mut cur_path: Option<PathBuf> = None;

    for line in diff.lines() {
        if let Some(rest) = line.strip_prefix("+++ ") {
            // "+++ b/path/to/file" — or "/dev/null" for a deleted file.
            flush(&mut signs, &mut cur_path, &mut cur);
            cur_path = if rest == "/dev/null" {
                None
            } else {
                Some(workspace.join(rest.strip_prefix("b/").unwrap_or(rest)))
            };
        } else if cur_path.is_some()
            && let Some(rest) = line.strip_prefix("@@ ")
        {
            // "@@ -A[,B] +C[,D] @@ …"
            let Some(((_old_start, old_count), (new_start, new_count))) = parse_hunk_header(rest)
            else {
                continue;
            };
            if new_count == 0 {
                // pure deletion: mark the line just above (0-based), clamped.
                let l = new_start.saturating_sub(1).max(1) - 1;
                cur.push((l, SignKind::Removed));
            } else {
                let kind = if old_count == 0 {
                    SignKind::Added
                } else {
                    SignKind::Modified
                };
                for n in 0..new_count {
                    cur.push((new_start.saturating_sub(1) + n, kind));
                }
            }
        }
    }
    flush(&mut signs, &mut cur_path, &mut cur);
    signs
}

/// `"-A[,B] +C[,D] @@ …"` → `((A, B), (C, D))` (counts default to 1).
pub fn parse_hunk_header(s: &str) -> Option<((usize, usize), (usize, usize))> {
    let mut parts = s.split_whitespace();
    let minus = parts.next()?.strip_prefix('-')?;
    let plus = parts.next()?.strip_prefix('+')?;
    let pair = |t: &str| -> Option<(usize, usize)> {
        match t.split_once(',') {
            Some((a, b)) => Some((a.parse().ok()?, b.parse().ok()?)),
            None => Some((t.parse().ok()?, 1)),
        }
    };
    Some((pair(minus)?, pair(plus)?))
}

// ── full hunk parsing (for the diff pane + hunk staging) ───────────────

/// One line inside a hunk.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HunkLine {
    Context(String),
    Added(String),
    Removed(String),
    /// `\ No newline at end of file`.
    NoNewline,
}

/// One `@@ … @@` hunk plus everything `git apply --cached` needs to stage it on
/// its own: the minimal patch is `--- a/{file_rel}\n+++ b/{file_rel}\n{body}`.
#[derive(Debug, Clone)]
pub struct Hunk {
    /// Absolute path of the file this hunk touches.
    pub file: PathBuf,
    /// The diff path (e.g. `src/foo.rs`) — used to rebuild the patch header.
    pub file_rel: String,
    /// The `@@ -a,b +c,d @@ …` line, verbatim (trailing `\n` trimmed) — for display.
    pub header: String,
    /// 1-based start line in the new file (where the editor should jump to).
    pub new_start: usize,
    /// The `+`/`-`/context lines, parsed for display.
    pub lines: Vec<HunkLine>,
    /// The raw hunk text — the `@@ … @@\n` line plus its `+`/`-`/space lines,
    /// verbatim from `git diff` (so `git apply` sees exactly what it expects).
    pub body: String,
}

impl Hunk {
    /// The minimal patch that stages (or, reversed, unstages) just this hunk.
    pub fn patch(&self) -> String {
        format!("--- a/{0}\n+++ b/{0}\n{1}", self.file_rel, self.body)
    }

    /// Count of new-side lines this hunk covers (i.e. its row span in the
    /// edited file). Pure-deletion hunks return 0 — they sit *between* two
    /// rows. Context and Added contribute, Removed and NoNewline don't.
    pub fn new_line_count(&self) -> usize {
        self.lines
            .iter()
            .filter(|l| matches!(l, HunkLine::Context(_) | HunkLine::Added(_)))
            .count()
    }

    /// True when `line_0based` (in the new file's coordinates) sits inside
    /// this hunk's new-side range. Pure-deletion hunks (new_line_count == 0)
    /// match the line *immediately above* the deletion point, mirroring the
    /// gutter sign placement (`SignKind::Removed`).
    pub fn contains_new_line(&self, line_0based: usize) -> bool {
        let start = self.new_start.saturating_sub(1);
        let count = self.new_line_count();
        if count == 0 {
            // Pure deletion: stick the marker on the row above.
            // `new_start` for `+0,0` lands at the deletion's row anchor;
            // diff machinery already biases it to the line above when count
            // is zero (see `line_signs`).
            return line_0based == start;
        }
        line_0based >= start && line_0based < start + count
    }
}

/// Char-level intraline diff between an old line and a new one. Returns the
/// `(start, end)` char indices of the "middle" — the part that differs — in
/// each string. Common prefix and common suffix outside that range are
/// identical and can be rendered dimly so the eye lands on the change.
///
/// Bounds are sane: an unchanged line returns `(len, len)` for both (empty
/// middle at the end), and a line that's entirely changed returns
/// `(0, len)` for both. Char-indexed so callers can split-by-char without
/// worrying about UTF-8 boundaries.
pub fn intraline_diff(old: &str, new: &str) -> ((usize, usize), (usize, usize)) {
    let o: Vec<char> = old.chars().collect();
    let n: Vec<char> = new.chars().collect();
    // common prefix
    let mut p = 0;
    while p < o.len() && p < n.len() && o[p] == n[p] {
        p += 1;
    }
    // common suffix, not running back into the prefix
    let mut s = 0;
    while s < o.len() - p && s < n.len() - p && o[o.len() - 1 - s] == n[n.len() - 1 - s] {
        s += 1;
    }
    ((p, o.len() - s), (p, n.len() - s))
}

/// Find the hunk in `git diff HEAD -- <rel>` whose new-side range contains
/// `line_0based`. `None` when nothing changed at that line.
pub fn peek_hunk_at(workspace: &Path, rel: &str, line_0based: usize) -> Option<Hunk> {
    let hunks = run_diff(workspace, &["diff", "HEAD", "--no-color", "--", rel]);
    hunks.into_iter().find(|h| h.contains_new_line(line_0based))
}

/// `git diff` for a single path (worktree vs index — i.e. unstaged changes).
pub fn diff_file(workspace: &Path, rel: &str) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "--", rel])
}
/// `git diff` for the whole worktree (unstaged changes).
pub fn diff_worktree(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color"])
}
/// `git diff HEAD` — every change vs the last commit (both staged and
/// unstaged combined, plus deleted/renamed/modified files). The
/// diffview-style "show me everything I've touched" entry-point.
pub fn diff_vs_head(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "HEAD", "--no-color"])
}
/// `git diff --cached` — the staged changes (index vs HEAD).
pub fn diff_staged(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "--cached"])
}
/// `git diff --cached -- <rel>` — staged changes for one file.
pub fn diff_staged_file(workspace: &Path, rel: &str) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "--cached", "--", rel])
}
/// Full-context single-file staged diff (`-U99999`).
pub fn diff_staged_file_full(workspace: &Path, rel: &str) -> Vec<Hunk> {
    run_diff(
        workspace,
        &["diff", "--no-color", "--cached", "-U99999", "--", rel],
    )
}
/// `git show <hash>` — the diff a commit introduced (read-only; the hunks here
/// can't be staged — they're history).
pub fn show_commit(workspace: &Path, hash: &str) -> Vec<Hunk> {
    run_diff(workspace, &["show", "--no-color", "--format=", hash])
}

/// `git show <hash> -- <rel_path>` — the diff for just one file inside a
/// commit (read-only). Use to surface a single file's contribution to a
/// commit without scrolling the full multi-file diff.
pub fn show_commit_file(workspace: &Path, hash: &str, rel_path: &str) -> Vec<Hunk> {
    run_diff(
        workspace,
        &["show", "--no-color", "--format=", hash, "--", rel_path],
    )
}

/// Full-file-context variants — used by the Split side-by-side
/// view, which needs every untouched line (not just 3 context
/// rows) to show the whole before/after of the file. `-U99999`
/// asks git for a context window large enough to cover any
/// realistic file; git happily clamps to file length.
pub fn diff_file_full(workspace: &Path, rel: &str) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "-U99999", "--", rel])
}
pub fn diff_worktree_full(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "-U99999"])
}
pub fn diff_vs_head_full(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "HEAD", "--no-color", "-U99999"])
}
pub fn diff_staged_full(workspace: &Path) -> Vec<Hunk> {
    run_diff(workspace, &["diff", "--no-color", "--cached", "-U99999"])
}
pub fn show_commit_full(workspace: &Path, hash: &str) -> Vec<Hunk> {
    run_diff(
        workspace,
        &["show", "--no-color", "--format=", "-U99999", hash],
    )
}
pub fn show_commit_file_full(workspace: &Path, hash: &str, rel_path: &str) -> Vec<Hunk> {
    run_diff(
        workspace,
        &[
            "show",
            "--no-color",
            "--format=",
            "-U99999",
            hash,
            "--",
            rel_path,
        ],
    )
}

fn run_diff(workspace: &Path, args: &[&str]) -> Vec<Hunk> {
    let Ok(out) = Command::new("git")
        .args(args)
        .current_dir(workspace)
        .output()
    else {
        return Vec::new();
    };
    if !out.status.success() {
        return Vec::new();
    }
    parse_hunks(&String::from_utf8_lossy(&out.stdout), workspace)
}

/// Discard a single hunk's changes against the working tree —
/// reverse-applies the hunk WITHOUT `--cached`, so the worktree file
/// reverts. Destructive; callers should confirm before invoking.
pub fn discard_hunk(workspace: &Path, hunk: &Hunk) -> Result<(), String> {
    use std::io::Write;
    let args = ["apply", "--unidiff-zero", "--reverse", "-"];
    let mut child = Command::new("git")
        .args(args)
        .current_dir(workspace)
        .stdin(std::process::Stdio::piped())
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::piped())
        .spawn()
        .map_err(|e| format!("spawn git apply: {e}"))?;
    child
        .stdin
        .take()
        .ok_or("no stdin")?
        .write_all(hunk.patch().as_bytes())
        .map_err(|e| format!("write patch: {e}"))?;
    let out = child
        .wait_with_output()
        .map_err(|e| format!("git apply: {e}"))?;
    if out.status.success() {
        Ok(())
    } else {
        Err(String::from_utf8_lossy(&out.stderr).trim().to_string())
    }
}

/// Stage (`reverse == false`) or unstage (`reverse == true`) a single hunk.
pub fn apply_hunk(workspace: &Path, hunk: &Hunk, reverse: bool) -> Result<(), String> {
    use std::io::Write;
    let mut args = vec!["apply", "--cached", "--unidiff-zero"];
    if reverse {
        args.push("--reverse");
    }
    args.push("-");
    let mut child = Command::new("git")
        .args(&args)
        .current_dir(workspace)
        .stdin(std::process::Stdio::piped())
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::piped())
        .spawn()
        .map_err(|e| format!("spawn git apply: {e}"))?;
    child
        .stdin
        .take()
        .ok_or("no stdin")?
        .write_all(hunk.patch().as_bytes())
        .map_err(|e| format!("write patch: {e}"))?;
    let out = child
        .wait_with_output()
        .map_err(|e| format!("git apply: {e}"))?;
    if out.status.success() {
        Ok(())
    } else {
        Err(String::from_utf8_lossy(&out.stderr).trim().to_string())
    }
}

/// Parse a full unified `git diff` into hunks. Robust to missing files
/// (`/dev/null`), which it just skips.
pub fn parse_hunks(diff: &str, workspace: &Path) -> Vec<Hunk> {
    // Index byte offsets of every line start so raw slices stay verbatim.
    let mut starts = vec![0usize];
    for (i, b) in diff.bytes().enumerate() {
        if b == b'\n' {
            starts.push(i + 1);
        }
    }
    let line_at = |k: usize| -> &str {
        let a = starts[k];
        let b = starts.get(k + 1).copied().unwrap_or(diff.len());
        &diff[a..b]
    };
    let n = starts.len();

    let mut hunks: Vec<Hunk> = Vec::new();
    let mut file_rel: Option<String> = None;
    // Open hunk being accumulated: (file_rel, header_line, new_start, start_line_index, parsed lines).
    let mut open: Option<(String, String, usize, usize, Vec<HunkLine>)> = None;

    let flush = |hunks: &mut Vec<Hunk>,
                 open: &mut Option<(String, String, usize, usize, Vec<HunkLine>)>,
                 end_line: usize| {
        if let Some((rel, header, new_start, start_k, lines)) = open.take() {
            let body = diff[starts[start_k]..starts.get(end_line).copied().unwrap_or(diff.len())]
                .to_string();
            hunks.push(Hunk {
                file: workspace.join(&rel),
                file_rel: rel,
                header,
                new_start,
                lines,
                body,
            });
        }
    };

    for k in 0..n {
        let line = line_at(k).trim_end_matches(['\n', '\r']);
        if line.starts_with("diff --git ") {
            flush(&mut hunks, &mut open, k);
            file_rel = None;
        } else if let Some(rest) = line.strip_prefix("+++ ") {
            if rest != "/dev/null" {
                file_rel = Some(rest.strip_prefix("b/").unwrap_or(rest).to_string());
            }
        } else if line.starts_with("@@ ") {
            flush(&mut hunks, &mut open, k);
            if let (Some(rel), Some(after)) = (file_rel.clone(), line.strip_prefix("@@ ")) {
                let new_start = parse_hunk_header(after)
                    .map(|(_, (c, _))| c)
                    .unwrap_or(1)
                    .max(1);
                open = Some((rel, line.to_string(), new_start, k, Vec::new()));
            }
        } else if let Some((_, _, _, _, lines)) = open.as_mut() {
            // a hunk line: ' ' context, '+' added, '-' removed, '\' no-newline
            match line.as_bytes().first() {
                Some(b' ') => lines.push(HunkLine::Context(line[1..].to_string())),
                Some(b'+') => lines.push(HunkLine::Added(line[1..].to_string())),
                Some(b'-') => lines.push(HunkLine::Removed(line[1..].to_string())),
                Some(b'\\') => lines.push(HunkLine::NoNewline),
                _ => {} // blank line within a zero-context diff, or stray — ignore
            }
        }
    }
    flush(&mut hunks, &mut open, n);
    hunks
}

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

    #[test]
    fn parses_added_modified_removed() {
        let ws = Path::new("/repo");
        let diff = "\
diff --git a/foo.rs b/foo.rs
index e69de29..1234567 100644
--- a/foo.rs
+++ b/foo.rs
@@ -0,0 +1,2 @@
+line one
+line two
@@ -10 +12,1 @@
-old
+new
@@ -20,2 +22,0 @@
-gone a
-gone b
";
        let s = parse(diff, ws);
        let v = s.get(&ws.join("foo.rs")).unwrap();
        // added: new lines 1,2 (1-based) → 0-based 0,1
        assert!(v.contains(&(0, SignKind::Added)));
        assert!(v.contains(&(1, SignKind::Added)));
        // modified: new line 12 (1-based) → 0-based 11
        assert!(v.contains(&(11, SignKind::Modified)));
        // removed: deletion at new line 22 (1-based) → marker around 0-based 20
        assert!(v.iter().any(|&(_, k)| k == SignKind::Removed));
        // sorted
        assert!(v.windows(2).all(|w| w[0].0 <= w[1].0));
    }

    #[test]
    fn dev_null_target_skipped() {
        let ws = Path::new("/repo");
        let diff = "\
diff --git a/del.txt b/del.txt
--- a/del.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-a
-b
-c
";
        let s = parse(diff, ws);
        assert!(s.is_empty());
    }

    #[test]
    fn parse_hunks_splits_files_and_hunks() {
        let ws = Path::new("/repo");
        let diff = "\
diff --git a/src/a.rs b/src/a.rs
index 111..222 100644
--- a/src/a.rs
+++ b/src/a.rs
@@ -1,3 +1,4 @@
 fn main() {
-    old();
+    new();
+    extra();
 }
diff --git a/b.txt b/b.txt
--- a/b.txt
+++ b/b.txt
@@ -5 +5 @@
-x
+y
";
        let hs = parse_hunks(diff, ws);
        assert_eq!(hs.len(), 2);
        assert_eq!(hs[0].file, ws.join("src/a.rs"));
        assert_eq!(hs[0].file_rel, "src/a.rs");
        assert_eq!(hs[0].new_start, 1);
        assert!(hs[0].header.starts_with("@@ -1,3 +1,4 @@"));
        assert!(matches!(hs[0].lines[0], HunkLine::Context(_)));
        assert!(matches!(hs[0].lines[1], HunkLine::Removed(_)));
        assert!(matches!(hs[0].lines[2], HunkLine::Added(_)));
        // the patch we'd hand to `git apply` reconstructs the file header.
        let patch = hs[0].patch();
        assert!(patch.starts_with("--- a/src/a.rs\n+++ b/src/a.rs\n@@ -1,3 +1,4 @@"));
        assert!(patch.contains("+    new();\n"));
        assert_eq!(hs[1].file_rel, "b.txt");
        assert_eq!(hs[1].new_start, 5);
    }

    #[test]
    fn contains_new_line_modified() {
        let ws = Path::new("/repo");
        let diff = "\
diff --git a/a.rs b/a.rs
--- a/a.rs
+++ b/a.rs
@@ -10,2 +10,3 @@
 ctx
-old
+new
+extra
";
        let hs = parse_hunks(diff, ws);
        let h = &hs[0];
        // new-side range is lines 10..=12 (1-based) ⇒ 9..=11 (0-based).
        assert_eq!(h.new_line_count(), 3);
        assert!(!h.contains_new_line(8));
        assert!(h.contains_new_line(9));
        assert!(h.contains_new_line(11));
        assert!(!h.contains_new_line(12));
    }

    #[test]
    fn intraline_diff_basic_cases() {
        // Identical lines → empty middle at the end.
        let ((a, b), (c, d)) = intraline_diff("hello", "hello");
        assert_eq!((a, b), (5, 5));
        assert_eq!((c, d), (5, 5));
        // One-char tail differs.
        let ((a, b), (c, d)) = intraline_diff("hello!", "hello?");
        assert_eq!(&"hello!"[..a].chars().count(), &5);
        assert_eq!(b - a, 1);
        assert_eq!(d - c, 1);
        // Middle differs, common prefix + suffix.
        let ((a, b), (c, d)) = intraline_diff("fn foo()", "fn bar()");
        // both have `fn ` prefix (3 chars) and `()` suffix (2 chars)
        assert_eq!(a, 3);
        assert_eq!(b, 6);
        assert_eq!(c, 3);
        assert_eq!(d, 6);
        // Entirely different.
        let ((a, b), (c, d)) = intraline_diff("abc", "xyz");
        assert_eq!((a, b), (0, 3));
        assert_eq!((c, d), (0, 3));
    }

    #[test]
    fn contains_new_line_pure_deletion_sticks_to_anchor() {
        let ws = Path::new("/repo");
        let diff = "\
diff --git a/a.rs b/a.rs
--- a/a.rs
+++ b/a.rs
@@ -20,2 +19,0 @@
-gone a
-gone b
";
        let hs = parse_hunks(diff, ws);
        let h = &hs[0];
        assert_eq!(h.new_line_count(), 0);
        // new_start = 19 (1-based) ⇒ 0-based 18 — the row right above the deletion.
        assert!(h.contains_new_line(18));
        assert!(!h.contains_new_line(17));
        assert!(!h.contains_new_line(19));
    }
}