document_test.rs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. use crate::document::edit_script::{EditorScript::*, *};
  2. use flowy_collaboration::entities::revision::RevisionState;
  3. use lib_ot::core::{count_utf16_code_units, Interval};
  4. #[tokio::test]
  5. async fn document_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. AssertNextRevId(None),
  14. AssertJson(r#"[{"insert":"123\n"}]"#),
  15. ];
  16. EditorTest::new().await.run_scripts(scripts).await;
  17. }
  18. #[tokio::test]
  19. async fn document_sync_state_check() {
  20. let scripts = vec![
  21. InsertText("1", 0),
  22. InsertText("2", 1),
  23. InsertText("3", 2),
  24. AssertRevisionState(1, RevisionState::Ack),
  25. AssertRevisionState(2, RevisionState::Ack),
  26. AssertRevisionState(3, RevisionState::Ack),
  27. AssertJson(r#"[{"insert":"123\n"}]"#),
  28. ];
  29. EditorTest::new().await.run_scripts(scripts).await;
  30. }
  31. #[tokio::test]
  32. async fn document_sync_insert_test() {
  33. let scripts = vec![
  34. InsertText("1", 0),
  35. InsertText("2", 1),
  36. InsertText("3", 2),
  37. AssertJson(r#"[{"insert":"123\n"}]"#),
  38. AssertNextRevId(None),
  39. ];
  40. EditorTest::new().await.run_scripts(scripts).await;
  41. }
  42. #[tokio::test]
  43. async fn document_sync_delete_test1() {
  44. let scripts = vec![
  45. InsertText("1", 0),
  46. InsertText("2", 1),
  47. InsertText("3", 2),
  48. Delete(Interval::new(0, 2)),
  49. AssertJson(r#"[{"insert":"3\n"}]"#),
  50. ];
  51. EditorTest::new().await.run_scripts(scripts).await;
  52. }
  53. #[tokio::test]
  54. async fn document_sync_replace_test() {
  55. let scripts = vec![
  56. InsertText("1", 0),
  57. InsertText("2", 1),
  58. InsertText("3", 2),
  59. Replace(Interval::new(0, 3), "abc"),
  60. AssertJson(r#"[{"insert":"abc\n"}]"#),
  61. ];
  62. EditorTest::new().await.run_scripts(scripts).await;
  63. }