Implement EditorBuffer::move_cursor_to_line_number()
This commit is contained in:
parent
5d82c84239
commit
28ce802116
|
|
@ -93,8 +93,8 @@ impl EditorBuffer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_cursor_to_line_number(&self, _line_num: usize) -> CommandResult {
|
fn move_cursor_to_line_number(&self, line_num: usize) -> CommandResult {
|
||||||
todo!()
|
self.move_cursor_to_point(Point::LineColumn(line_num, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_char(&self, c: char) -> CommandResult {
|
fn insert_char(&self, c: char) -> CommandResult {
|
||||||
|
|
@ -321,4 +321,57 @@ mod tests {
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(expected_lines, found_lines);
|
assert_eq!(expected_lines, found_lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn insert_line() {
|
||||||
|
let mut test_file = create_simple_test_file();
|
||||||
|
let mut file_contents = String::new();
|
||||||
|
test_file
|
||||||
|
.read_to_string(&mut file_contents)
|
||||||
|
.expect("Reading text file");
|
||||||
|
let test_file = test_file;
|
||||||
|
let mut expected_lines: Vec<_> = file_contents.lines().collect();
|
||||||
|
expected_lines.insert(6, "abc 123".into());
|
||||||
|
|
||||||
|
let target = EditorBuffer::new();
|
||||||
|
let result = target.execute(Command::OpenFile(test_file.path().into()));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::MoveCursorToLine(7));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('a'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('b'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('c'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar(' '));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('1'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('2'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('3'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let result = target.execute(Command::InsertChar('\n'));
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let target = result.buffer;
|
||||||
|
let found_lines: Vec<String> = target
|
||||||
|
.buffer
|
||||||
|
.iter_chars()
|
||||||
|
.collect::<String>()
|
||||||
|
.lines()
|
||||||
|
.map(|l| l.into())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected_lines, found_lines);
|
||||||
|
assert_eq!(Point::LineColumn(8, 0), target.get_cursor_position());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue