• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MitMaro / git-interactive-rebase-tool / 6883077488

15 Nov 2023 09:23PM UTC coverage: 93.248% (-0.4%) from 93.64%
6883077488

Pull #873

github

web-flow
Merge 0ab516642 into d7655157f
Pull Request #873: When editing in the middle of a rebase, dont clear on quit

45 of 72 new or added lines in 14 files covered. (62.5%)

1 existing line in 1 file now uncovered.

4792 of 5139 relevant lines covered (93.25%)

3.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/src/view/src/testutil/render_view_line.rs
1
use bitflags::bitflags;
2
use display::DisplayColor;
3

4
use crate::{LineSegment, ViewData, ViewLine};
5

6
bitflags! {
18✔
7
        /// Options for the `assert_rendered_output!` macro
8
        #[derive(Default, PartialEq, Eq, Debug, Clone, Copy)]
4✔
9
        pub struct AssertRenderOptions: u8 {
10
                /// Ignore trailing whitespace
11
                const INCLUDE_TRAILING_WHITESPACE = 0b0000_0001;
12
                /// Ignore pinned indicator
13
                const INCLUDE_PINNED = 0b0000_0010;
14
                /// Don't include style information
15
                const INCLUDE_STYLE = 0b0000_0100;
16
                /// Only render the body, in this mode {BODY} is also not rendered
17
                const BODY_ONLY = 0b0000_1000;
18
        }
19
}
20

21
pub(crate) fn render_view_data(view_data: &ViewData, options: AssertRenderOptions) -> Vec<String> {
1✔
22
        let mut lines = vec![];
1✔
23
        let body_only = options.contains(AssertRenderOptions::BODY_ONLY);
2✔
24
        if !body_only && view_data.show_title() {
2✔
25
                if view_data.show_help() {
1✔
26
                        lines.push(String::from("{TITLE}{HELP}"));
2✔
27
                }
28
                else {
29
                        lines.push(String::from("{TITLE}"));
2✔
30
                }
31
        }
32

33
        if view_data.is_empty() {
2✔
34
                lines.push(String::from("{EMPTY}"));
×
35
        }
36

37
        if !body_only {
1✔
38
                let leading_lines = view_data.get_leading_lines();
2✔
39
                if !leading_lines.is_empty() {
1✔
40
                        lines.push(String::from("{LEADING}"));
1✔
41
                        for line in leading_lines {
1✔
42
                                lines.push(render_view_line(line, Some(options)));
1✔
43
                        }
44
                }
45
        }
46

47
        let body_lines = view_data.get_lines();
2✔
48
        if !body_lines.is_empty() {
1✔
49
                if !body_only {
1✔
50
                        lines.push(String::from("{BODY}"));
2✔
51
                }
52
                for line in body_lines {
2✔
53
                        lines.push(render_view_line(line, Some(options)));
1✔
54
                }
55
        }
56

57
        if !body_only {
1✔
58
                let trailing_lines = view_data.get_trailing_lines();
2✔
59
                if !trailing_lines.is_empty() {
1✔
60
                        lines.push(String::from("{TRAILING}"));
1✔
61
                        for line in trailing_lines {
1✔
62
                                lines.push(render_view_line(line, Some(options)));
1✔
63
                        }
64
                }
65
        }
66
        lines
1✔
67
}
68

69
pub(crate) fn render_style(line_segment: &LineSegment) -> String {
2✔
70
        let color_string = match line_segment.get_color() {
2✔
71
                DisplayColor::ActionBreak => String::from("ActionBreak"),
2✔
72
                DisplayColor::ActionDrop => String::from("ActionDrop"),
1✔
73
                DisplayColor::ActionEdit => String::from("ActionEdit"),
2✔
74
                DisplayColor::ActionExec => String::from("ActionExec"),
2✔
75
                DisplayColor::ActionFixup => String::from("ActionFixup"),
2✔
76
                DisplayColor::ActionPick => String::from("ActionPick"),
2✔
77
                DisplayColor::ActionReword => String::from("ActionReword"),
2✔
78
                DisplayColor::ActionSquash => String::from("ActionSquash"),
2✔
79
                DisplayColor::DiffAddColor => String::from("DiffAddColor"),
1✔
80
                DisplayColor::DiffChangeColor => String::from("DiffChangeColor"),
1✔
81
                DisplayColor::DiffRemoveColor => String::from("DiffRemoveColor"),
1✔
82
                DisplayColor::DiffContextColor => String::from("DiffContextColor"),
1✔
83
                DisplayColor::DiffWhitespaceColor => String::from("DiffWhitespaceColor"),
1✔
84
                DisplayColor::IndicatorColor => String::from("IndicatorColor"),
1✔
85
                DisplayColor::Normal => String::from("Normal"),
2✔
NEW
86
                DisplayColor::ActionCut => String::from("ActionCut"),
×
NEW
87
                DisplayColor::ActionIndex => String::from("ActionIndex"),
×
88
                DisplayColor::ActionLabel => String::from("ActionLabel"),
2✔
89
                DisplayColor::ActionReset => String::from("ActionReset"),
2✔
90
                DisplayColor::ActionMerge => String::from("ActionMerge"),
2✔
91
                DisplayColor::ActionUpdateRef => String::from("ActionUpdateRef"),
2✔
92
        };
93

94
        let mut style = vec![];
2✔
95
        if line_segment.is_dimmed() {
4✔
96
                style.push("Dimmed");
2✔
97
        }
98
        if line_segment.is_underlined() {
4✔
99
                style.push("Underline");
2✔
100
        }
101
        if line_segment.is_reversed() {
4✔
102
                style.push("Reversed");
1✔
103
        }
104

105
        if style.is_empty() {
6✔
106
                format!("{{{color_string}}}")
2✔
107
        }
108
        else {
109
                format!("{{{color_string},{}}}", style.join(","))
6✔
110
        }
111
}
112

113
/// Render a `ViewLine` to a `String` using similar logic that is used in the `View`.
114
#[must_use]
115
#[inline]
116
pub fn render_view_line(view_line: &ViewLine, options: Option<AssertRenderOptions>) -> String {
2✔
117
        let mut line = String::new();
2✔
118

119
        let opts = options.unwrap_or_default();
4✔
120

121
        if opts.contains(AssertRenderOptions::INCLUDE_PINNED) {
2✔
122
                let pinned = view_line.get_number_of_pinned_segment();
1✔
123
                if pinned > 0 {
1✔
124
                        line.push_str(format!("{{Pin({pinned})}}").as_str());
1✔
125
                }
126
        }
127

128
        if view_line.get_selected() {
4✔
129
                line.push_str("{Selected}");
1✔
130
        }
131

132
        let mut last_style = String::new();
2✔
133
        for segment in view_line.get_segments() {
6✔
134
                if opts.contains(AssertRenderOptions::INCLUDE_STYLE) {
6✔
135
                        let style = render_style(segment);
2✔
136
                        if style != last_style {
6✔
137
                                line.push_str(style.as_str());
2✔
138
                                last_style = style;
2✔
139
                        }
140
                }
141
                line.push_str(segment.get_content());
4✔
142
        }
143
        if let Some(padding) = view_line.get_padding().as_ref() {
4✔
144
                if opts.contains(AssertRenderOptions::INCLUDE_STYLE) {
4✔
145
                        let style = render_style(padding);
2✔
146
                        if style != last_style {
4✔
147
                                line.push_str(style.as_str());
1✔
148
                        }
149
                }
150
                line.push_str(format!("{{Pad({})}}", padding.get_content()).as_str());
6✔
151
        }
152
        line
2✔
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc