forked from mars/breed
1
0
Fork 0

Add some actions unit tests

This commit is contained in:
mars 2023-04-13 01:05:45 -04:00
parent e9c8cd7a06
commit 878f47c7e9
1 changed files with 54 additions and 0 deletions

View File

@ -159,3 +159,57 @@ pub fn insert_newline(state: &mut State) {
state.cursor.line += 1;
state.cursor.column = 0;
}
#[cfg(test)]
mod tests {
use super::*;
fn state(src: &str) -> State {
State::from_str(None, src).unwrap()
}
#[test]
fn backspace_empty() {
let mut state = state("");
delete_char_backward(&mut state);
}
#[test]
fn append_on_newline() {
let mut state = state("test\ntest\n");
state.cursor.column = 4;
append_mode(&mut state);
assert_eq!(state.cursor.line, 1);
assert_eq!(state.cursor.column, 0);
}
#[test]
fn append_at_eof() {
let mut state = state("test\n");
state.cursor.column = 4;
append_mode(&mut state);
assert_eq!(state.cursor.line, 1);
assert_eq!(state.cursor.column, 0);
}
#[test]
fn move_line_up_preserve_column() {
let mut state = state("test\n\ntest\n");
state.cursor.line = 2;
state.cursor.column = 3;
move_line_up(&mut state);
move_line_up(&mut state);
assert_eq!(state.cursor.line, 0);
assert_eq!(state.cursor.column, 3);
}
#[test]
fn move_line_down_preserve_column() {
let mut state = state("test\n\ntest\n");
state.cursor.column = 3;
move_line_down(&mut state);
move_line_down(&mut state);
assert_eq!(state.cursor.line, 2);
assert_eq!(state.cursor.column, 3);
}
}