perspt-tui 0.5.8

Ratatui-based TUI for Perspt
Documentation
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
//! Diff Viewer Component
//!
//! Rich diff display with syntax highlighting and line numbers.

use crate::theme::Theme;
use ratatui::{
    layout::{Constraint, Direction, Layout, Rect},
    style::{Color, Modifier, Style},
    text::{Line, Span},
    widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, Tabs},
    Frame,
};
use similar::{ChangeTag, TextDiff};

/// Display mode for diffs
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DiffViewMode {
    #[default]
    Unified,
    SideBySide,
}

/// A single diff hunk
#[derive(Debug, Clone)]
pub struct DiffHunk {
    /// Original file path
    pub file_path: String,
    /// File extension (for syntax highlighting)
    pub extension: Option<String>,
    /// Lines with change type
    pub lines: Vec<DiffLine>,
    /// Original line number start
    pub old_start: usize,
    /// New line number start
    pub new_start: usize,
    /// Operation label (e.g. "created", "modified")
    pub operation: Option<String>,
}

/// A diff line with its type
#[derive(Debug, Clone)]
pub struct DiffLine {
    /// Line content
    pub content: String,
    /// Line type
    pub line_type: DiffLineType,
    /// Old line number (if applicable)
    pub old_line_number: Option<usize>,
    /// New line number (if applicable)
    pub new_line_number: Option<usize>,
}

/// Type of diff line
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiffLineType {
    /// Unchanged context line
    Context,
    /// Added line
    Added,
    /// Removed line
    Removed,
    /// Header line (file path, etc.)
    Header,
    /// Hunk header (@@...@@)
    HunkHeader,
}

impl DiffLine {
    pub fn new(content: &str, line_type: DiffLineType) -> Self {
        Self {
            content: content.to_string(),
            line_type,
            old_line_number: None,
            new_line_number: None,
        }
    }

    pub fn with_line_numbers(
        content: &str,
        line_type: DiffLineType,
        old: Option<usize>,
        new: Option<usize>,
    ) -> Self {
        Self {
            content: content.to_string(),
            line_type,
            old_line_number: old,
            new_line_number: new,
        }
    }
}

/// Enhanced diff viewer with syntax highlighting
pub struct DiffViewer {
    /// Diff hunks to display
    pub hunks: Vec<DiffHunk>,
    /// Current scroll offset
    pub scroll: usize,
    /// Currently selected hunk index
    pub selected_hunk: usize,
    /// View mode
    pub view_mode: DiffViewMode,
    /// Theme for styling
    theme: Theme,
    /// Total line count (cached for scrolling)
    total_lines: usize,
    /// Bundle summary header (node id, file counts)
    pub bundle_summary: Option<BundleSummary>,
}

/// Summary of a node bundle displayed as a header
#[derive(Debug, Clone, Default)]
pub struct BundleSummary {
    /// Node identifier
    pub node_id: String,
    /// Node class (Interface, Implementation, etc.)
    pub node_class: String,
    /// Number of files created
    pub files_created: usize,
    /// Number of files modified
    pub files_modified: usize,
    /// Write operation count
    pub writes_count: usize,
    /// Diff operation count
    pub diffs_count: usize,
}

impl Default for DiffViewer {
    fn default() -> Self {
        Self {
            hunks: Vec::new(),
            scroll: 0,
            selected_hunk: 0,
            view_mode: DiffViewMode::Unified,
            theme: Theme::default(),
            total_lines: 0,
            bundle_summary: None,
        }
    }
}

impl DiffViewer {
    /// Create a new diff viewer
    pub fn new() -> Self {
        Self::default()
    }

    /// Compute diff between two strings using `similar`
    pub fn compute_diff(&mut self, file_path: &str, old_content: &str, new_content: &str) {
        self.hunks.clear();

        let diff = TextDiff::from_lines(old_content, new_content);
        let extension = file_path.rsplit('.').next().map(String::from);

        let mut current_hunk = DiffHunk {
            file_path: file_path.to_string(),
            extension: extension.clone(),
            lines: vec![DiffLine::new(
                &format!("diff --git a/{} b/{}", file_path, file_path),
                DiffLineType::Header,
            )],
            old_start: 1,
            new_start: 1,
            operation: None,
        };

        let mut old_line = 1usize;
        let mut new_line = 1usize;

        for change in diff.iter_all_changes() {
            let (line_type, old_num, new_num) = match change.tag() {
                ChangeTag::Delete => {
                    let num = old_line;
                    old_line += 1;
                    (DiffLineType::Removed, Some(num), None)
                }
                ChangeTag::Insert => {
                    let num = new_line;
                    new_line += 1;
                    (DiffLineType::Added, None, Some(num))
                }
                ChangeTag::Equal => {
                    let o = old_line;
                    let n = new_line;
                    old_line += 1;
                    new_line += 1;
                    (DiffLineType::Context, Some(o), Some(n))
                }
            };

            // Remove trailing newline for display
            let content = change.value().trim_end_matches('\n');
            current_hunk.lines.push(DiffLine::with_line_numbers(
                content, line_type, old_num, new_num,
            ));
        }

        if !current_hunk.lines.is_empty() {
            self.hunks.push(current_hunk);
        }

        self.update_total_lines();
    }

    /// Parse a unified diff string
    pub fn parse_diff(&mut self, diff_text: &str) {
        self.hunks.clear();
        let mut current_hunk: Option<DiffHunk> = None;
        let mut old_line = 1usize;
        let mut new_line = 1usize;

        for line in diff_text.lines() {
            if line.starts_with("diff --git") {
                if let Some(hunk) = current_hunk.take() {
                    self.hunks.push(hunk);
                }
                let file_path = line.split(" b/").nth(1).unwrap_or("unknown").to_string();
                let extension = file_path.rsplit('.').next().map(String::from);
                current_hunk = Some(DiffHunk {
                    file_path,
                    extension,
                    lines: vec![DiffLine::new(line, DiffLineType::Header)],
                    old_start: 1,
                    new_start: 1,
                    operation: None,
                });
                old_line = 1;
                new_line = 1;
            } else if line.starts_with("---") || line.starts_with("+++") {
                if let Some(ref mut hunk) = current_hunk {
                    hunk.lines.push(DiffLine::new(line, DiffLineType::Header));
                }
            } else if line.starts_with("@@") {
                // Parse hunk header to get line numbers
                if let Some(ref mut hunk) = current_hunk {
                    hunk.lines
                        .push(DiffLine::new(line, DiffLineType::HunkHeader));
                    // Parse @@ -old_start,old_count +new_start,new_count @@
                    if let Some(nums) = parse_hunk_header(line) {
                        old_line = nums.0;
                        new_line = nums.2;
                        hunk.old_start = nums.0;
                        hunk.new_start = nums.2;
                    }
                }
            } else if let Some(ref mut hunk) = current_hunk {
                let (line_type, old_num, new_num) = if line.starts_with('+') {
                    let n = new_line;
                    new_line += 1;
                    (DiffLineType::Added, None, Some(n))
                } else if line.starts_with('-') {
                    let o = old_line;
                    old_line += 1;
                    (DiffLineType::Removed, Some(o), None)
                } else {
                    let o = old_line;
                    let n = new_line;
                    old_line += 1;
                    new_line += 1;
                    (DiffLineType::Context, Some(o), Some(n))
                };

                // Remove the +/- or space prefix for display
                let content = if line.len() > 1
                    && (line.starts_with('+') || line.starts_with('-') || line.starts_with(' '))
                {
                    &line[1..]
                } else {
                    line
                };

                hunk.lines.push(DiffLine::with_line_numbers(
                    content, line_type, old_num, new_num,
                ));
            }
        }

        if let Some(hunk) = current_hunk {
            self.hunks.push(hunk);
        }

        self.update_total_lines();
    }

    /// Clear all diffs
    pub fn clear(&mut self) {
        self.hunks.clear();
        self.scroll = 0;
        self.selected_hunk = 0;
        self.total_lines = 0;
        self.bundle_summary = None;
    }

    fn update_total_lines(&mut self) {
        self.total_lines = self.hunks.iter().map(|h| h.lines.len()).sum();
    }

    /// Toggle view mode
    pub fn toggle_view_mode(&mut self) {
        self.view_mode = match self.view_mode {
            DiffViewMode::Unified => DiffViewMode::SideBySide,
            DiffViewMode::SideBySide => DiffViewMode::Unified,
        };
    }

    /// Scroll up
    pub fn scroll_up(&mut self) {
        self.scroll = self.scroll.saturating_sub(1);
    }

    /// Scroll down
    pub fn scroll_down(&mut self) {
        self.scroll = self.scroll.saturating_add(1);
    }

    /// Page up
    pub fn page_up(&mut self, lines: usize) {
        self.scroll = self.scroll.saturating_sub(lines);
    }

    /// Page down
    pub fn page_down(&mut self, lines: usize) {
        self.scroll = self.scroll.saturating_add(lines);
    }

    /// Next hunk
    pub fn next_hunk(&mut self) {
        if self.selected_hunk < self.hunks.len().saturating_sub(1) {
            self.selected_hunk += 1;
            // Scroll to show the hunk
            let mut line_offset = 0;
            for i in 0..self.selected_hunk {
                line_offset += self.hunks[i].lines.len();
            }
            self.scroll = line_offset;
        }
    }

    /// Previous hunk
    pub fn prev_hunk(&mut self) {
        if self.selected_hunk > 0 {
            self.selected_hunk -= 1;
            let mut line_offset = 0;
            for i in 0..self.selected_hunk {
                line_offset += self.hunks[i].lines.len();
            }
            self.scroll = line_offset;
        }
    }

    /// Render the diff viewer
    pub fn render(&self, frame: &mut Frame, area: Rect) {
        let chunks = Layout::default()
            .direction(Direction::Vertical)
            .constraints([Constraint::Length(3), Constraint::Min(5)])
            .split(area);

        // Tabs for view mode
        let tab_titles = vec!["Unified", "Side-by-Side"];
        let tabs = Tabs::new(tab_titles)
            .block(
                Block::default()
                    .borders(Borders::ALL)
                    .title("View Mode")
                    .border_style(self.theme.border),
            )
            .select(match self.view_mode {
                DiffViewMode::Unified => 0,
                DiffViewMode::SideBySide => 1,
            })
            .style(Style::default().fg(Color::White))
            .highlight_style(self.theme.highlight);
        frame.render_widget(tabs, chunks[0]);

        // Diff content
        match self.view_mode {
            DiffViewMode::Unified => self.render_unified(frame, chunks[1]),
            DiffViewMode::SideBySide => self.render_side_by_side(frame, chunks[1]),
        }
    }

    fn render_unified(&self, frame: &mut Frame, area: Rect) {
        let mut lines: Vec<Line> = Vec::new();

        // Bundle summary header
        if let Some(ref summary) = self.bundle_summary {
            lines.push(Line::from(vec![
                Span::styled("  Node: ", Style::default().fg(Color::DarkGray)),
                Span::styled(
                    &summary.node_id,
                    Style::default()
                        .fg(Color::Rgb(129, 212, 250))
                        .add_modifier(Modifier::BOLD),
                ),
                Span::styled(
                    format!("  [{}]", summary.node_class),
                    Style::default().fg(Color::Rgb(179, 157, 219)),
                ),
            ]));
            lines.push(Line::from(vec![Span::styled(
                format!(
                    "  {} created, {} modified — {} writes, {} diffs",
                    summary.files_created,
                    summary.files_modified,
                    summary.writes_count,
                    summary.diffs_count
                ),
                Style::default().fg(Color::Rgb(158, 158, 158)),
            )]));
            lines.push(Line::from(""));
        }

        for (hunk_idx, hunk) in self.hunks.iter().enumerate() {
            // Per-file operation label
            if let Some(ref op) = hunk.operation {
                let op_color = match op.as_str() {
                    "created" => Color::Rgb(102, 187, 106),
                    "modified" => Color::Rgb(255, 183, 77),
                    _ => Color::White,
                };
                lines.push(Line::from(vec![
                    Span::styled(
                        format!("  {} ", op),
                        Style::default().fg(op_color).add_modifier(Modifier::BOLD),
                    ),
                    Span::styled(
                        &hunk.file_path,
                        Style::default().fg(Color::Rgb(129, 212, 250)),
                    ),
                ]));
            }

            for line in &hunk.lines {
                let (fg_color, bg_color, prefix) = match line.line_type {
                    DiffLineType::Added => {
                        (Color::Rgb(200, 255, 200), Some(Color::Rgb(30, 50, 30)), "+")
                    }
                    DiffLineType::Removed => {
                        (Color::Rgb(255, 200, 200), Some(Color::Rgb(50, 30, 30)), "-")
                    }
                    DiffLineType::Header => (Color::Rgb(129, 212, 250), None, " "),
                    DiffLineType::HunkHeader => {
                        (Color::Rgb(186, 104, 200), Some(Color::Rgb(40, 30, 50)), " ")
                    }
                    DiffLineType::Context => (Color::Rgb(180, 180, 180), None, " "),
                };

                let line_nums = match (line.old_line_number, line.new_line_number) {
                    (Some(o), Some(n)) => format!("{:>4} {:>4} ", o, n),
                    (Some(o), None) => format!("{:>4}      ", o),
                    (None, Some(n)) => format!("     {:>4} ", n),
                    (None, None) => "          ".to_string(),
                };

                let mut spans = vec![
                    Span::styled(line_nums, Style::default().fg(Color::Rgb(100, 100, 100))),
                    Span::styled(format!("{} ", prefix), Style::default().fg(fg_color)),
                ];

                let content_style = if hunk_idx == self.selected_hunk {
                    Style::default().fg(fg_color).add_modifier(Modifier::BOLD)
                } else {
                    Style::default().fg(fg_color)
                };

                let content_style = if let Some(bg) = bg_color {
                    content_style.bg(bg)
                } else {
                    content_style
                };

                spans.push(Span::styled(&line.content, content_style));
                lines.push(Line::from(spans));
            }
        }

        let visible_lines = area.height.saturating_sub(2) as usize;
        let max_scroll = self.total_lines.saturating_sub(visible_lines);
        let scroll = self.scroll.min(max_scroll);

        let stats = self.compute_stats();
        let title = format!(
            "📝 Diff: {} files, +{} -{} ({} hunks)",
            self.hunks.len(),
            stats.additions,
            stats.deletions,
            self.hunks.len()
        );

        let para = Paragraph::new(lines)
            .block(
                Block::default()
                    .title(title)
                    .borders(Borders::ALL)
                    .border_style(self.theme.border),
            )
            .scroll((scroll as u16, 0));

        frame.render_widget(para, area);

        // Scrollbar
        let scrollbar = Scrollbar::default()
            .orientation(ScrollbarOrientation::VerticalRight)
            .begin_symbol(Some(""))
            .end_symbol(Some(""));
        let mut scrollbar_state = ScrollbarState::new(self.total_lines).position(scroll);
        frame.render_stateful_widget(scrollbar, area, &mut scrollbar_state);
    }

    fn render_side_by_side(&self, frame: &mut Frame, area: Rect) {
        // Split into two columns
        let columns = Layout::default()
            .direction(Direction::Horizontal)
            .constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
            .split(area);

        // Left side (old)
        let old_lines: Vec<Line> = self
            .hunks
            .iter()
            .flat_map(|hunk| {
                hunk.lines.iter().filter_map(|line| {
                    match line.line_type {
                        DiffLineType::Removed | DiffLineType::Context => {
                            let num = line
                                .old_line_number
                                .map(|n| format!("{:>4} ", n))
                                .unwrap_or_else(|| "     ".to_string());
                            let style = match line.line_type {
                                DiffLineType::Removed => Style::default()
                                    .fg(Color::Rgb(255, 200, 200))
                                    .bg(Color::Rgb(50, 30, 30)),
                                _ => Style::default().fg(Color::Rgb(180, 180, 180)),
                            };
                            Some(Line::from(vec![
                                Span::styled(num, Style::default().fg(Color::Rgb(100, 100, 100))),
                                Span::styled(&line.content, style),
                            ]))
                        }
                        DiffLineType::Added => Some(Line::from("")), // Empty placeholder
                        _ => None,
                    }
                })
            })
            .collect();

        // Right side (new)
        let new_lines: Vec<Line> = self
            .hunks
            .iter()
            .flat_map(|hunk| {
                hunk.lines.iter().filter_map(|line| {
                    match line.line_type {
                        DiffLineType::Added | DiffLineType::Context => {
                            let num = line
                                .new_line_number
                                .map(|n| format!("{:>4} ", n))
                                .unwrap_or_else(|| "     ".to_string());
                            let style = match line.line_type {
                                DiffLineType::Added => Style::default()
                                    .fg(Color::Rgb(200, 255, 200))
                                    .bg(Color::Rgb(30, 50, 30)),
                                _ => Style::default().fg(Color::Rgb(180, 180, 180)),
                            };
                            Some(Line::from(vec![
                                Span::styled(num, Style::default().fg(Color::Rgb(100, 100, 100))),
                                Span::styled(&line.content, style),
                            ]))
                        }
                        DiffLineType::Removed => Some(Line::from("")), // Empty placeholder
                        _ => None,
                    }
                })
            })
            .collect();

        let visible = area.height.saturating_sub(2) as usize;
        let scroll = self.scroll.min(old_lines.len().saturating_sub(visible));

        let old_para = Paragraph::new(old_lines)
            .block(Block::default().title("Old").borders(Borders::ALL))
            .scroll((scroll as u16, 0));
        frame.render_widget(old_para, columns[0]);

        let new_para = Paragraph::new(new_lines)
            .block(Block::default().title("New").borders(Borders::ALL))
            .scroll((scroll as u16, 0));
        frame.render_widget(new_para, columns[1]);
    }

    /// Compute diff statistics
    fn compute_stats(&self) -> DiffStats {
        let mut stats = DiffStats::default();
        for hunk in &self.hunks {
            for line in &hunk.lines {
                match line.line_type {
                    DiffLineType::Added => stats.additions += 1,
                    DiffLineType::Removed => stats.deletions += 1,
                    _ => {}
                }
            }
        }
        stats
    }
}

/// Parse hunk header like "@@ -1,5 +1,7 @@"
fn parse_hunk_header(line: &str) -> Option<(usize, usize, usize, usize)> {
    let parts: Vec<&str> = line.split_whitespace().collect();
    if parts.len() < 3 {
        return None;
    }

    let old_range = parts.get(1)?;
    let new_range = parts.get(2)?;

    let parse_range = |s: &str| -> Option<(usize, usize)> {
        let s = s.trim_start_matches(['-', '+'].as_ref());
        let parts: Vec<&str> = s.split(',').collect();
        let start = parts.first()?.parse().ok()?;
        let count = parts.get(1).and_then(|s| s.parse().ok()).unwrap_or(1);
        Some((start, count))
    };

    let (old_start, old_count) = parse_range(old_range)?;
    let (new_start, new_count) = parse_range(new_range)?;

    Some((old_start, old_count, new_start, new_count))
}

#[derive(Default)]
struct DiffStats {
    additions: usize,
    deletions: usize,
}

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

    #[test]
    fn test_compute_diff() {
        let mut viewer = DiffViewer::new();
        viewer.compute_diff(
            "test.rs",
            "line1\nline2\nline3\n",
            "line1\nmodified\nline3\nnew line\n",
        );

        assert_eq!(viewer.hunks.len(), 1);
        // Should have some added and removed lines
        let stats = viewer.compute_stats();
        assert!(stats.additions > 0);
        assert!(stats.deletions > 0);
    }

    #[test]
    fn test_parse_hunk_header() {
        let result = parse_hunk_header("@@ -1,5 +1,7 @@");
        assert_eq!(result, Some((1, 5, 1, 7)));
    }

    #[test]
    fn test_bundle_summary_default() {
        let viewer = DiffViewer::new();
        assert!(viewer.bundle_summary.is_none());
    }

    #[test]
    fn test_bundle_summary_set_and_clear() {
        let mut viewer = DiffViewer::new();
        viewer.bundle_summary = Some(BundleSummary {
            node_id: "node-1".to_string(),
            node_class: "Implementation".to_string(),
            files_created: 2,
            files_modified: 3,
            writes_count: 5,
            diffs_count: 3,
        });
        assert!(viewer.bundle_summary.is_some());
        viewer.clear();
        assert!(viewer.bundle_summary.is_none());
    }

    #[test]
    fn test_hunk_operation_label() {
        let mut viewer = DiffViewer::new();
        viewer.compute_diff("src/new.rs", "", "fn main() {}\n");
        assert_eq!(viewer.hunks.len(), 1);
        // Set operation manually as agent_app would
        viewer.hunks[0].operation = Some("created".to_string());
        assert_eq!(viewer.hunks[0].operation.as_deref(), Some("created"));
    }

    #[test]
    fn test_parse_diff_multi_file() {
        let mut viewer = DiffViewer::new();
        let diff_text = "\
diff --git a/src/a.rs b/src/a.rs
--- a/src/a.rs
+++ b/src/a.rs
@@ -1,3 +1,4 @@
 line1
+new line
 line2
 line3
diff --git a/src/b.rs b/src/b.rs
--- a/src/b.rs
+++ b/src/b.rs
@@ -1,2 +1,2 @@
-old
+new
 same
";
        viewer.parse_diff(diff_text);
        assert_eq!(viewer.hunks.len(), 2);
        assert_eq!(viewer.hunks[0].file_path, "src/a.rs");
        assert_eq!(viewer.hunks[1].file_path, "src/b.rs");
    }
}