mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
chore: more tests, imports
This commit is contained in:
parent
da44aff408
commit
10e4a458ce
2 changed files with 22 additions and 6 deletions
|
@ -3,8 +3,6 @@
|
|||
//! an editor-friendly representation of a text change in a buffer
|
||||
//! to easily interface with codemp from various editors
|
||||
|
||||
use crate::proto::RowCol;
|
||||
|
||||
/// an editor-friendly representation of a text change in a buffer
|
||||
///
|
||||
/// this represent a range in the previous state of the string and a new content which should be
|
||||
|
@ -82,10 +80,10 @@ impl TextChange {
|
|||
|
||||
/// convert from byte index to row and column
|
||||
/// txt must be the whole content of the buffer, in order to count lines
|
||||
pub fn index_to_rowcol(txt: &str, index: usize) -> RowCol {
|
||||
pub fn index_to_rowcol(txt: &str, index: usize) -> crate::proto::RowCol {
|
||||
let row = txt[..index].matches('\n').count() as i32;
|
||||
let col = txt[..index].split('\n').last().unwrap_or("").len() as i32;
|
||||
RowCol { row, col }
|
||||
crate::proto::RowCol { row, col }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,4 +139,24 @@ mod tests {
|
|||
let result = change.apply("hello cruel world!");
|
||||
assert_eq!(result, "hello not very pleasant world!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn textchange_apply_never_panics() {
|
||||
let change = super::TextChange { span: 100..110, content: "a very long string \n which totally matters".to_string() };
|
||||
let result = change.apply("a short text");
|
||||
assert_eq!(result, "a short texta very long string \n which totally matters");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_diff_produces_empty_textchange() {
|
||||
let change = super::TextChange::from_diff("same \n\n text", "same \n\n text");
|
||||
assert!(change.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_textchange_doesnt_alter_buffer() {
|
||||
let change = super::TextChange { span: 42..42, content: "".to_string() };
|
||||
let result = change.apply("some important text");
|
||||
assert_eq!(result, "some important text");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
use std::{sync::Arc, collections::BTreeMap};
|
||||
|
||||
use tokio::sync::mpsc;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
use crate::{
|
||||
api::Controller,
|
||||
cursor::{worker::CursorControllerWorker, controller::CursorController},
|
||||
proto::{
|
||||
buffer_client::BufferClient, cursor_client::CursorClient, UserIdentity, BufferPayload,
|
||||
|
|
Loading…
Reference in a new issue