Skip to content

Commit

Permalink
feat: add text update API (#404)
Browse files Browse the repository at this point in the history
* feat: add diff algorithm

* feat: implement DiffHook

* feat: add rust/typescript API

* feat: use u8 to enable SIMD

* feat: add SIMD support

* test: add a failed test case

* revert: change to unicode index

* fix: text event index correctness when using utf8 or unicode

* fix: use unicode index

* fix: apply delta

* fix: remove splice_unicode

---------

Co-authored-by: Zixuan Chen <remch183@outlook.com>
  • Loading branch information
Lampese and zxch3n authored Jul 23, 2024
1 parent b8f9faf commit e01505e
Show file tree
Hide file tree
Showing 15 changed files with 846 additions and 146 deletions.
29 changes: 15 additions & 14 deletions crates/fuzz/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/fuzz/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ libfuzzer-sys = "0.4"
[dependencies.fuzz]
path = ".."

[dependencies.loro]
path = "../../loro"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
Expand Down Expand Up @@ -44,3 +47,9 @@ name = "counter"
path = "fuzz_targets/counter.rs"
test = false
doc = false

[[bin]]
name = "text-update"
path = "fuzz_targets/text-update.rs"
test = false
doc = false
15 changes: 15 additions & 0 deletions crates/fuzz/fuzz/fuzz_targets/text-update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use loro::LoroDoc;

fuzz_target!(|data: [&str; 3]| {
let (old, new, new1) = (data[0], data[1], data[2]);
let doc = LoroDoc::new();
let text = doc.get_text("text");
text.update(old);
text.update(new);
assert_eq!(&text.to_string(), new);
text.update(new1);
assert_eq!(&text.to_string(), new1);
});
10 changes: 10 additions & 0 deletions crates/fuzz/tests/update_text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use loro::LoroDoc;

#[test]
fn update_text() {
let doc = LoroDoc::new();
let text = doc.get_text("text");
text.update("ϼCCC");
text.update("2");
assert_eq!(&text.to_string(), "2");
}
Loading

0 comments on commit e01505e

Please sign in to comment.