summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2023-08-10 19:48:37 -0230
committerTim Oram <dev@mitmaro.ca>2023-08-11 08:51:01 -0230
commitdd31e71f7dfe9716e850f545c690a6c32804dd27 (patch)
tree999302e4ca14ee04beba76a34d9fe99df146a530
parent64e3a9195f7540c2e57b3071f778cf67d914521d (diff)
Add original values to Line
This adds to the Line struct, the original action, content, and option. This includes a refactor in how Line's are constructed, and a rename of the line parse function from new to parse.
-rw-r--r--src/core/src/modules/external_editor/tests.rs12
-rw-r--r--src/core/src/modules/list/tests/render.rs2
-rw-r--r--src/core/src/process/tests.rs4
-rw-r--r--src/core/src/testutil/action_line.rs4
-rw-r--r--src/todo_file/src/history/tests.rs64
-rw-r--r--src/todo_file/src/lib.rs4
-rw-r--r--src/todo_file/src/line.rs302
-rw-r--r--src/todo_file/src/testutil.rs2
8 files changed, 142 insertions, 252 deletions
diff --git a/src/core/src/modules/external_editor/tests.rs b/src/core/src/modules/external_editor/tests.rs
index cfebfd2..f6491b8 100644
--- a/src/core/src/modules/external_editor/tests.rs
+++ b/src/core/src/modules/external_editor/tests.rs
@@ -60,8 +60,8 @@ fn activate() {
Artifact::ExternalCommand((String::from("editor"), vec![String::from(todo_path.as_str())]))
);
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
- Line::new("pick aaa comment1").unwrap(),
- Line::new("drop bbb comment2").unwrap()
+ Line::parse("pick aaa comment1").unwrap(),
+ Line::parse("drop bbb comment2").unwrap()
]);
assert!(!module.lines.is_empty());
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
@@ -223,8 +223,8 @@ fn empty_edit_undo_and_edit() {
);
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
- Line::new("pick aaa comment").unwrap(),
- Line::new("drop bbb comment").unwrap()
+ Line::parse("pick aaa comment").unwrap(),
+ Line::parse("drop bbb comment").unwrap()
]);
},
);
@@ -387,7 +387,7 @@ fn error_restore_and_abort() {
Artifact::ChangeState(State::List)
);
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
- Line::new("pick aaa comment").unwrap()
+ Line::parse("pick aaa comment").unwrap()
]);
});
}
@@ -407,7 +407,7 @@ fn error_undo_modifications_and_reedit() {
);
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
- Line::new("pick aaa comment").unwrap()
+ Line::parse("pick aaa comment").unwrap()
]);
});
}
diff --git a/src/core/src/modules/list/tests/render.rs b/src/core/src/modules/list/tests/render.rs
index de1230d..f252bd9 100644
--- a/src/core/src/modules/list/tests/render.rs
+++ b/src/core/src/modules/list/tests/render.rs
@@ -117,7 +117,7 @@ fn noop_list() {
let mut module = create_list(&Config::new(), test_context.take_todo_file());
let mut todo_file = module.todo_file.lock();
todo_file.remove_lines(0, 0);
- todo_file.add_line(0, Line::new("noop").unwrap());
+ todo_file.add_line(0, Line::parse("noop").unwrap());
drop(todo_file);
let view_data = test_context.build_view_data(&mut module);
diff --git a/src/core/src/process/tests.rs b/src/core/src/process/tests.rs
index 844ed07..73a1412 100644
--- a/src/core/src/process/tests.rs
+++ b/src/core/src/process/tests.rs
@@ -198,12 +198,12 @@ fn write_todo_file() {
process
.todo_file
.lock()
- .set_lines(vec![Line::new("fixup ddd comment").unwrap()]);
+ .set_lines(vec![Line::parse("fixup ddd comment").unwrap()]);
process.write_todo_file().unwrap();
process.todo_file.lock().load_file().unwrap();
assert_eq!(
process.todo_file.lock().get_line(0).unwrap(),
- &Line::new("fixup ddd comment").unwrap()
+ &Line::parse("fixup ddd comment").unwrap()
);
},
);
diff --git a/src/core/src/testutil/action_line.rs b/src/core/src/testutil/action_line.rs
index 26d6db7..a4f100c 100644
--- a/src/core/src/testutil/action_line.rs
+++ b/src/core/src/testutil/action_line.rs
@@ -9,7 +9,7 @@ lazy_static! {
fn parse_rendered_action_line(rendered: &str) -> Result<Line, ParseError> {
let cleaned_line = FORMAT_REGEX.replace_all(rendered, "").replace(" > ", "");
- Line::new(cleaned_line.as_ref())
+ Line::parse(cleaned_line.as_ref())
}
#[derive(Debug)]
@@ -21,7 +21,7 @@ pub(crate) struct ActionPattern {
impl ActionPattern {
fn new(line: &str, selected: bool) -> Self {
Self {
- line: Line::new(line).expect("Expected valid pick"),
+ line: Line::parse(line).expect("Expected valid pick"),
selected,
}
}
diff --git a/src/todo_file/src/history/tests.rs b/src/todo_file/src/history/tests.rs
index 442bf5f..726557b 100644
--- a/src/todo_file/src/history/tests.rs
+++ b/src/todo_file/src/history/tests.rs
@@ -36,17 +36,17 @@ macro_rules! assert_history_items {
fn create_lines() -> Vec<Line> {
vec![
- Line::new("pick aaa c1").unwrap(),
- Line::new("pick bbb c2").unwrap(),
- Line::new("pick ccc c3").unwrap(),
- Line::new("pick ddd c4").unwrap(),
- Line::new("pick eee c5").unwrap(),
+ Line::parse("pick aaa c1").unwrap(),
+ Line::parse("pick bbb c2").unwrap(),
+ Line::parse("pick ccc c3").unwrap(),
+ Line::parse("pick ddd c4").unwrap(),
+ Line::parse("pick eee c5").unwrap(),
]
}
macro_rules! assert_todo_lines {
($lines:expr, $($arg:expr),*) => {
- let expected = vec![$( Line::new($arg).unwrap(), )*];
+ let expected = vec![$( Line::parse($arg).unwrap(), )*];
pretty_assertions::assert_str_eq!(
$lines.iter().map(Line::to_text).collect::<Vec<String>>().join("\n"),
expected.iter().map(Line::to_text).collect::<Vec<String>>().join("\n")
@@ -229,7 +229,7 @@ fn undo_redo_add_range_end_index_at_bottom() {
#[test]
fn undo_redo_remove_start() {
let mut history = History::new(10);
- history.record(HistoryItem::new_remove(0, 0, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_remove(0, 0, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 0, 0));
assert_todo_lines!(
@@ -255,7 +255,7 @@ fn undo_redo_remove_start() {
#[test]
fn undo_redo_remove_end() {
let mut history = History::new(10);
- history.record(HistoryItem::new_remove(5, 5, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_remove(5, 5, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 5, 5));
assert_todo_lines!(
@@ -281,7 +281,7 @@ fn undo_redo_remove_end() {
#[test]
fn undo_redo_remove_middle() {
let mut history = History::new(10);
- history.record(HistoryItem::new_remove(2, 2, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_remove(2, 2, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 2, 2));
assert_todo_lines!(
@@ -308,8 +308,8 @@ fn undo_redo_remove_middle() {
fn undo_redo_remove_range_start_index_top() {
let mut history = History::new(10);
history.record(HistoryItem::new_remove(0, 1, vec![
- Line::new("drop xxx cx").unwrap(),
- Line::new("drop yyy cy").unwrap(),
+ Line::parse("drop xxx cx").unwrap(),
+ Line::parse("drop yyy cy").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 0, 1));
@@ -338,8 +338,8 @@ fn undo_redo_remove_range_start_index_top() {
fn undo_redo_remove_range_start_index_bottom() {
let mut history = History::new(10);
history.record(HistoryItem::new_remove(6, 5, vec![
- Line::new("drop xxx cx").unwrap(),
- Line::new("drop yyy cy").unwrap(),
+ Line::parse("drop xxx cx").unwrap(),
+ Line::parse("drop yyy cy").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 6, 5));
@@ -368,8 +368,8 @@ fn undo_redo_remove_range_start_index_bottom() {
fn undo_redo_remove_range_end_index_top() {
let mut history = History::new(10);
history.record(HistoryItem::new_remove(1, 0, vec![
- Line::new("drop xxx cx").unwrap(),
- Line::new("drop yyy cy").unwrap(),
+ Line::parse("drop xxx cx").unwrap(),
+ Line::parse("drop yyy cy").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 1, 0));
@@ -398,8 +398,8 @@ fn undo_redo_remove_range_end_index_top() {
fn undo_redo_remove_range_end_index_bottom() {
let mut history = History::new(10);
history.record(HistoryItem::new_remove(5, 6, vec![
- Line::new("drop xxx cx").unwrap(),
- Line::new("drop yyy cy").unwrap(),
+ Line::parse("drop xxx cx").unwrap(),
+ Line::parse("drop yyy cy").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 5, 6));
@@ -702,7 +702,7 @@ fn undo_redo_swap_down_range_up_index_end() {
#[test]
fn undo_redo_modify_single_index_start() {
let mut history = History::new(10);
- history.record(HistoryItem::new_modify(0, 0, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_modify(0, 0, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 0, 0));
assert_todo_lines!(
@@ -727,7 +727,7 @@ fn undo_redo_modify_single_index_start() {
#[test]
fn undo_redo_modify_single_index_end() {
let mut history = History::new(10);
- history.record(HistoryItem::new_modify(4, 4, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_modify(4, 4, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 4, 4));
assert_todo_lines!(
@@ -752,7 +752,7 @@ fn undo_redo_modify_single_index_end() {
#[test]
fn undo_redo_modify_single_index_middle() {
let mut history = History::new(10);
- history.record(HistoryItem::new_modify(2, 2, vec![Line::new("drop xxx cx").unwrap()]));
+ history.record(HistoryItem::new_modify(2, 2, vec![Line::parse("drop xxx cx").unwrap()]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 2));
assert_todo_lines!(
@@ -778,9 +778,9 @@ fn undo_redo_modify_single_index_middle() {
fn undo_redo_modify_range_down_index_start() {
let mut history = History::new(10);
history.record(HistoryItem::new_modify(0, 2, vec![
- Line::new("drop xx1 c1").unwrap(),
- Line::new("drop xx2 c2").unwrap(),
- Line::new("drop xx3 c3").unwrap(),
+ Line::parse("drop xx1 c1").unwrap(),
+ Line::parse("drop xx2 c2").unwrap(),
+ Line::parse("drop xx3 c3").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 0, 2));
@@ -807,9 +807,9 @@ fn undo_redo_modify_range_down_index_start() {
fn undo_redo_modify_range_down_index_end() {
let mut history = History::new(10);
history.record(HistoryItem::new_modify(2, 4, vec![
- Line::new("drop xx1 c1").unwrap(),
- Line::new("drop xx2 c2").unwrap(),
- Line::new("drop xx3 c3").unwrap(),
+ Line::parse("drop xx1 c1").unwrap(),
+ Line::parse("drop xx2 c2").unwrap(),
+ Line::parse("drop xx3 c3").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 4));
@@ -836,9 +836,9 @@ fn undo_redo_modify_range_down_index_end() {
fn undo_redo_modify_range_up_index_start() {
let mut history = History::new(10);
history.record(HistoryItem::new_modify(2, 0, vec![
- Line::new("drop xx1 c1").unwrap(),
- Line::new("drop xx2 c2").unwrap(),
- Line::new("drop xx3 c3").unwrap(),
+ Line::parse("drop xx1 c1").unwrap(),
+ Line::parse("drop xx2 c2").unwrap(),
+ Line::parse("drop xx3 c3").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 0));
@@ -865,9 +865,9 @@ fn undo_redo_modify_range_up_index_start() {
fn undo_redo_modify_range_up_index_end() {
let mut history = History::new(10);
history.record(HistoryItem::new_modify(4, 2, vec![
- Line::new("drop xx1 c1").unwrap(),
- Line::new("drop xx2 c2").unwrap(),
- Line::new("drop xx3 c3").unwrap(),
+ Line::parse("drop xx1 c1").unwrap(),
+ Line::parse("drop xx2 c2").unwrap(),
+ Line::parse("drop xx3 c3").unwrap(),
]));
let mut lines = create_lines();
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 4, 2));
diff --git a/src/todo_file/src/lib.rs b/src/todo_file/src/lib.rs
index dc7632e..a90fa9a 100644
--- a/src/todo_file/src/lib.rs
+++ b/src/todo_file/src/lib.rs
@@ -224,7 +224,7 @@ impl TodoFile {
None
}
else {
- Some(Line::new(l).map_err(|err| {
+ Some(Line::parse(l).map_err(|err| {
IoError::FileRead {
file: self.filepath.clone(),
cause: FileReadErrorCause::from(err),
@@ -492,7 +492,7 @@ mod tests {
use super::*;
fn create_line(line: &str) -> Line {
- Line::new(line).unwrap()
+ Line::parse(line).unwrap()
}
fn create_and_load_todo_file(file_contents: &[&str]) -> (TodoFile, NamedTempFile) {
diff --git a/src/todo_file/src/line.rs b/src/todo_file/src/line.rs
index 002b230..2a1dca6 100644
--- a/src/todo_file/src/line.rs
+++ b/src/todo_file/src/line.rs
@@ -8,110 +8,82 @@ pub struct Line {
hash: String,
mutated: bool,
option: Option<String>,
+ original_action: Action,
+ original_content: String,
+ original_option: Option<String>,
}
impl Line {
- /// Create a new noop line.
- #[must_use]
- const fn new_noop() -> Self {
+ fn new(action: Action, hash: &str, content: &str, option: Option<&str>) -> Self {
+ let original_action = action;
+ let original_content = String::from(content);
+ let original_option = option.map(String::from);
+
Self {
- action: Action::Noop,
- content: String::new(),
- hash: String::new(),
+ action,
+ content: String::from(content),
+ hash: String::from(hash),
mutated: false,
- option: None,
+ option: original_option.clone(),
+ original_action,
+ original_content,
+ original_option,
}
}
+ /// Create a new noop line.
+ #[must_use]
+ fn new_noop() -> Self {
+ Self::new(Action::Noop, "", "", None)
+ }
+
/// Create a new pick line.
#[must_use]
#[inline]
pub fn new_pick(hash: &str) -> Self {
- Self {
- action: Action::Pick,
- content: String::new(),
- hash: String::from(hash),
- mutated: false,
- option: None,
- }
+ Self::new(Action::Pick, hash, "", None)
}
/// Create a new break line.
#[must_use]
#[inline]
- pub const fn new_break() -> Self {
- Self {
- action: Action::Break,
- content: String::new(),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ pub fn new_break() -> Self {
+ Self::new(Action::Break, "", "", None)
}
/// Create a new exec line.
#[must_use]
#[inline]
pub fn new_exec(command: &str) -> Self {
- Self {
- action: Action::Exec,
- content: String::from(command),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ Self::new(Action::Exec, "", command, None)
}
/// Create a new merge line.
#[must_use]
#[inline]
- pub fn new_merge(command: &str) -> Self {
- Self {
- action: Action::Merge,
- content: String::from(command),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ pub fn new_merge(label: &str) -> Self {
+ Self::new(Action::Merge, "", label, None)
}
/// Create a new label line.
#[must_use]
#[inline]
pub fn new_label(label: &str) -> Self {
- Self {
- action: Action::Label,
- content: String::from(label),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ Self::new(Action::Label, "", label, None)
}
/// Create a new reset line.
#[must_use]
#[inline]
pub fn new_reset(label: &str) -> Self {
- Self {
- action: Action::Reset,
- content: String::from(label),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ Self::new(Action::Reset, "", label, None)
}
/// Create a new update-ref line.
#[must_use]
#[inline]
pub fn new_update_ref(ref_name: &str) -> Self {
- Self {
- action: Action::UpdateRef,
- content: String::from(ref_name),
- hash: String::new(),
- mutated: false,
- option: None,
- }
+ Self::new(Action::UpdateRef, "", ref_name, None)
}
/// Create a new line from a rebase file line.
@@ -120,7 +92,7 @@ impl Line {
///
/// Returns an error if an invalid line is provided.
#[inline]
- pub fn new(input_line: &str) -> Result<Self, ParseError> {
+ pub fn parse(input_line: &str) -> Result<Self, ParseError> {
let mut line_parser = LineParser::new(input_line);
let action = Action::try_from(line_parser.next()?)?;
@@ -128,14 +100,7 @@ impl Line {
Action::Noop => Self::new_noop(),
Action::Break => Self::new_break(),
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop => {
- let hash = String::from(line_parser.next()?);
- Self {
- action,
- hash,
- content: String::from(line_parser.take_remaining()),
- mutated: false,
- option: None,
- }
+ Self::new(action, line_parser.next()?, line_parser.take_remaining(), None)
},
Action::Fixup => {
let mut next = line_parser.next()?;
@@ -149,27 +114,13 @@ impl Line {
None
};
- let hash = String::from(next);
-
- Self {
- action,
- hash,
- content: String::from(line_parser.take_remaining()),
- mutated: false,
- option,
- }
+ Self::new(action, next, line_parser.take_remaining(), option.as_deref())
},
Action::Exec | Action::Merge | Action::Label | Action::Reset | Action::UpdateRef => {
if !line_parser.has_more() {
return Err(line_parser.parse_error());
}
- Self {
- action,
- hash: String::new(),
- content: String::from(line_parser.take_remaining()),
- mutated: false,
- option: None,
- }
+ Self::new(action, "", line_parser.take_remaining(), None)
},
})
}
@@ -189,6 +140,7 @@ impl Line {
pub fn edit_content(&mut self, content: &str) {
if self.is_editable() {
self.content = String::from(content);
+ self.mutated = true;
}
}
@@ -257,6 +209,13 @@ impl Line {
}
}
+ /// Has this line been modified
+ #[must_use]
+ #[inline]
+ pub fn is_modified(&self) -> bool {
+ self.mutated
+ }
+
/// Create a string containing a textual version of the line, as would be seen in the rebase file.
#[must_use]
#[inline]
@@ -287,113 +246,23 @@ mod tests {
use super::*;
#[rstest]
- #[case::pick_action("pick aaa comment", &Line {
- action: Action::Pick,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::reword_action("reword aaa comment", &Line {
- action: Action::Reword,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::edit_action("edit aaa comment", &Line {
- action: Action::Edit,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::squash_action("squash aaa comment", &Line {
- action: Action::Squash,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::fixup_action("fixup aaa comment", &Line {
- action: Action::Fixup,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::fixup_with_option_action("fixup -c aaa comment", &Line {
- action: Action::Fixup,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: Some(String::from("-c")),
- })]
- #[case::drop_action("drop aaa comment", &Line {
- action: Action::Drop,
- hash: String::from("aaa"),
- content: String::from("comment"),
- mutated: false,
- option: None,
- })]
- #[case::action_without_comment("pick aaa", &Line {
- action: Action::Pick,
- hash: String::from("aaa"),
- content: String::new(),
- mutated: false,
- option: None,
- })]
- #[case::exec_action("exec command", &Line {
- action: Action::Exec,
- hash: String::new(),
- content: String::from("command"),
- mutated: false,
- option: None,
- })]
- #[case::label_action("label ref", &Line {
- action: Action::Label,
- hash: String::new(),
- content: String::from("ref"),
- mutated: false,
- option: None,
- })]
- #[case::reset_action("reset ref", &Line {
- action: Action::Reset,
- hash: String::new(),
- content: String::from("ref"),
- mutated: false,
- option: None,
- })]
- #[case::reset_action("merge command", &Line {
- action: Action::Merge,
- hash: String::new(),
- content: String::from("command"),
- mutated: false,
- option: None,
- })]
- #[case::update_ref_action("update-ref reference", &Line {
- action: Action::UpdateRef,
- hash: String::new(),
- content: String::from("reference"),
- mutated: false,
- option: None,
- })]
- #[case::break_action("break", &Line {
- action: Action::Break,
- hash: String::new(),
- content: String::new(),
- mutated: false,
- option: None,
- })]
- #[case::nnop( "noop", &Line {
- action: Action::Noop,
- hash: String::new(),
- content: String::new(),
- mutated: false,
- option: None,
- })]
+ #[case::pick_action("pick aaa comment", &Line::new(Action::Pick, "aaa", "comment", None))]
+ #[case::reword_action("reword aaa comment", &Line::new(Action::Reword, "aaa", "comment", None))]
+ #[case::edit_action("edit aaa comment", &Line::new(Action::Edit, "aaa", "comment", None))]
+ #[case::squash_action("squash aaa comment", &Line::new(Action::Squash, "aaa", "comment", None))]
+ #[case::fixup_action("fixup aaa comment", & Line::new(Action::Fixup, "aaa", "comment", None))]
+ #[case::fixup_with_option_action("fixup -c aaa comment", &Line::new(Action::Fixup, "aaa", "comment", Some("-c")))]
+ #[case::drop_action("drop aaa comment", &Line::new(Action::Drop, "aaa", "comment", None))]
+ #[case::action_without_comment("pick aaa", &Line::new(Action::Pick, "aaa", "", None))]
+ #[case::exec_action("exec command", &Line::new(Action::Exec, "", "command", None))]
+ #[case::label_action("label ref", &Line::new(Action::Label, "", "ref", None))]
+ #[case::reset_action("reset ref", &Line::new(Action::Reset, "", "ref", None))]
+ #[case::reset_action("merge command", &Line::new(Action::Merge, "", "command", None))]
+ #[case::update_ref_action("update-ref reference", &Line::new(Action::UpdateRef, "", "reference", None))]
+ #[case::break_action("break", &Line::new(Action::Break, "", "", None))]
+ #[case::noop( "noop", &Line::new(Action::Noop, "", "", None))]
fn new(#[case] line: &str, #[case] expected: &Line) {
- assert_ok_eq!(&Line::new(line), expected);
+ assert_ok_eq!(&Line::parse(line), expected);
}
#[test]
@@ -404,6 +273,9 @@ mod tests {
content: String::new(),
mutated: false,
option: None,
+ original_action: Action::Pick,
+ original_content: String::new(),
+ original_option: None,
});
}
@@ -415,6 +287,9 @@ mod tests {
content: String::new(),
mutated: false,
option: None,
+ original_action: Action::Break,
+ original_content: String::new(),
+ original_option: None,
});
}
@@ -426,6 +301,9 @@ mod tests {
content: String::from("command"),
mutated: false,
option: None,
+ original_action: Action::Exec,
+ original_content: String::from("command"),
+ original_option: None,
});
}
@@ -437,6 +315,9 @@ mod tests {
content: String::from("command"),
mutated: false,
option: None,
+ original_action: Action::Merge,
+ original_content: String::from("command"),
+ original_option: None,
});
}
@@ -448,6 +329,9 @@ mod tests {
content: String::from("label"),
mutated: false,
option: None,
+ original_action: Action::Label,
+ original_content: String::from("label"),
+ original_option: None,
});
}
@@ -459,6 +343,9 @@ mod tests {
content: String::from("label"),
mutated: false,
option: None,
+ original_action: Action::Reset,
+ original_content: String::from("label"),
+ original_option: None,
});
}
@@ -470,13 +357,16 @@ mod tests {
content: String::from("reference"),
mutated: false,
option: None,
+ original_action: Action::UpdateRef,
+ original_content: String::from("reference"),
+ original_option: None,
});
}
#[test]
fn new_err_invalid_action() {
assert_err_eq!(
- Line::new("invalid aaa comment"),
+ Line::parse("invalid aaa comment"),
ParseError::InvalidAction(String::from("invalid"))
);
}
@@ -494,7 +384,7 @@ mod tests {
#[case::merge_line_only("merge")]
#[case::update_ref_line_only("update-ref")]
fn new_err(#[case] line: &str) {
- assert_err_eq!(Line::new(line), ParseError::InvalidLine(String::from(line)));
+ assert_err_eq!(Line::parse(line), ParseError::InvalidLine(String::from(line)));
}
#[rstest]
@@ -505,10 +395,10 @@ mod tests {
#[case::reword(Action::Reword, Action::Fixup)]
#[case::squash(Action::Squash, Action::Fixup)]
fn set_action_non_static(#[case] from: Action, #[case] to: Action) {
- let mut line = Line::new(format!("{from} aaa bbb").as_str()).unwrap();
+ let mut line = Line::parse(format!("{from} aaa bbb").as_str()).unwrap();
line.set_action(to);
assert_eq!(line.action, to);
- assert!(line.mutated);
+ assert!(line.is_modified());
}
#[rstest]
@@ -520,26 +410,26 @@ mod tests {
#[case::update_ref(Action::UpdateRef, Action::Fixup)]
#[case::noop(Action::Noop, Action::Fixup)]
fn set_action_static(#[case] from: Action, #[case] to: Action) {
- let mut line = Line::new(format!("{from} comment").as_str()).unwrap();
+ let mut line = Line::parse(format!("{from} comment").as_str()).unwrap();
line.set_action(to);
assert_eq!(line.action, from);
- assert!(!line.mutated);
+ assert!(!line.is_modified());
}
#[test]
fn set_to_new_action_with_changed_action() {
- let mut line = Line::new("pick aaa comment").unwrap();
+ let mut line = Line::parse("pick aaa comment").unwrap();
line.set_action(Action::Fixup);
assert_eq!(line.action, Action::Fixup);
- assert!(line.mutated);
+ assert!(line.is_modified());
}
#[test]
fn set_to_new_action_with_unchanged_action() {
- let mut line = Line::new("pick aaa comment").unwrap();
+ let mut line = Line::parse("pick aaa comment").unwrap();
line.set_action(Action::Pick);
assert_eq!(line.action, Action::Pick);
- assert!(!line.mutated);
+ assert!(!line.is_modified());
}
#[rstest]
@@ -556,7 +446,7 @@ mod tests {
#[case::merge("merge command", "new")]
#[case::update_ref("update-ref reference", "new")]
fn edit_content(#[case] line: &str, #[case] expected: &str) {
- let mut line = Line::new(line).unwrap();
+ let mut line = Line::parse(line).unwrap();
line.edit_content("new");
assert_eq!(line.get_content(), expected);
}
@@ -575,7 +465,7 @@ mod tests {
#[case::merge("merge command", "command")]
#[case::update_ref("update-ref reference", "reference")]
fn get_content(#[case] line: &str, #[case] expected: &str) {
- assert_eq!(Line::new(line).unwrap().get_content(), expected);
+ assert_eq!(Line::parse(line).unwrap().get_content(), expected);
}
#[rstest]
@@ -592,7 +482,7 @@ mod tests {
#[case::merge("merge command", Action::Merge)]
#[case::update_ref("update-ref reference", Action::UpdateRef)]
fn get_action(#[case] line: &str, #[case] expected: Action) {
- assert_eq!(Line::new(line).unwrap().get_action(), &expected);
+ assert_eq!(Line::parse(line).unwrap().get_action(), &expected);
}
#[rstest]
@@ -609,7 +499,7 @@ mod tests {
#[case::merge("merge command", "")]
#[case::update_ref("update-ref reference", "")]
fn get_hash(#[case] line: &str, #[case] expected: &str) {
- assert_eq!(Line::new(line).unwrap().get_hash(), expected);
+ assert_eq!(Line::parse(line).unwrap().get_hash(), expected);
}
#[rstest]
@@ -626,7 +516,7 @@ mod tests {
#[case::merge("merge command", false)]
#[case::update_ref("update-ref reference", false)]
fn has_reference(#[case] line: &str, #[case] expected: bool) {
- assert_eq!(Line::new(line).unwrap().has_reference(), expected);
+ assert_eq!(Line::parse(line).unwrap().has_reference(), expected);
}
#[rstest]
@@ -644,7 +534,7 @@ mod tests {
#[case::merge(Action::Merge, true)]
#[case::update_ref(Action::UpdateRef, true)]
fn is_editable(#[case] from: Action, #[case] editable: bool) {
- let line = Line::new(format!("{from} aaa bbb").as_str()).unwrap();
+ let line = Line::parse(format!("{from} aaa bbb").as_str()).unwrap();
assert_eq!(line.is_editable(), editable);
}
@@ -663,6 +553,6 @@ mod tests {
#[case::merge("merge command")]
#[case::update_ref("update-ref reference")]
fn to_text(#[case] line: &str) {
- assert_eq!(Line::new(line).unwrap().to_text(), line);
+ assert_eq!(Line::parse(line).unwrap().to_text(), line);
}
}
diff --git a/src/todo_file/src/testutil.rs b/src/todo_file/src/testutil.rs
index 3b59df9..417b619 100644
--- a/src/todo_file/src/testutil.rs
+++ b/src/todo_file/src/testutil.rs
@@ -96,7 +96,7 @@ where C: FnOnce(TodoFileTestContext) {
.unwrap();
let mut todo_file = TodoFile::new(git_todo_file.path().to_str().unwrap(), 1, "#");
- todo_file.set_lines(lines.iter().map(|l| Line::new(l).unwrap()).collect());
+ todo_file.set_lines(lines.iter().map(|l| Line::parse(l).unwrap()).collect());
callback(TodoFileTestContext {
git_todo_file: RefCell::new(git_todo_file),
todo_file,