Lines
100 %
Functions
Branches
use crate::history::{Operation, OperationType};
use crate::Position;
#[test]
fn test_insert_operation_end_position() {
let op = Operation {
op_type: OperationType::Insert,
content: String::from("Hello"),
start_position: Position { x: 0, y: 0 },
};
assert_eq!(op.end_position(&[5]), Position { x: 4, y: 0 });
let op_with_newline = Operation {
content: String::from("Hello\nWorld"),
assert_eq!(
op_with_newline.end_position(&[5, 5]),
Position { x: 4, y: 1 }
);
let op_starting_with_newline = Operation {
content: String::from("\nHello\nWorld"),
op_starting_with_newline.end_position(&[0, 5, 5]),
Position { x: 4, y: 2 }
let op_starting_with_newline_not_at_start_of_doc = Operation {
content: String::from("\nplop"),
start_position: Position { x: 11, y: 0 },
op_starting_with_newline_not_at_start_of_doc.end_position(&[0, 4]),
Position { x: 3, y: 1 }
}
fn test_insert_operation_with_multiple_adjacent_newlines_end_position() {
let op_starting_with_adjacent_newlines = Operation {
content: String::from("hello\n\n\nplop"),
op_starting_with_adjacent_newlines.end_position(&[5, 0, 0, 4]),
Position { x: 3, y: 3 }
fn test_delete_operation_end_position() {
op_type: OperationType::Delete,
content: String::from("olleH"),
start_position: Position { x: 4, y: 0 },
assert_eq!(op.end_position(&[5]), Position { x: 0, y: 0 });
content: String::from("dlrow\nolleH"),
start_position: Position { x: 4, y: 1 },
Position { x: 0, y: 0 }
fn test_operation_reversed() {
content: String::from("Hello\n"),
let op_rev = op.reversed(&[5]);
op_rev,
Operation {
content: String::from("\nolleH"),
start_position: Position { x: 0, y: 1 },
let op_rev_rev = op_rev.reversed(&[5, 0]);
assert_eq!(op_rev_rev, op);
fn test_operation_end_position_insert_single_line() {
content: String::from("rûst"),
assert_eq!(op.end_position(&[4]), Position { x: 3, y: 0 });
fn test_operation_end_position_insert_multi_line() {
content: String::from("rûst\nröcks"),
assert_eq!(op.end_position(&[4, 5]), Position { x: 4, y: 1 });
fn test_operation_end_position_insert_multiple_words() {
content: String::from("rûst röcks"),
assert_eq!(op.end_position(&[10]), Position { x: 9, y: 0 });
fn test_operation_end_position_insert_multi_line_starting_with_newline() {
content: String::from("\nrûst\nröcks"),
assert_eq!(op.end_position(&[0, 4, 5]), Position { x: 4, y: 2 });
fn test_operation_end_position_delete_single_line() {
content: String::from("tsûr"),
start_position: Position { x: 3, y: 0 },
assert_eq!(op.end_position(&[4]), Position { x: 0, y: 0 });
fn test_operation_end_position_delete_multiple_words() {
content: String::from("skcör tsûr"),
start_position: Position { x: 9, y: 0 },
assert_eq!(op.end_position(&[10]), Position { x: 0, y: 0 });
fn test_operation_end_position_delete_multi_line() {
content: String::from("skcör\ntsur"),
assert_eq!(op.end_position(&[4, 5]), Position { x: 0, y: 0 });
fn test_operation_end_position_delete_multi_line_starting_with_newline() {
content: String::from("\nskcör\ntsur"),
start_position: Position { x: 0, y: 2 },
assert_eq!(op.end_position(&[4, 5, 0]), Position { x: 0, y: 0 });