Fix lint & tests
This commit is contained in:
parent
4c77a0360e
commit
b0ad819ac6
4 changed files with 23 additions and 10 deletions
|
|
@ -371,7 +371,9 @@ where
|
|||
|
||||
Operation::Insert { text, .. } => {
|
||||
if let Some(prev_length) = previous_equal {
|
||||
result.push(NumberOrString::Number(prev_length as i64));
|
||||
result.push(NumberOrString::Number(
|
||||
i64::try_from(prev_length).unwrap_or(i64::MAX),
|
||||
));
|
||||
previous_equal = None;
|
||||
}
|
||||
|
||||
|
|
@ -387,17 +389,22 @@ where
|
|||
..
|
||||
} => {
|
||||
if let Some(prev_length) = previous_equal {
|
||||
result.push(NumberOrString::Number(prev_length as i64));
|
||||
result.push(NumberOrString::Number(
|
||||
i64::try_from(prev_length).unwrap_or(i64::MAX),
|
||||
));
|
||||
previous_equal = None;
|
||||
}
|
||||
|
||||
result.push(NumberOrString::Number(-(*deleted_character_count as i64)));
|
||||
let count = i64::try_from(*deleted_character_count).unwrap_or(i64::MAX);
|
||||
result.push(NumberOrString::Number(-count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(prev_length) = previous_equal {
|
||||
result.push(NumberOrString::Number(prev_length as i64));
|
||||
result.push(NumberOrString::Number(
|
||||
i64::try_from(prev_length).unwrap_or(i64::MAX),
|
||||
));
|
||||
}
|
||||
|
||||
result
|
||||
|
|
@ -417,7 +424,7 @@ where
|
|||
match simple_operation {
|
||||
NumberOrString::Number(length) => {
|
||||
if length >= 0 {
|
||||
let length = length as usize;
|
||||
let length = usize::try_from(length).unwrap_or(usize::MAX);
|
||||
let original_characters: String =
|
||||
original_text.chars().skip(order).take(length).collect();
|
||||
|
||||
|
|
@ -428,7 +435,7 @@ where
|
|||
order += token.get_original_length();
|
||||
}
|
||||
} else {
|
||||
let length = -length as usize;
|
||||
let length = usize::try_from(-length).unwrap_or(usize::MAX);
|
||||
operations.push(Operation::create_delete(order, length));
|
||||
order += length;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ impl TextWithCursorsAndHistory {
|
|||
/// Returns the UTF8 parsed string if it's a text, or `None` if it's likely
|
||||
/// binary.
|
||||
#[must_use]
|
||||
pub fn string_or_nothing(data: &[u8]) -> Option<String> {
|
||||
fn string_or_nothing(data: &[u8]) -> Option<String> {
|
||||
if data.contains(&0) {
|
||||
// Even though the NUL character is valid in UTF-8, it's highly suspicious in
|
||||
// human-readable text.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod example_document;
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use example_document::ExampleDocument;
|
||||
use reconcile_text::{BuiltinTokenizer, EditedText, reconcile};
|
||||
use reconcile_text::{BuiltinTokenizer, reconcile};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[test]
|
||||
|
|
@ -37,6 +37,8 @@ fn test_document_one_way_with_cursors() {
|
|||
#[cfg(feature = "serde")]
|
||||
#[test]
|
||||
fn test_document_one_way_with_serialisation() {
|
||||
use reconcile_text::EditedText;
|
||||
|
||||
for doc in &get_all_documents() {
|
||||
let parent = doc.parent();
|
||||
let left_operations =
|
||||
|
|
|
|||
|
|
@ -59,8 +59,12 @@ fn test_merge_binary() {
|
|||
fn test_get_compact_diff() {
|
||||
let parent = "hello ";
|
||||
let changed = "world";
|
||||
|
||||
let result = get_compact_diff(parent, &changed.into(), BuiltinTokenizer::Word);
|
||||
|
||||
assert_eq!(result.len(), 2);
|
||||
assert_eq!(result[0].as_f64().unwrap(), -6.0);
|
||||
assert_eq!(result[1].as_string().unwrap(), "world");
|
||||
let first: i64 = result[0].clone().try_into().unwrap();
|
||||
let second: String = result[1].clone().try_into().unwrap();
|
||||
assert_eq!(first, -6);
|
||||
assert_eq!(second, "world");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue