| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | use crate::document::script::{EditorScript::*, *};
 | 
					
						
							| 
									
										
										
										
											2022-03-19 16:52:28 +08:00
										 |  |  | use flowy_revision::disk::RevisionState;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | use lib_ot::core::{count_utf16_code_units, Interval};
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_current_rev_id_check() {
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("1", 0),
 | 
					
						
							|  |  |  |         AssertCurrentRevId(1),
 | 
					
						
							|  |  |  |         InsertText("2", 1),
 | 
					
						
							|  |  |  |         AssertCurrentRevId(2),
 | 
					
						
							|  |  |  |         InsertText("3", 2),
 | 
					
						
							|  |  |  |         AssertCurrentRevId(3),
 | 
					
						
							| 
									
										
										
										
											2022-01-26 23:29:18 +08:00
										 |  |  |         AssertNextSyncRevId(None),
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |         AssertJson(r#"[{"insert":"123\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_state_check() {
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("1", 0),
 | 
					
						
							|  |  |  |         InsertText("2", 1),
 | 
					
						
							|  |  |  |         InsertText("3", 2),
 | 
					
						
							|  |  |  |         AssertRevisionState(1, RevisionState::Ack),
 | 
					
						
							|  |  |  |         AssertRevisionState(2, RevisionState::Ack),
 | 
					
						
							|  |  |  |         AssertRevisionState(3, RevisionState::Ack),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"123\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_insert_test() {
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("1", 0),
 | 
					
						
							|  |  |  |         InsertText("2", 1),
 | 
					
						
							|  |  |  |         InsertText("3", 2),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"123\n"}]"#),
 | 
					
						
							| 
									
										
										
										
											2022-01-26 23:29:18 +08:00
										 |  |  |         AssertNextSyncRevId(None),
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_insert_in_chinese() {
 | 
					
						
							| 
									
										
										
										
											2022-01-09 11:12:34 +08:00
										 |  |  |     let s = "好".to_owned();
 | 
					
						
							|  |  |  |     let offset = count_utf16_code_units(&s);
 | 
					
						
							|  |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("你", 0),
 | 
					
						
							|  |  |  |         InsertText("好", offset),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"你好\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-09 15:13:45 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_insert_with_emoji() {
 | 
					
						
							| 
									
										
										
										
											2022-01-09 15:13:45 +08:00
										 |  |  |     let s = "😁".to_owned();
 | 
					
						
							|  |  |  |     let offset = count_utf16_code_units(&s);
 | 
					
						
							|  |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("😁", 0),
 | 
					
						
							|  |  |  |         InsertText("☺️", offset),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"😁☺️\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-09 11:12:34 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_delete_in_english() {
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("1", 0),
 | 
					
						
							|  |  |  |         InsertText("2", 1),
 | 
					
						
							|  |  |  |         InsertText("3", 2),
 | 
					
						
							|  |  |  |         Delete(Interval::new(0, 2)),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"3\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 11:12:34 +08:00
										 |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_delete_in_chinese() {
 | 
					
						
							| 
									
										
										
										
											2022-01-09 11:12:34 +08:00
										 |  |  |     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"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-09 11:12:34 +08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | #[tokio::test]
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  | async fn text_block_sync_replace_test() {
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         InsertText("1", 0),
 | 
					
						
							|  |  |  |         InsertText("2", 1),
 | 
					
						
							|  |  |  |         InsertText("3", 2),
 | 
					
						
							|  |  |  |         Replace(Interval::new(0, 3), "abc"),
 | 
					
						
							|  |  |  |         AssertJson(r#"[{"insert":"abc\n"}]"#),
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							| 
									
										
										
										
											2022-03-12 21:06:15 +08:00
										 |  |  |     TextBlockEditorTest::new().await.run_scripts(scripts).await;
 | 
					
						
							| 
									
										
										
										
											2022-01-08 18:21:13 +08:00
										 |  |  | }
 |