Revert oversimplifications
This commit is contained in:
parent
03856fe868
commit
5170bf02ca
2 changed files with 72 additions and 89 deletions
|
|
@ -40,10 +40,9 @@ impl ExampleDocument {
|
|||
/// If the result string does not match the expected string, the program
|
||||
/// will panic.
|
||||
pub fn assert_eq(&self, result: &EditedText<'_, String>) {
|
||||
let result_str = ExampleDocument::text_with_cursors_to_string(result);
|
||||
assert_eq!(
|
||||
self.expected, result_str,
|
||||
"Left (expected) isn't equal to right (actual). Actual: ```\n{result_str}```",
|
||||
Self::string_to_text_with_cursors(&self.expected),
|
||||
result.apply()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -62,30 +61,6 @@ impl ExampleDocument {
|
|||
);
|
||||
}
|
||||
|
||||
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 '{}.'",
|
||||
cursor.char_index(),
|
||||
result.len(),
|
||||
result
|
||||
);
|
||||
|
||||
result.insert(
|
||||
result
|
||||
.char_indices()
|
||||
.nth(cursor.char_index() + i)
|
||||
.map_or_else(|| result.len(), |(byte_index, _)| byte_index), /* find the utf8 char index of the insert
|
||||
* in byte index */
|
||||
'|',
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn string_to_text_with_cursors(text: &str) -> TextWithCursors {
|
||||
let cursors = Self::parse_cursors(text);
|
||||
let text = text.replace('|', "");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![cfg(feature = "wasm")]
|
||||
|
||||
use reconcile_text::{BuiltinTokenizer, CursorPosition, TextWithCursors, wasm::*};
|
||||
use reconcile_text::{BuiltinTokenizer, CursorPosition, EditedText, TextWithCursors, wasm::*};
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
|
|
@ -55,6 +55,16 @@ fn test_merge_binary() {
|
|||
);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
fn test_from_diff_rejects_oversized_lengths() {
|
||||
for length in [1_i64 << 32, -(1_i64 << 40), i64::MAX, i64::MIN] {
|
||||
let error = EditedText::from_diff("abc", vec![length.into()], &*BuiltinTokenizer::Word)
|
||||
.unwrap_err();
|
||||
|
||||
assert!(error.to_string().starts_with("Invalid diff:"));
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test] // JsValue isn't supported outside of wasm
|
||||
fn test_diff() {
|
||||
let parent = "hello ";
|
||||
|
|
|
|||
Loading…
Reference in a new issue