1. fix the potential infinite loop when composing delta. Because of calculating the wrong code unit offset.

2. add test of calculating Chinese character
This commit is contained in:
appflowy 2022-01-09 11:12:34 +08:00
parent c456687a18
commit 7e7254b306
12 changed files with 225 additions and 175 deletions

View file

@ -44,7 +44,19 @@ async fn document_sync_insert_test() {
}
#[tokio::test]
async fn document_sync_delete_test1() {
async fn document_sync_insert_in_chinese() {
let s = "".to_owned();
let offset = count_utf16_code_units(&s);
let scripts = vec![
InsertText("", 0),
InsertText("", offset),
AssertJson(r#"[{"insert":"你好\n"}]"#),
];
EditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
async fn document_sync_delete_in_english() {
let scripts = vec![
InsertText("1", 0),
InsertText("2", 1),
@ -55,6 +67,19 @@ async fn document_sync_delete_test1() {
EditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
async fn document_sync_delete_in_chinese() {
let s = "".to_owned();
let offset = count_utf16_code_units(&s);
let scripts = vec![
InsertText("", 0),
InsertText("", offset),
Delete(Interval::new(0, offset)),
AssertJson(r#"[{"insert":"好\n"}]"#),
];
EditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
async fn document_sync_replace_test() {
let scripts = vec![