• 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

90.91
/src/todo_file/src/action.rs
1
use std::fmt::{Display, Formatter};
2

3
use crate::errors::ParseError;
4

5
/// Describes an rebase action.
6
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7
#[allow(clippy::exhaustive_enums)]
8
pub enum Action {
9
        /// A break action.
10
        Break,
11
        /// A cut action for git-revise.
12
        Cut,
13
        /// A drop action.
14
        Drop,
15
        /// An edit action.
16
        Edit,
17
        /// An exec action.
18
        Exec,
19
        /// A fixup action.
20
        Fixup,
21
        /// A index action for git-revise.
22
        Index,
23
        /// A noop action.
24
        Noop,
25
        /// A pick action.
26
        Pick,
27
        /// A reword action.
28
        Reword,
29
        /// A squash action.
30
        Squash,
31
        /// A label for a merge block.
32
        Label,
33
        /// A reset for a merge block.
34
        Reset,
35
        /// A merge action.
36
        Merge,
37
        /// Update a reference
38
        UpdateRef,
39
}
40

41
impl Action {
42
        /// Get the abbreviated version of the action.
43
        #[must_use]
44
        #[inline]
45
        pub fn to_abbreviation(self) -> String {
5✔
46
                String::from(match self {
10✔
47
                        Self::Break => "b",
2✔
48
                        Self::Drop => "d",
2✔
NEW
49
                        Self::Cut => "c",
×
50
                        Self::Edit => "e",
2✔
51
                        Self::Exec => "x",
2✔
52
                        Self::Fixup => "f",
2✔
NEW
53
                        Self::Index => "i",
×
54
                        Self::Label => "l",
2✔
55
                        Self::Merge => "m",
2✔
56
                        Self::Noop => "n",
1✔
57
                        Self::Pick => "p",
2✔
58
                        Self::Reset => "t",
2✔
59
                        Self::Reword => "r",
2✔
60
                        Self::Squash => "s",
2✔
61
                        Self::UpdateRef => "u",
2✔
62
                })
63
        }
64

65
        /// Can the action be changed.
66
        #[must_use]
67
        #[inline]
68
        pub const fn is_static(self) -> bool {
6✔
69
                match self {
5✔
70
                        Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge | Self::UpdateRef => true,
2✔
71
                        Self::Cut | Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
6✔
72
                }
73
        }
74
}
75

76
impl Display for Action {
77
        #[inline]
78
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
6✔
79
                write!(f, "{}", match *self {
11✔
80
                        Self::Break => "break",
2✔
NEW
81
                        Self::Cut => "cut",
×
82
                        Self::Drop => "drop",
3✔
83
                        Self::Edit => "edit",
3✔
84
                        Self::Exec => "exec",
3✔
85
                        Self::Fixup => "fixup",
3✔
NEW
86
                        Self::Index => "index",
×
87
                        Self::Label => "label",
3✔
88
                        Self::Merge => "merge",
3✔
89
                        Self::Noop => "noop",
2✔
90
                        Self::Pick => "pick",
3✔
91
                        Self::Reset => "reset",
3✔
92
                        Self::Reword => "reword",
3✔
93
                        Self::Squash => "squash",
3✔
94
                        Self::UpdateRef => "update-ref",
3✔
95
                })
96
        }
97
}
98

99
impl TryFrom<&str> for Action {
100
        type Error = ParseError;
101

102
        #[inline]
103
        fn try_from(s: &str) -> Result<Self, Self::Error> {
4✔
104
                match s {
×
105
                        "break" | "b" => Ok(Self::Break),
4✔
106
                        // "cut" => Ok(Self::Cut),
107
                        "drop" | "d" => Ok(Self::Drop),
4✔
108
                        "edit" | "e" => Ok(Self::Edit),
4✔
109
                        "exec" | "x" => Ok(Self::Exec),
4✔
110
                        "fixup" | "f" => Ok(Self::Fixup),
4✔
111
                        "index" => Ok(Self::Index),
4✔
112
                        "noop" | "n" => Ok(Self::Noop),
8✔
113
                        "pick" | "p" => Ok(Self::Pick),
4✔
114
                        "reword" | "r" => Ok(Self::Reword),
3✔
115
                        "squash" | "s" => Ok(Self::Squash),
2✔
116
                        "label" | "l" => Ok(Self::Label),
2✔
117
                        "reset" | "t" => Ok(Self::Reset),
2✔
118
                        "merge" | "m" => Ok(Self::Merge),
2✔
119
                        "update-ref" | "u" => Ok(Self::UpdateRef),
2✔
120
                        _ => Err(ParseError::InvalidAction(String::from(s))),
1✔
121
                }
122
        }
123
}
124

125
#[cfg(test)]
126
mod tests {
127
        use claims::assert_ok_eq;
128
        use rstest::rstest;
129
        use testutils::assert_err_eq;
130

131
        use super::*;
132

133
        #[rstest]
134
        #[case::break_str(Action::Break, "break")]
135
        #[case::drop(Action::Drop, "drop")]
136
        #[case::edit(Action::Edit, "edit")]
137
        #[case::exec(Action::Exec, "exec")]
138
        #[case::fixup(Action::Fixup, "fixup")]
139
        #[case::noop(Action::Noop, "noop")]
140
        #[case::pick(Action::Pick, "pick")]
141
        #[case::reword(Action::Reword, "reword")]
142
        #[case::squash(Action::Squash, "squash")]
143
        #[case::label(Action::Label, "label")]
144
        #[case::reset(Action::Reset, "reset")]
145
        #[case::merge(Action::Merge, "merge")]
146
        #[case::update_ref(Action::UpdateRef, "update-ref")]
147
        fn to_string(#[case] action: Action, #[case] expected: &str) {
148
                assert_eq!(format!("{action}"), expected);
149
        }
150

151
        #[rstest]
152
        #[case::b("b", Action::Break)]
153
        #[case::break_str("break", Action::Break)]
154
        #[case::d("d", Action::Drop)]
155
        #[case::drop("drop", Action::Drop)]
156
        #[case::e("e", Action::Edit)]
157
        #[case::edit("edit", Action::Edit)]
158
        #[case::x("x", Action::Exec)]
159
        #[case::exec("exec", Action::Exec)]
160
        #[case::f("f", Action::Fixup)]
161
        #[case::fixup("fixup", Action::Fixup)]
162
        #[case::n("n", Action::Noop)]
163
        #[case::noop("noop", Action::Noop)]
164
        #[case::p("p", Action::Pick)]
165
        #[case::pick("pick", Action::Pick)]
166
        #[case::r("r", Action::Reword)]
167
        #[case::reword("reword", Action::Reword)]
168
        #[case::s("s", Action::Squash)]
169
        #[case::squash("squash", Action::Squash)]
170
        #[case::l("l", Action::Label)]
171
        #[case::label("label", Action::Label)]
172
        #[case::t("t", Action::Reset)]
173
        #[case::reset("reset", Action::Reset)]
174
        #[case::m("m", Action::Merge)]
175
        #[case::merge("merge", Action::Merge)]
176
        #[case::u("u", Action::UpdateRef)]
177
        #[case::update_ref("update-ref", Action::UpdateRef)]
178
        fn try_from(#[case] action_str: &str, #[case] expected: Action) {
179
                assert_ok_eq!(Action::try_from(action_str), expected);
180
        }
181

182
        #[test]
183
        fn action_try_from_invalid() {
184
                let invalid = String::from("invalid");
185
                assert_err_eq!(Action::try_from(invalid.as_str()), ParseError::InvalidAction(invalid));
186
        }
187

188
        #[rstest]
189
        #[case::b(Action::Break, "b")]
190
        #[case::d(Action::Drop, "d")]
191
        #[case::e(Action::Edit, "e")]
192
        #[case::x(Action::Exec, "x")]
193
        #[case::f(Action::Fixup, "f")]
194
        #[case::n(Action::Noop, "n")]
195
        #[case::p(Action::Pick, "p")]
196
        #[case::r(Action::Reword, "r")]
197
        #[case::s(Action::Squash, "s")]
198
        #[case::l(Action::Label, "l")]
199
        #[case::t(Action::Reset, "t")]
200
        #[case::m(Action::Merge, "m")]
201
        #[case::u(Action::UpdateRef, "u")]
202
        fn to_abbreviation(#[case] action: Action, #[case] expected: &str) {
203
                assert_eq!(action.to_abbreviation(), expected);
204
        }
205

206
        #[rstest]
207
        #[case::break_action(Action::Break, true)]
208
        #[case::drop(Action::Drop, false)]
209
        #[case::edit(Action::Edit, false)]
210
        #[case::exec(Action::Exec, true)]
211
        #[case::fixup(Action::Fixup, false)]
212
        #[case::noop(Action::Noop, true)]
213
        #[case::pick(Action::Pick, false)]
214
        #[case::reword(Action::Reword, false)]
215
        #[case::squash(Action::Squash, false)]
216
        #[case::label(Action::Label, true)]
217
        #[case::reset(Action::Reset, true)]
218
        #[case::merge(Action::Merge, true)]
219
        #[case::update_ref(Action::UpdateRef, true)]
220
        fn module_lifecycle(#[case] action: Action, #[case] expected: bool) {
221
                assert_eq!(action.is_static(), expected);
222
        }
223
}
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