Don't depend on serde for wasm

This commit is contained in:
Andras Schmelczer 2025-11-16 12:29:30 +00:00
parent d0ce566118
commit 4c77a0360e
14 changed files with 251 additions and 314 deletions

View file

@ -34,8 +34,9 @@ fn test_document_one_way_with_cursors() {
}
}
#[cfg(feature = "serde")]
#[test]
fn test_document_one_way_with_cursors_and_serialisation() {
fn test_document_one_way_with_serialisation() {
for doc in &get_all_documents() {
let parent = doc.parent();
let left_operations =
@ -47,19 +48,23 @@ fn test_document_one_way_with_cursors_and_serialisation() {
);
let serialised_left =
serde_yaml::from_str(&serde_yaml::to_string(&left_operations.to_change_set()).unwrap())
serde_yaml::from_str(&serde_yaml::to_string(&left_operations.to_changes()).unwrap())
.unwrap();
let serialised_right =
serde_yaml::from_str(&serde_yaml::to_string(&right_operations.to_changes()).unwrap())
.unwrap();
let serialised_right = serde_yaml::from_str(
&serde_yaml::to_string(&right_operations.to_change_set()).unwrap(),
)
.unwrap();
let restored_left_operations =
EditedText::from_change_set(&parent, serialised_left, &*BuiltinTokenizer::Word);
EditedText::from_changes(&parent, serialised_left, &*BuiltinTokenizer::Word);
let restored_right_operations =
EditedText::from_change_set(&parent, serialised_right, &*BuiltinTokenizer::Word);
EditedText::from_changes(&parent, serialised_right, &*BuiltinTokenizer::Word);
doc.assert_eq(&restored_left_operations.merge(restored_right_operations));
doc.assert_eq_without_cursors(
&restored_left_operations
.merge(restored_right_operations)
.apply()
.text(),
);
}
}

View file

@ -55,10 +55,12 @@ fn test_merge_binary() {
);
}
#[wasm_bindgen_test(unsupported = test)]
#[wasm_bindgen_test] // JsValue isn't supported outside of wasm
fn test_get_compact_diff() {
let parent = "hello ";
let changed = "world";
let result = get_compact_diff(parent, &changed.into(), BuiltinTokenizer::Word);
assert_eq!(result, "{\"operations\":[-6,\"world\"],\"cursors\":[]}");
assert_eq!(result.len(), 2);
assert_eq!(result[0].as_f64().unwrap(), -6.0);
assert_eq!(result[1].as_string().unwrap(), "world");
}