Remove diff mod
This commit is contained in:
parent
763f74a0e2
commit
07f3a5f795
9 changed files with 29 additions and 27 deletions
|
|
@ -1,2 +0,0 @@
|
|||
pub mod myers;
|
||||
pub mod raw_operation;
|
||||
|
|
@ -1,9 +1,15 @@
|
|||
use crate::tokenizer::token::Token;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::{tokenizer::token::Token, utils::myers_diff::myers_diff};
|
||||
|
||||
/// Text editing operation containing the to-be-changed `Tokens`-s.
|
||||
///
|
||||
/// RawOperations can be joined together when the underlying tokens
|
||||
/// allow for joining subseqeunt operations.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum RawOperation<T>
|
||||
where
|
||||
T: PartialEq + Clone + std::fmt::Debug,
|
||||
T: PartialEq + Clone + Debug,
|
||||
{
|
||||
Insert(Vec<Token<T>>),
|
||||
Delete(Vec<Token<T>>),
|
||||
|
|
@ -12,8 +18,10 @@ where
|
|||
|
||||
impl<T> RawOperation<T>
|
||||
where
|
||||
T: PartialEq + Clone + std::fmt::Debug,
|
||||
T: PartialEq + Clone + Debug,
|
||||
{
|
||||
pub fn vec_from(left: &[Token<T>], right: &[Token<T>]) -> Vec<Self> { myers_diff(left, right) }
|
||||
|
||||
pub fn tokens(&self) -> &Vec<Token<T>> {
|
||||
match self {
|
||||
RawOperation::Insert(tokens)
|
||||
|
|
@ -41,7 +49,7 @@ where
|
|||
/// Extends the operation with another operation. Only operations of the
|
||||
/// same type as self can be used to extend self, otherwise the function
|
||||
/// will panic.
|
||||
pub fn extend(self, other: RawOperation<T>) -> RawOperation<T> {
|
||||
pub fn join(self, other: RawOperation<T>) -> RawOperation<T> {
|
||||
debug_assert!(
|
||||
std::mem::discriminant(&self) == std::mem::discriminant(&other),
|
||||
"Cannot extend operations of different types. This should have been handled before \
|
||||
|
|
@ -2,5 +2,6 @@ pub mod common_prefix_len;
|
|||
pub mod common_suffix_len;
|
||||
pub mod find_longest_prefix_contained_within;
|
||||
pub mod history;
|
||||
pub mod myers_diff;
|
||||
pub mod side;
|
||||
pub mod string_builder;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ use std::{
|
|||
vec,
|
||||
};
|
||||
|
||||
use super::raw_operation::RawOperation;
|
||||
use crate::{
|
||||
raw_operation::RawOperation,
|
||||
tokenizer::token::Token,
|
||||
utils::{common_prefix_len::common_prefix_len, common_suffix_len::common_suffix_len},
|
||||
};
|
||||
|
|
@ -35,8 +35,8 @@ use crate::{
|
|||
/// Diff `old`, between indices `old_range` and `new` between indices
|
||||
/// `new_range`.
|
||||
///
|
||||
/// The returned `RawOperations` all have a token count of 1.
|
||||
pub fn diff<T>(old: &[Token<T>], new: &[Token<T>]) -> Vec<RawOperation<T>>
|
||||
/// The returned `RawOperations` each wrap a single token.
|
||||
pub fn myers_diff<T>(old: &[Token<T>], new: &[Token<T>]) -> Vec<RawOperation<T>>
|
||||
where
|
||||
T: PartialEq + Clone + std::fmt::Debug,
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ where
|
|||
|
||||
debug_assert!(
|
||||
result.iter().all(|op| op.tokens().len() == 1),
|
||||
"All operations should be of length 1"
|
||||
"All operations must be of length 1"
|
||||
);
|
||||
|
||||
result
|
||||
|
|
@ -80,7 +80,7 @@ where
|
|||
#[derive(Debug)]
|
||||
struct V {
|
||||
offset: isize,
|
||||
v: Vec<usize>, // Look into initializing this to -1 and storing isize
|
||||
v: Vec<usize>,
|
||||
}
|
||||
|
||||
impl V {
|
||||
|
|
@ -312,14 +312,14 @@ mod tests {
|
|||
fn test_empty_diff() {
|
||||
let old: Vec<Token<String>> = vec![];
|
||||
let new: Vec<Token<String>> = vec![];
|
||||
let result = diff(&old, &new);
|
||||
let result = myers_diff(&old, &new);
|
||||
assert_eq!(result.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_identical_content() {
|
||||
let content = vec!["a".into(), "b".into(), "c".into()];
|
||||
let result = diff(&content, &content);
|
||||
let result = myers_diff(&content, &content);
|
||||
assert_debug_snapshot!(result);
|
||||
}
|
||||
|
||||
|
|
@ -327,7 +327,7 @@ mod tests {
|
|||
fn test_insert_only() {
|
||||
let old: Vec<Token<String>> = vec![];
|
||||
let new: Vec<Token<String>> = vec!["a".into(), "b".into()];
|
||||
let result = diff(&old, &new);
|
||||
let result = myers_diff(&old, &new);
|
||||
assert_debug_snapshot!(result);
|
||||
}
|
||||
|
||||
|
|
@ -335,7 +335,7 @@ mod tests {
|
|||
fn test_delete_only() {
|
||||
let old = vec!["a".into(), "b".into()];
|
||||
let new: Vec<Token<String>> = vec![];
|
||||
let result = diff(&old, &new);
|
||||
let result = myers_diff(&old, &new);
|
||||
assert_debug_snapshot!(result);
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ mod tests {
|
|||
fn test_prefix_and_suffix() {
|
||||
let old = vec!["a".into(), "b".into(), "c".into(), "d".into()];
|
||||
let new = vec!["a".into(), "x".into(), "d".into()];
|
||||
let result = diff(&old, &new);
|
||||
let result = myers_diff(&old, &new);
|
||||
assert_debug_snapshot!(result);
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +351,7 @@ mod tests {
|
|||
fn test_complex_diff() {
|
||||
let old = vec!["a".into(), "b".into(), "c".into(), "d".into()];
|
||||
let new = vec!["a".into(), "x".into(), "c".into(), "y".into()];
|
||||
let result = diff(&old, &new);
|
||||
let result = myers_diff(&old, &new);
|
||||
assert_debug_snapshot!(result);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
source: reconcile/src/diffs/myers.rs
|
||||
source: src/utils/myers_diff.rs
|
||||
expression: result
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
Equal(
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
source: reconcile/src/diffs/myers.rs
|
||||
source: src/utils/myers_diff.rs
|
||||
expression: result
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
Delete(
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
source: reconcile/src/diffs/myers.rs
|
||||
source: src/utils/myers_diff.rs
|
||||
expression: result
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
Equal(
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
source: reconcile/src/diffs/myers.rs
|
||||
source: src/utils/myers_diff.rs
|
||||
expression: result
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
Insert(
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
---
|
||||
source: reconcile/src/diffs/myers.rs
|
||||
source: src/utils/myers_diff.rs
|
||||
expression: result
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
Equal(
|
||||
Loading…
Add table
Add a link
Reference in a new issue