Remove the exponential API
This commit is contained in:
parent
0448e30dd9
commit
4fda83fe17
8 changed files with 248 additions and 150 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use reconcile::{CursorPosition, TextWithCursors};
|
||||
use reconcile::{CursorPosition, EditedText, TextWithCursors};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// `ExampleDocument` represents a test case for the reconciliation process.
|
||||
|
|
@ -37,7 +37,7 @@ impl ExampleDocument {
|
|||
///
|
||||
/// If the result string does not match the expected string, the program
|
||||
/// will panic.
|
||||
pub fn assert_eq(&self, result: &TextWithCursors) {
|
||||
pub fn assert_eq(&self, result: &EditedText<'_, String>) {
|
||||
let result_str = ExampleDocument::text_with_cursors_to_string(result);
|
||||
assert_eq!(
|
||||
self.expected, result_str,
|
||||
|
|
@ -60,14 +60,16 @@ impl ExampleDocument {
|
|||
);
|
||||
}
|
||||
|
||||
fn text_with_cursors_to_string(document: &TextWithCursors) -> String {
|
||||
let mut result = document.text().clone();
|
||||
for (i, cursor) in document.cursors().iter().enumerate() {
|
||||
fn text_with_cursors_to_string(document: &EditedText<'_, String>) -> String {
|
||||
let merged = document.apply();
|
||||
let mut result = merged.text();
|
||||
for (i, cursor) in merged.cursors().iter().enumerate() {
|
||||
assert!(
|
||||
cursor.char_index <= result.len(), // equals in case of insert at the end
|
||||
"Cursor index out of bounds: {} > {} when testing for '{result}'",
|
||||
"Cursor index out of bounds: {} > {} when testing for '{}.'",
|
||||
cursor.char_index,
|
||||
result.len()
|
||||
result.len(),
|
||||
result
|
||||
);
|
||||
|
||||
result.insert(
|
||||
|
|
@ -85,7 +87,7 @@ impl ExampleDocument {
|
|||
fn string_to_text_with_cursors(text: &str) -> TextWithCursors {
|
||||
let cursors = Self::parse_cursors(text);
|
||||
let text = text.replace('|', "");
|
||||
TextWithCursors::new_owned(text, cursors)
|
||||
TextWithCursors::new(text, cursors)
|
||||
}
|
||||
|
||||
fn parse_cursors(text: &str) -> Vec<CursorPosition> {
|
||||
|
|
|
|||
|
|
@ -3,27 +3,33 @@ mod example_document;
|
|||
use std::{fs, path::Path};
|
||||
|
||||
use example_document::ExampleDocument;
|
||||
use reconcile::{reconcile, reconcile_with_cursors};
|
||||
use reconcile::{BuiltinTokenizer, reconcile};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[test]
|
||||
fn test_document_one_way_without_cursors() {
|
||||
for doc in &get_all_documents() {
|
||||
doc.assert_eq_without_cursors(&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.left().text(),
|
||||
&doc.right().text(),
|
||||
));
|
||||
doc.assert_eq_without_cursors(
|
||||
&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.left().text().into(),
|
||||
&doc.right().text().into(),
|
||||
&*BuiltinTokenizer::Word,
|
||||
)
|
||||
.apply()
|
||||
.text(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_document_one_way_with_cursors() {
|
||||
for doc in &get_all_documents() {
|
||||
doc.assert_eq(&reconcile_with_cursors(
|
||||
doc.assert_eq(&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.left(),
|
||||
&doc.right(),
|
||||
&*BuiltinTokenizer::Word,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -31,21 +37,27 @@ fn test_document_one_way_with_cursors() {
|
|||
#[test]
|
||||
fn test_document_inverse_way_without_cursors() {
|
||||
for doc in &get_all_documents() {
|
||||
doc.assert_eq_without_cursors(&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.right().text(),
|
||||
&doc.left().text(),
|
||||
));
|
||||
doc.assert_eq_without_cursors(
|
||||
&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.right().text().into(),
|
||||
&doc.left().text().into(),
|
||||
&*BuiltinTokenizer::Word,
|
||||
)
|
||||
.apply()
|
||||
.text(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_document_inverse_way_with_cursors() {
|
||||
for doc in &get_all_documents() {
|
||||
doc.assert_eq(&reconcile_with_cursors(
|
||||
doc.assert_eq(&reconcile(
|
||||
&doc.parent(),
|
||||
&doc.right(),
|
||||
&doc.left(),
|
||||
&*BuiltinTokenizer::Word,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
#![cfg(feature = "wasm")]
|
||||
|
||||
use reconcile::{CursorPosition, TextWithCursors, wasm::*};
|
||||
use reconcile::{BuiltinTokenizer, CursorPosition, TextWithCursors, wasm::*};
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
fn test_merge() {
|
||||
let left = b"hello ";
|
||||
let right = b"world";
|
||||
let result = merge(b"", left, right);
|
||||
let result = generic_reconcile(b"", left, right, BuiltinTokenizer::Word);
|
||||
assert_eq!(result, b"hello world");
|
||||
|
||||
let left = b"\0binary";
|
||||
let right = b"other";
|
||||
let result = merge(b"", left, right);
|
||||
let result = generic_reconcile(b"", left, right, BuiltinTokenizer::Word);
|
||||
assert_eq!(result, right);
|
||||
}
|
||||
|
||||
|
|
@ -20,19 +20,20 @@ fn test_merge() {
|
|||
fn test_merge_text() {
|
||||
let left = "hello ";
|
||||
let right = "world";
|
||||
let result = merge_text("", left, right);
|
||||
let result = reconcile("", &left.into(), &right.into(), BuiltinTokenizer::Word).text();
|
||||
assert_eq!(result, "hello world");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
fn test_merge_text_with_cursors() {
|
||||
let result = merge_text_with_cursors(
|
||||
let result = reconcile(
|
||||
"hi",
|
||||
&TextWithCursors::new("hi world".to_owned(), vec![]),
|
||||
&TextWithCursors::new(
|
||||
"hi".to_owned(),
|
||||
vec![CursorPosition::new(0, 1), CursorPosition::new(1, 2)],
|
||||
),
|
||||
BuiltinTokenizer::Word,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
|
@ -48,7 +49,10 @@ fn test_merge_text_with_cursors() {
|
|||
fn merge_binary() {
|
||||
let left = [0, 1, 2];
|
||||
let right = [3, 4, 5];
|
||||
assert_eq!(merge(b"", &left, &right), right);
|
||||
assert_eq!(
|
||||
generic_reconcile(b"", &left, &right, BuiltinTokenizer::Word),
|
||||
right
|
||||
);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue