old_document_test.rs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. use crate::old_document::script::{EditorScript::*, *};
  2. use flowy_revision_persistence::RevisionState;
  3. use lib_ot::core::{count_utf16_code_units, Interval};
  4. #[tokio::test]
  5. async fn text_block_sync_current_rev_id_check() {
  6. let scripts = vec![
  7. InsertText("1", 0),
  8. AssertCurrentRevId(1),
  9. InsertText("2", 1),
  10. AssertCurrentRevId(2),
  11. InsertText("3", 2),
  12. AssertCurrentRevId(3),
  13. AssertNextSyncRevId(None),
  14. AssertJson(r#"[{"insert":"123\n"}]"#),
  15. ];
  16. DeltaDocumentEditorTest::new()
  17. .await
  18. .run_scripts(scripts)
  19. .await;
  20. }
  21. #[tokio::test]
  22. async fn text_block_sync_state_check() {
  23. let scripts = vec![
  24. InsertText("1", 0),
  25. InsertText("2", 1),
  26. InsertText("3", 2),
  27. AssertRevisionState(1, RevisionState::Ack),
  28. AssertRevisionState(2, RevisionState::Ack),
  29. AssertRevisionState(3, RevisionState::Ack),
  30. AssertJson(r#"[{"insert":"123\n"}]"#),
  31. ];
  32. DeltaDocumentEditorTest::new()
  33. .await
  34. .run_scripts(scripts)
  35. .await;
  36. }
  37. #[tokio::test]
  38. async fn text_block_sync_insert_test() {
  39. let scripts = vec![
  40. InsertText("1", 0),
  41. InsertText("2", 1),
  42. InsertText("3", 2),
  43. AssertJson(r#"[{"insert":"123\n"}]"#),
  44. AssertNextSyncRevId(None),
  45. ];
  46. DeltaDocumentEditorTest::new()
  47. .await
  48. .run_scripts(scripts)
  49. .await;
  50. }
  51. #[tokio::test]
  52. async fn text_block_sync_insert_in_chinese() {
  53. let s = "好".to_owned();
  54. let offset = count_utf16_code_units(&s);
  55. let scripts = vec![
  56. InsertText("你", 0),
  57. InsertText("好", offset),
  58. AssertJson(r#"[{"insert":"你好\n"}]"#),
  59. ];
  60. DeltaDocumentEditorTest::new()
  61. .await
  62. .run_scripts(scripts)
  63. .await;
  64. }
  65. #[tokio::test]
  66. async fn text_block_sync_insert_with_emoji() {
  67. let s = "😁".to_owned();
  68. let offset = count_utf16_code_units(&s);
  69. let scripts = vec![
  70. InsertText("😁", 0),
  71. InsertText("☺️", offset),
  72. AssertJson(r#"[{"insert":"😁☺️\n"}]"#),
  73. ];
  74. DeltaDocumentEditorTest::new()
  75. .await
  76. .run_scripts(scripts)
  77. .await;
  78. }
  79. #[tokio::test]
  80. async fn text_block_sync_delete_in_english() {
  81. let scripts = vec![
  82. InsertText("1", 0),
  83. InsertText("2", 1),
  84. InsertText("3", 2),
  85. Delete(Interval::new(0, 2)),
  86. AssertJson(r#"[{"insert":"3\n"}]"#),
  87. ];
  88. DeltaDocumentEditorTest::new()
  89. .await
  90. .run_scripts(scripts)
  91. .await;
  92. }
  93. #[tokio::test]
  94. async fn text_block_sync_delete_in_chinese() {
  95. let s = "好".to_owned();
  96. let offset = count_utf16_code_units(&s);
  97. let scripts = vec![
  98. InsertText("你", 0),
  99. InsertText("好", offset),
  100. Delete(Interval::new(0, offset)),
  101. AssertJson(r#"[{"insert":"好\n"}]"#),
  102. ];
  103. DeltaDocumentEditorTest::new()
  104. .await
  105. .run_scripts(scripts)
  106. .await;
  107. }
  108. #[tokio::test]
  109. async fn text_block_sync_replace_test() {
  110. let scripts = vec![
  111. InsertText("1", 0),
  112. InsertText("2", 1),
  113. InsertText("3", 2),
  114. Replace(Interval::new(0, 3), "abc"),
  115. AssertJson(r#"[{"insert":"abc\n"}]"#),
  116. ];
  117. DeltaDocumentEditorTest::new()
  118. .await
  119. .run_scripts(scripts)
  120. .await;
  121. }