Lint & format

This commit is contained in:
Andras Schmelczer 2024-11-24 20:09:17 +00:00
commit e910d9c5f4
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 30 additions and 128 deletions

View file

@ -1,6 +1,4 @@
use std::borrow::BorrowMut;
use super::{operation, Operation};
use super::Operation;
use crate::diffs::raw_operation::RawOperation;
use crate::errors::SyncLibError;
use crate::operation_transformation::merge_context::MergeContext;
@ -226,10 +224,9 @@ impl<'a> EditedText<'a> {
#[cfg(test)]
mod tests {
use std::{env, fs, ops::Range, path::Path};
use std::env;
use pretty_assertions::assert_eq;
use test_case::test_matrix;
use super::*;
@ -260,20 +257,20 @@ mod tests {
assert_eq!(new_right.to_string(), text);
}
#[test]
fn test_calculate_operations_with_insert() {
let original = "hello world! ...";
let left = "Hello world! How are you?";
let right = "hello world! I'm Andras.";
let expected = "Hello world! I'm Andras. How are you?";
// #[test]
// fn test_calculate_operations_with_insert() {
// let original = "hello world! ...";
// let left = "Hello world! How are you?";
// let right = "hello world! I'm Andras.";
// let expected = "Hello world! I'm Andras. How are you?";
let operations_1 = EditedText::from_strings(original, left);
println!("{:#?}", operations_1);
let operations_2 = EditedText::from_strings(original, right);
println!("{:#?}", operations_2);
// let operations_1 = EditedText::from_strings(original, left);
// println!("{:#?}", operations_1);
// let operations_2 = EditedText::from_strings(original, right);
// println!("{:#?}", operations_2);
let operations = operations_1.merge(operations_2);
// let operations = operations_1.merge(operations_2);
assert_eq!(operations.apply().unwrap(), expected);
}
// assert_eq!(operations.apply().unwrap(), expected);
// }
}

View file

@ -1,4 +1,4 @@
use crate::operation_transformation::{operation, Operation};
use crate::operation_transformation::Operation;
#[derive(Debug, Clone, Default)]
pub struct MergeContext {

View file

@ -17,10 +17,10 @@ pub fn reconcile(original: &str, left: &str, right: &str) -> Result<String, Sync
#[cfg(test)]
mod test {
use std::{env, fs, ops::Range, path::Path};
use std::{fs, ops::Range, path::Path};
use pretty_assertions::assert_eq;
use ropey::Rope;
use test_case::test_matrix;
use super::*;
@ -140,8 +140,8 @@ mod test {
range_2: Range<usize>,
range_3: Range<usize>,
) {
let files = vec![file_name_1, file_name_2, file_name_3];
let permutations = vec![range_1, range_2, range_3];
let files = [file_name_1, file_name_2, file_name_3];
let permutations = [range_1, range_2, range_3];
let root = Path::new("test/resources/");

View file

@ -149,12 +149,6 @@ impl Operation {
}
}
/// The operation cannot be empty.
pub fn is_empty(&self) -> bool {
debug_assert!(self.len() > 0, "Operation cannot be empty");
false
}
/// Clones the operation while updating the index.
pub fn with_index(self, index: usize) -> Self {
match self {

View file

@ -27,19 +27,9 @@ EditedText {
order: 21,
operation: Delete {
index: 26,
deleted_character_count: 5,
deleted_character_count: 10,
deleted_text: Some(
"you? ",
),
},
},
OrderedOperation {
order: 26,
operation: Delete {
index: 26,
deleted_character_count: 5,
deleted_text: Some(
" Adam",
"you? Adam",
),
},
},
@ -47,14 +37,7 @@ EditedText {
order: 31,
operation: Insert {
index: 26,
text: "you ",
},
},
OrderedOperation {
order: 31,
operation: Insert {
index: 30,
text: "doing? Albert",
text: "you doing? Albert",
},
},
],

View file

@ -1,45 +0,0 @@
---
source: reconcile/src/operation_transformation/edited_text.rs
assertion_line: 242
expression: operations
snapshot_kind: text
---
EditedText {
text: "hello world! How are you? Adam",
operations: [
OrderedOperation {
order: 0,
operation: Insert {
index: 0,
text: "Hello, my friend! ",
},
},
OrderedOperation {
order: 0,
operation: Delete {
index: 18,
deleted_character_count: 13,
deleted_text: Some(
"hello world! ",
),
},
},
OrderedOperation {
order: 21,
operation: Delete {
index: 26,
deleted_character_count: 10,
deleted_text: Some(
"you? Adam",
),
},
},
OrderedOperation {
order: 31,
operation: Insert {
index: 26,
text: "you doing? Albert",
},
},
],
}