Skip to content

Commit dd31e71

Browse files
committed
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.
1 parent 64e3a91 commit dd31e71

File tree

8 files changed

+142
-252
lines changed

8 files changed

+142
-252
lines changed

src/core/src/modules/external_editor/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ fn activate() {
6060
Artifact::ExternalCommand((String::from("editor"), vec![String::from(todo_path.as_str())]))
6161
);
6262
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
63-
Line::new("pick aaa comment1").unwrap(),
64-
Line::new("drop bbb comment2").unwrap()
63+
Line::parse("pick aaa comment1").unwrap(),
64+
Line::parse("drop bbb comment2").unwrap()
6565
]);
6666
assert!(!module.lines.is_empty());
6767
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
@@ -223,8 +223,8 @@ fn empty_edit_undo_and_edit() {
223223
);
224224
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
225225
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
226-
Line::new("pick aaa comment").unwrap(),
227-
Line::new("drop bbb comment").unwrap()
226+
Line::parse("pick aaa comment").unwrap(),
227+
Line::parse("drop bbb comment").unwrap()
228228
]);
229229
},
230230
);
@@ -387,7 +387,7 @@ fn error_restore_and_abort() {
387387
Artifact::ChangeState(State::List)
388388
);
389389
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
390-
Line::new("pick aaa comment").unwrap()
390+
Line::parse("pick aaa comment").unwrap()
391391
]);
392392
});
393393
}
@@ -407,7 +407,7 @@ fn error_undo_modifications_and_reedit() {
407407
);
408408
assert_external_editor_state_eq!(module.state, ExternalEditorState::Active);
409409
assert_eq!(module.todo_file.lock().get_lines_owned(), vec![
410-
Line::new("pick aaa comment").unwrap()
410+
Line::parse("pick aaa comment").unwrap()
411411
]);
412412
});
413413
}

src/core/src/modules/list/tests/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn noop_list() {
117117
let mut module = create_list(&Config::new(), test_context.take_todo_file());
118118
let mut todo_file = module.todo_file.lock();
119119
todo_file.remove_lines(0, 0);
120-
todo_file.add_line(0, Line::new("noop").unwrap());
120+
todo_file.add_line(0, Line::parse("noop").unwrap());
121121
drop(todo_file);
122122

123123
let view_data = test_context.build_view_data(&mut module);

src/core/src/process/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ fn write_todo_file() {
198198
process
199199
.todo_file
200200
.lock()
201-
.set_lines(vec![Line::new("fixup ddd comment").unwrap()]);
201+
.set_lines(vec![Line::parse("fixup ddd comment").unwrap()]);
202202
process.write_todo_file().unwrap();
203203
process.todo_file.lock().load_file().unwrap();
204204
assert_eq!(
205205
process.todo_file.lock().get_line(0).unwrap(),
206-
&Line::new("fixup ddd comment").unwrap()
206+
&Line::parse("fixup ddd comment").unwrap()
207207
);
208208
},
209209
);

src/core/src/testutil/action_line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lazy_static! {
99

1010
fn parse_rendered_action_line(rendered: &str) -> Result<Line, ParseError> {
1111
let cleaned_line = FORMAT_REGEX.replace_all(rendered, "").replace(" > ", "");
12-
Line::new(cleaned_line.as_ref())
12+
Line::parse(cleaned_line.as_ref())
1313
}
1414

1515
#[derive(Debug)]
@@ -21,7 +21,7 @@ pub(crate) struct ActionPattern {
2121
impl ActionPattern {
2222
fn new(line: &str, selected: bool) -> Self {
2323
Self {
24-
line: Line::new(line).expect("Expected valid pick"),
24+
line: Line::parse(line).expect("Expected valid pick"),
2525
selected,
2626
}
2727
}

src/todo_file/src/history/tests.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ macro_rules! assert_history_items {
3636

3737
fn create_lines() -> Vec<Line> {
3838
vec![
39-
Line::new("pick aaa c1").unwrap(),
40-
Line::new("pick bbb c2").unwrap(),
41-
Line::new("pick ccc c3").unwrap(),
42-
Line::new("pick ddd c4").unwrap(),
43-
Line::new("pick eee c5").unwrap(),
39+
Line::parse("pick aaa c1").unwrap(),
40+
Line::parse("pick bbb c2").unwrap(),
41+
Line::parse("pick ccc c3").unwrap(),
42+
Line::parse("pick ddd c4").unwrap(),
43+
Line::parse("pick eee c5").unwrap(),
4444
]
4545
}
4646

4747
macro_rules! assert_todo_lines {
4848
($lines:expr, $($arg:expr),*) => {
49-
let expected = vec![$( Line::new($arg).unwrap(), )*];
49+
let expected = vec![$( Line::parse($arg).unwrap(), )*];
5050
pretty_assertions::assert_str_eq!(
5151
$lines.iter().map(Line::to_text).collect::<Vec<String>>().join("\n"),
5252
expected.iter().map(Line::to_text).collect::<Vec<String>>().join("\n")
@@ -229,7 +229,7 @@ fn undo_redo_add_range_end_index_at_bottom() {
229229
#[test]
230230
fn undo_redo_remove_start() {
231231
let mut history = History::new(10);
232-
history.record(HistoryItem::new_remove(0, 0, vec![Line::new("drop xxx cx").unwrap()]));
232+
history.record(HistoryItem::new_remove(0, 0, vec![Line::parse("drop xxx cx").unwrap()]));
233233
let mut lines = create_lines();
234234
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 0, 0));
235235
assert_todo_lines!(
@@ -255,7 +255,7 @@ fn undo_redo_remove_start() {
255255
#[test]
256256
fn undo_redo_remove_end() {
257257
let mut history = History::new(10);
258-
history.record(HistoryItem::new_remove(5, 5, vec![Line::new("drop xxx cx").unwrap()]));
258+
history.record(HistoryItem::new_remove(5, 5, vec![Line::parse("drop xxx cx").unwrap()]));
259259
let mut lines = create_lines();
260260
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 5, 5));
261261
assert_todo_lines!(
@@ -281,7 +281,7 @@ fn undo_redo_remove_end() {
281281
#[test]
282282
fn undo_redo_remove_middle() {
283283
let mut history = History::new(10);
284-
history.record(HistoryItem::new_remove(2, 2, vec![Line::new("drop xxx cx").unwrap()]));
284+
history.record(HistoryItem::new_remove(2, 2, vec![Line::parse("drop xxx cx").unwrap()]));
285285
let mut lines = create_lines();
286286
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 2, 2));
287287
assert_todo_lines!(
@@ -308,8 +308,8 @@ fn undo_redo_remove_middle() {
308308
fn undo_redo_remove_range_start_index_top() {
309309
let mut history = History::new(10);
310310
history.record(HistoryItem::new_remove(0, 1, vec![
311-
Line::new("drop xxx cx").unwrap(),
312-
Line::new("drop yyy cy").unwrap(),
311+
Line::parse("drop xxx cx").unwrap(),
312+
Line::parse("drop yyy cy").unwrap(),
313313
]));
314314
let mut lines = create_lines();
315315
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 0, 1));
@@ -338,8 +338,8 @@ fn undo_redo_remove_range_start_index_top() {
338338
fn undo_redo_remove_range_start_index_bottom() {
339339
let mut history = History::new(10);
340340
history.record(HistoryItem::new_remove(6, 5, vec![
341-
Line::new("drop xxx cx").unwrap(),
342-
Line::new("drop yyy cy").unwrap(),
341+
Line::parse("drop xxx cx").unwrap(),
342+
Line::parse("drop yyy cy").unwrap(),
343343
]));
344344
let mut lines = create_lines();
345345
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 6, 5));
@@ -368,8 +368,8 @@ fn undo_redo_remove_range_start_index_bottom() {
368368
fn undo_redo_remove_range_end_index_top() {
369369
let mut history = History::new(10);
370370
history.record(HistoryItem::new_remove(1, 0, vec![
371-
Line::new("drop xxx cx").unwrap(),
372-
Line::new("drop yyy cy").unwrap(),
371+
Line::parse("drop xxx cx").unwrap(),
372+
Line::parse("drop yyy cy").unwrap(),
373373
]));
374374
let mut lines = create_lines();
375375
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 1, 0));
@@ -398,8 +398,8 @@ fn undo_redo_remove_range_end_index_top() {
398398
fn undo_redo_remove_range_end_index_bottom() {
399399
let mut history = History::new(10);
400400
history.record(HistoryItem::new_remove(5, 6, vec![
401-
Line::new("drop xxx cx").unwrap(),
402-
Line::new("drop yyy cy").unwrap(),
401+
Line::parse("drop xxx cx").unwrap(),
402+
Line::parse("drop yyy cy").unwrap(),
403403
]));
404404
let mut lines = create_lines();
405405
assert_some_eq!(history.undo(&mut lines), (Operation::Remove, 5, 6));
@@ -702,7 +702,7 @@ fn undo_redo_swap_down_range_up_index_end() {
702702
#[test]
703703
fn undo_redo_modify_single_index_start() {
704704
let mut history = History::new(10);
705-
history.record(HistoryItem::new_modify(0, 0, vec![Line::new("drop xxx cx").unwrap()]));
705+
history.record(HistoryItem::new_modify(0, 0, vec![Line::parse("drop xxx cx").unwrap()]));
706706
let mut lines = create_lines();
707707
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 0, 0));
708708
assert_todo_lines!(
@@ -727,7 +727,7 @@ fn undo_redo_modify_single_index_start() {
727727
#[test]
728728
fn undo_redo_modify_single_index_end() {
729729
let mut history = History::new(10);
730-
history.record(HistoryItem::new_modify(4, 4, vec![Line::new("drop xxx cx").unwrap()]));
730+
history.record(HistoryItem::new_modify(4, 4, vec![Line::parse("drop xxx cx").unwrap()]));
731731
let mut lines = create_lines();
732732
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 4, 4));
733733
assert_todo_lines!(
@@ -752,7 +752,7 @@ fn undo_redo_modify_single_index_end() {
752752
#[test]
753753
fn undo_redo_modify_single_index_middle() {
754754
let mut history = History::new(10);
755-
history.record(HistoryItem::new_modify(2, 2, vec![Line::new("drop xxx cx").unwrap()]));
755+
history.record(HistoryItem::new_modify(2, 2, vec![Line::parse("drop xxx cx").unwrap()]));
756756
let mut lines = create_lines();
757757
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 2));
758758
assert_todo_lines!(
@@ -778,9 +778,9 @@ fn undo_redo_modify_single_index_middle() {
778778
fn undo_redo_modify_range_down_index_start() {
779779
let mut history = History::new(10);
780780
history.record(HistoryItem::new_modify(0, 2, vec![
781-
Line::new("drop xx1 c1").unwrap(),
782-
Line::new("drop xx2 c2").unwrap(),
783-
Line::new("drop xx3 c3").unwrap(),
781+
Line::parse("drop xx1 c1").unwrap(),
782+
Line::parse("drop xx2 c2").unwrap(),
783+
Line::parse("drop xx3 c3").unwrap(),
784784
]));
785785
let mut lines = create_lines();
786786
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 0, 2));
@@ -807,9 +807,9 @@ fn undo_redo_modify_range_down_index_start() {
807807
fn undo_redo_modify_range_down_index_end() {
808808
let mut history = History::new(10);
809809
history.record(HistoryItem::new_modify(2, 4, vec![
810-
Line::new("drop xx1 c1").unwrap(),
811-
Line::new("drop xx2 c2").unwrap(),
812-
Line::new("drop xx3 c3").unwrap(),
810+
Line::parse("drop xx1 c1").unwrap(),
811+
Line::parse("drop xx2 c2").unwrap(),
812+
Line::parse("drop xx3 c3").unwrap(),
813813
]));
814814
let mut lines = create_lines();
815815
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 4));
@@ -836,9 +836,9 @@ fn undo_redo_modify_range_down_index_end() {
836836
fn undo_redo_modify_range_up_index_start() {
837837
let mut history = History::new(10);
838838
history.record(HistoryItem::new_modify(2, 0, vec![
839-
Line::new("drop xx1 c1").unwrap(),
840-
Line::new("drop xx2 c2").unwrap(),
841-
Line::new("drop xx3 c3").unwrap(),
839+
Line::parse("drop xx1 c1").unwrap(),
840+
Line::parse("drop xx2 c2").unwrap(),
841+
Line::parse("drop xx3 c3").unwrap(),
842842
]));
843843
let mut lines = create_lines();
844844
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 2, 0));
@@ -865,9 +865,9 @@ fn undo_redo_modify_range_up_index_start() {
865865
fn undo_redo_modify_range_up_index_end() {
866866
let mut history = History::new(10);
867867
history.record(HistoryItem::new_modify(4, 2, vec![
868-
Line::new("drop xx1 c1").unwrap(),
869-
Line::new("drop xx2 c2").unwrap(),
870-
Line::new("drop xx3 c3").unwrap(),
868+
Line::parse("drop xx1 c1").unwrap(),
869+
Line::parse("drop xx2 c2").unwrap(),
870+
Line::parse("drop xx3 c3").unwrap(),
871871
]));
872872
let mut lines = create_lines();
873873
assert_some_eq!(history.undo(&mut lines), (Operation::Modify, 4, 2));

src/todo_file/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl TodoFile {
224224
None
225225
}
226226
else {
227-
Some(Line::new(l).map_err(|err| {
227+
Some(Line::parse(l).map_err(|err| {
228228
IoError::FileRead {
229229
file: self.filepath.clone(),
230230
cause: FileReadErrorCause::from(err),
@@ -492,7 +492,7 @@ mod tests {
492492
use super::*;
493493

494494
fn create_line(line: &str) -> Line {
495-
Line::new(line).unwrap()
495+
Line::parse(line).unwrap()
496496
}
497497

498498
fn create_and_load_todo_file(file_contents: &[&str]) -> (TodoFile, NamedTempFile) {

0 commit comments

Comments
 (0)