Remove superficial tests in `diff` and `brain`

369f7d79da0e378b0f61ed3f21f0391c8066c9eb
These tests are checking spacing or style.
Alexis Sellier committed ago 1 parent 45bd4683
crates/brain/src/session/status.rs +3 -69
596 596
                .any(|(_, label)| *label == "save")
597 597
        );
598 598
    }
599 599
600 600
    #[test]
601 -
    fn chrome_error_replaces_status_and_actions() {
601 +
    fn chrome_error_replaces_status() {
602 602
        let mut chrome = Chrome {
603 603
            status: Status {
604 604
                mode: "commit",
605 605
                context: StatusContext::Commit {
606 606
                    short: "1234567".to_owned(),
616 616
        };
617 617
        let mut buffer = Buffer::empty(Rect::new(0, 0, 40, 2));
618 618
619 619
        chrome.render(buffer.area(), &mut buffer);
620 620
621 -
        let status = (0..buffer.area().cols)
622 -
            .filter_map(|x| buffer.get(x, 0))
623 -
            .map(|cell| cell.glyph())
624 -
            .collect::<String>();
625 -
        let actions = (0..buffer.area().cols)
626 -
            .filter_map(|x| buffer.get(x, 1))
627 -
            .map(|cell| cell.glyph())
628 -
            .collect::<String>();
629 -
        let badge_style = Style::default().fg(Color::White).bg(Color::Red).bold();
630 -
        let message_style = Style::default().fg(FOOTER_VALUE_FG).bg(FOOTER_BG);
631 -
632 -
        assert!(status.contains(" error  patch does not apply"));
621 +
        let status = buffer.line(0);
622 +
        assert!(status.contains("patch does not apply"));
633 623
        assert!(!status.contains("brain"));
634 -
        assert!(actions.chars().all(|glyph| glyph == ' '));
635 -
        assert!((0..7).all(|x| buffer.get(x, 0).unwrap().style() == badge_style));
636 -
        assert_eq!(buffer.get(7, 0).unwrap().style(), message_style);
637 -
        assert!(
638 -
            (0..buffer.area().cols)
639 -
                .all(|x| buffer.get(x, 1).unwrap().style().bg_color() == FOOTER_BG)
640 -
        );
641 -
642 -
        let mut narrow = Buffer::empty(Rect::new(0, 0, 10, 2));
643 -
        chrome.render(narrow.area(), &mut narrow);
644 -
        let status = (0..narrow.area().cols)
645 -
            .filter_map(|x| narrow.get(x, 0))
646 -
            .map(|cell| cell.glyph())
647 -
            .collect::<String>();
648 -
649 -
        assert_eq!(status, " error  pa");
650 -
    }
651 -
652 -
    #[test]
653 -
    fn status_renders_right_padding() {
654 -
        let mut status = Status {
655 -
            mode: "commit",
656 -
            context: StatusContext::Commit {
657 -
                short: "1234567".to_owned(),
658 -
                summary: "summary".to_owned(),
659 -
            },
660 -
            progress: ReviewProgress::default(),
661 -
            stats: DiffStat::default(),
662 -
            palette: DiffPalette::default(),
663 -
            visibility: Visibility::default(),
664 -
            error: None,
665 -
        };
666 -
        let mut buffer = Buffer::empty(Rect::new(0, 0, 80, 1));
667 -
668 -
        status.render(buffer.area(), &mut buffer);
669 -
670 -
        assert_eq!(buffer.get(78, 0).unwrap().glyph(), FULL_FILE_MODE_ICON);
671 -
        assert_eq!(buffer.get(79, 0).unwrap().glyph(), " ");
672 -
        assert_eq!(buffer.get(79, 0).unwrap().style().bg_color(), FOOTER_BG);
673 624
    }
674 625
675 626
    #[test]
676 627
    fn completed_commit_status_hides_diff_summary() {
677 628
        let mut status = Status {
852 803
        assert!(text.contains("just now"), "text: {text:?}");
853 804
        assert!(text.contains("first second"), "text: {text:?}");
854 805
        assert!(!text.contains('🗨'), "text: {text:?}");
855 806
    }
856 807
857 -
    #[test]
858 -
    fn unselected_comment_cards_render_a_faint_border() {
859 -
        let comment = Comment {
860 -
            id: 1.into(),
861 -
            author: "alice".to_owned(),
862 -
            timestamp: current_timestamp(),
863 -
            body: "first".to_owned(),
864 -
        };
865 -
866 -
        let mut lines = comment_card_lines(&comment, false, 40);
867 -
        let mut buffer = Buffer::empty(Rect::new(0, 0, 40, lines.len()));
868 -
869 -
        Line::renders(lines.drain(..), buffer.area(), &mut buffer);
870 -
871 -
        assert_eq!(buffer.get(0, 0).unwrap().style().fg_color(), colors::FAINT);
872 -
    }
873 -
874 808
    #[test]
875 809
    fn relative_time_uses_largest_whole_unit() {
876 810
        let now = 2_000_000_000;
877 811
878 812
        assert_eq!(relative_time(now, now), "just now");
crates/diff/src/bin/rustik-diff/session.rs +5 -47
372 372
        );
373 373
    }
374 374
375 375
    #[test]
376 376
    fn status_line_renders_application_badge() {
377 -
        let mut line = status_line(24, Stats::default(), DiffPalette::default(), None, None);
378 -
        let mut buffer = tui::Buffer::empty(Rect::new(0, 0, 24, 1));
379 -
        let badge_style = Style::default().fg(Color::White).bg(APP_BADGE_BG).bold();
377 +
        let line = status_line(24, Stats::default(), DiffPalette::default(), None, None);
380 378
381 -
        line.render(buffer.area(), &mut buffer);
382 -
383 -
        let badge = (0..6)
384 -
            .map(|x| buffer.get(x, 0).unwrap().glyph())
385 -
            .collect::<String>();
386 -
        assert_eq!(badge, " diff ");
387 -
        assert!((0..6).all(|x| buffer.get(x, 0).unwrap().style() == badge_style));
388 -
    }
389 -
390 -
    #[test]
391 -
    fn status_line_renders_right_padding() {
392 -
        let mut line = status_line(24, Stats::default(), DiffPalette::default(), None, None);
393 -
        let mut buffer = tui::Buffer::empty(Rect::new(0, 0, 24, 1));
394 -
395 -
        line.render(buffer.area(), &mut buffer);
396 -
397 -
        assert_eq!(buffer.get(22, 0).unwrap().glyph(), "s");
398 -
        assert_eq!(buffer.get(23, 0).unwrap().glyph(), " ");
399 -
        assert_eq!(buffer.get(23, 0).unwrap().style().bg_color(), FOOTER_BG);
379 +
        assert!(line.to_string().contains("diff"));
400 380
    }
401 381
402 382
    #[test]
403 383
    fn status_line_renders_recoverable_error() {
404 -
        let mut line = status_line(
384 +
        let line = status_line(
405 385
            40,
406 386
            Stats::default(),
407 387
            DiffPalette::default(),
408 388
            Some("highlight 1.0ms"),
409 389
            Some("input failed"),
410 390
        );
411 -
        let mut buffer = tui::Buffer::empty(Rect::new(0, 0, 40, 1));
412 -
413 -
        line.render(buffer.area(), &mut buffer);
391 +
        let text = line.to_string();
414 392
415 -
        let text = (0..buffer.area().cols)
416 -
            .filter_map(|x| buffer.get(x, 0))
417 -
            .map(|cell| cell.glyph())
418 -
            .collect::<String>();
419 -
        let badge_style = Style::default().fg(Color::White).bg(Color::Red).bold();
420 -
        let message_style = Style::default().fg(FOOTER_VALUE_FG).bg(FOOTER_BG);
421 -
422 -
        assert!(text.contains(" error  input failed"));
393 +
        assert!(text.contains("input failed"));
423 394
        assert!(!text.contains("diff"));
424 395
        assert!(!text.contains("highlight"));
425 -
        assert!((0..7).all(|x| buffer.get(x, 0).unwrap().style() == badge_style));
426 -
        assert_eq!(buffer.get(7, 0).unwrap().style(), message_style);
427 -
428 -
        let narrow = status_line(
429 -
            10,
430 -
            Stats::default(),
431 -
            DiffPalette::default(),
432 -
            None,
433 -
            Some("input failed"),
434 -
        );
435 -
436 -
        assert_eq!(narrow.width(), 10);
437 -
        assert_eq!(narrow.to_string(), " error  in");
438 396
    }
439 397
440 398
    #[test]
441 399
    fn resize_requests_redraw_even_when_viewer_continues() {
442 400
        let resized = true;
crates/diff/src/builtins.rs +0 -0
script\n\ +0 -0
{path}\n\ +0 -0
crates/diff/src/viewer.rs +0 -1
2825 2825
#[cfg(test)]
2826 2826
#[allow(clippy::unwrap_used)]
2827 2827
mod tests {
2828 2828
    use std::fs;
2829 2829
    use std::path::PathBuf;
2830 -
    use std::str::FromStr;
2831 2830
    use std::time::{SystemTime, UNIX_EPOCH};
2832 2831
2833 2832
    use super::*;
2834 2833
2835 2834
    use crate::Decode;
a.rs +0 -0
image.png +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +0 -0
src/a.rs +0 -0
src/b.rs +0 -0
README.md +0 -0
src/app/a.rs +0 -0
src/lib/b.rs +0 -0
README.md +0 -0
a.rs +0 -0
b.rs +0 -0
assets/css/style.css +0 -18
1 -
+++ b/assets/css/style.css
2 -
@@ -12,7 +12,8 @@
3 -
   --color-foreground: #112;
4 -
   --color-headers: #222;
5 -
   --color-background: #d3d1d1;
6 -
-  --color-background-light: #dedddd;
7 -
+  --color-background-light: #dad8d8;
8 -
+  --color-background-dark: #cecccc;
9 -
   --color-dim: #334;
10 -
   --color-dimmer: #666;
11 -
   --color-subtle: #888;
12 -
",
13 -
        )
14 -
        .unwrap();
15 -
        let mut viewer = DiffViewer::new(document, DiffOptions::default());
16 -
        let full = DiffDocument::decode_str(
17 -
            "\
18 -
assets/css/style.css +0 -68
1 -
+++ b/assets/css/style.css
2 -
@@ -1,19 +1,20 @@
3 -
 html {
4 -
   box-sizing: border-box;
5 -
 }
6 -
 *, *::before, *::after {
7 -
   box-sizing: inherit;
8 -
 }
9 -
 body {
10 -
   margin: 0;
11 -
 }
12 -
 :root {
13 -
   color-scheme: light;
14 -
   --color-foreground: #112;
15 -
   --color-headers: #222;
16 -
   --color-background: #d3d1d1;
17 -
-  --color-background-light: #dedddd;
18 -
+  --color-background-light: #dad8d8;
19 -
+  --color-background-dark: #cecccc;
20 -
   --color-dim: #334;
21 -
   --color-dimmer: #666;
22 -
   --color-subtle: #888;
23 -
 }
24 -
",
25 -
        )
26 -
        .unwrap();
27 -
        let mut registry = syntax::Registry::default();
28 -
        registry.add_theme(
29 -
            syntax::Theme::parse(include_str!("themes/rustik-catppuccin-mocha.json")).unwrap(),
30 -
        );
31 -
        registry.add_grammar(syntax::Grammar::from_str(syntax::syntaxes::CSS).unwrap());
32 -
        let mut highlighter = crate::BuiltinHighlighter::new(registry, "rustik-catppuccin-mocha");
33 -
34 -
        // Enrich the visible requests with source context, as the pager
35 -
        // worker does, so the highlighter sees the CSS rule in context.
36 -
        let source = full.files[0].highlight_source(DiffSide::New).unwrap();
37 -
        let mut requests = viewer.highlight_requests(Rect::new(0, 0, 80, 20));
38 -
        for request in &mut requests {
39 -
            if request.key.side == DiffSide::New {
40 -
                request.source = source.clone();
41 -
            }
42 -
        }
43 -
        let result = highlighter
44 -
            .highlight_requests(requests)
45 -
            .into_iter()
46 -
            .find(|result| {
47 -
                result.key.text_hash == {
48 -
                    use std::collections::hash_map::DefaultHasher;
49 -
                    use std::hash::{Hash, Hasher};
50 -
51 -
                    let mut hasher = DefaultHasher::new();
52 -
                    "  --color-background-light: #dad8d8;".hash(&mut hasher);
53 -
                    hasher.finish()
54 -
                }
55 -
            })
56 -
            .unwrap();
57 -
58 -
        let color = Color::RGB(137, 180, 250);
59 -
        let variable = result
60 -
            .line
61 -
            .labels()
62 -
            .iter()
63 -
            .find(|label| label.content().contains("--color-background-light"))
64 -
            .unwrap();
65 -
66 -
        assert_eq!(variable.paint.style().fg_color(), color);
67 -
    }
68 -
69 1
    #[test]
70 2
    fn metadata_lookup_matches_rendered_diff_rows() {
71 3
        let viewer = sample_viewer();
72 4
        for row in 0..viewer.index.rows {
73 5
            assert_eq!(
first.rs +0 -0
second.rs +0 -0
a.rs +0 -33
1 -
+++ b/a.rs
2 -
@@ -1 +1,5 @@
3 -
-old
4 -
+fn main() {
5 -
+    let value = true;
6 -
+    if value {
7 -
+        return;
8 -
+    }
9 -
",
10 -
        )
11 -
        .unwrap();
12 -
        let single = DiffDocument::for_hunks(&full.files[0], [full.files[0].hunks[0].clone()]);
13 -
        let mut viewer = DiffViewer::new(single.clone(), DiffOptions::default());
14 -
        let mut highlighter = crate::Builtins::highlighter(&single).unwrap();
15 -
16 -
        assert!(viewer.apply_visible_highlights(Rect::new(0, 0, 80, 20), &mut highlighter));
17 -
18 -
        let rendered = (0..viewer.index.rows)
19 -
            .filter_map(|row| viewer.render_row(row, 80))
20 -
            .map(|row| row.line)
21 -
            .collect::<Vec<_>>();
22 -
        for token in ["fn", "let", "if", "return"] {
23 -
            assert!(
24 -
                rendered.iter().any(|line| {
25 -
                    line.labels().iter().any(|label| {
26 -
                        label.content() == token && label.paint.style().fg_color() != Color::Unset
27 -
                    })
28 -
                }),
29 -
                "missing highlighted token {token}: {rendered:#?}"
30 -
            );
31 -
        }
32 -
    }
33 -
34 1
    #[test]
35 2
    fn apply_visible_highlights_runs_one_visible_batch() {
36 3
        let mut viewer = sample_viewer();
37 4
        let area = Rect::new(0, 0, 64, 5);
38 5
        let mut highlighter = RecordingHighlighter::default();
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs\n", +0 -0
new.rs\n", +0 -0
a\n\ +0 -0