Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
add tests and fix warnings
appflowy958918e0a0b1
diff --git a/rust-lib/flowy-ot/src/client/mod.rs b/rust-lib/flowy-ot/src/client/mod.rsnew file mode 100644index 0000000000..e69de29bb2diff --git a/rust-lib/flowy-ot/src/attributes.rs b/rust-lib/flowy-ot/src/core/attributes.rssimilarity index 99%rename from rust-lib/flowy-ot/src/attributes.rsrename to rust-lib/flowy-ot/src/core/attributes.rsindex 464b3f272c..3e3f23f9ac 100644--- a/rust-lib/flowy-ot/src/attributes.rs+++ b/rust-lib/flowy-ot/src/core/attributes.rs@@ -1,4 +1,4 @@-use crate::operation::Operation;+use crate::core::Operation;use std::{collections::HashMap, fmt};const PLAIN: &'static str = "";diff --git a/rust-lib/flowy-ot/src/delta.rs b/rust-lib/flowy-ot/src/core/delta.rssimilarity index 99%rename from rust-lib/flowy-ot/src/delta.rsrename to rust-lib/flowy-ot/src/core/delta.rsindex 4df9441e50..cb98bcccab 100644--- a/rust-lib/flowy-ot/src/delta.rs+++ b/rust-lib/flowy-ot/src/core/delta.rs@@ -1,4 +1,7 @@-use crate::{attributes::*, errors::OTError, operation::*};+use crate::{+ core::{attributes::*, operation::*},+ errors::OTError,+};use bytecount::num_chars;use std::{cmp::Ordering, fmt, iter::FromIterator, str::FromStr};diff --git a/rust-lib/flowy-ot/src/interval.rs b/rust-lib/flowy-ot/src/core/interval.rssimilarity index 99%rename from rust-lib/flowy-ot/src/interval.rsrename to rust-lib/flowy-ot/src/core/interval.rsindex 10d3e9fe26..795816a5ce 100644--- a/rust-lib/flowy-ot/src/interval.rs+++ b/rust-lib/flowy-ot/src/core/interval.rs@@ -131,7 +131,7 @@ impl From<RangeToInclusive<usize>> for Interval {#[cfg(test)]mod tests {- use crate::interval::Interval;+ use crate::core::Interval;#[test]fn contains() {diff --git a/rust-lib/flowy-ot/src/core/mod.rs b/rust-lib/flowy-ot/src/core/mod.rsnew file mode 100644index 0000000000..58b6c0bec0--- /dev/null+++ b/rust-lib/flowy-ot/src/core/mod.rs@@ -0,0 +1,10 @@+mod attributes;+mod delta;+mod interval;+mod operation;+mod operation_serde;++pub use attributes::*;+pub use delta::*;+pub use interval::*;+pub use operation::*;diff --git a/rust-lib/flowy-ot/src/operation.rs b/rust-lib/flowy-ot/src/core/operation.rssimilarity index 99%rename from rust-lib/flowy-ot/src/operation.rsrename to rust-lib/flowy-ot/src/core/operation.rsindex 4d11c51ea9..d1c157af23 100644--- a/rust-lib/flowy-ot/src/operation.rs+++ b/rust-lib/flowy-ot/src/core/operation.rs@@ -1,4 +1,4 @@-use crate::attributes::Attributes;+use crate::core::Attributes;use bytecount::num_chars;use std::{fmt,diff --git a/rust-lib/flowy-ot/src/operation_serde.rs b/rust-lib/flowy-ot/src/core/operation_serde.rssimilarity index 98%rename from rust-lib/flowy-ot/src/operation_serde.rsrename to rust-lib/flowy-ot/src/core/operation_serde.rsindex f54c37bba2..4d3ab82688 100644--- a/rust-lib/flowy-ot/src/operation_serde.rs+++ b/rust-lib/flowy-ot/src/core/operation_serde.rs@@ -1,4 +1,4 @@-use crate::{attributes::Attributes, delta::Delta, operation::Operation};+use crate::core::{Attributes, Delta, Operation};use serde::{de,de::{MapAccess, SeqAccess, Visitor},diff --git a/rust-lib/flowy-ot/src/lib.rs b/rust-lib/flowy-ot/src/lib.rsindex e0bf6884a2..f71d8666cf 100644--- a/rust-lib/flowy-ot/src/lib.rs+++ b/rust-lib/flowy-ot/src/lib.rs@@ -1,6 +1,4 @@-pub mod attributes;-pub mod delta;+pub mod client;+pub mod core;pub mod errors;-pub mod interval;-pub mod operation;-mod operation_serde;+pub mod server;diff --git a/rust-lib/flowy-ot/src/server/mod.rs b/rust-lib/flowy-ot/src/server/mod.rsnew file mode 100644index 0000000000..e69de29bb2diff --git a/rust-lib/flowy-ot/tests/attribute_test.rs b/rust-lib/flowy-ot/tests/attribute_test.rsindex 8d6d768482..2c386dee8e 100644--- a/rust-lib/flowy-ot/tests/attribute_test.rs+++ b/rust-lib/flowy-ot/tests/attribute_test.rs@@ -1,10 +1,7 @@pub mod helper;use crate::helper::{MergeTestOp::*, *};-use flowy_ot::{- interval::Interval,- operation::{OpBuilder, Operation, Retain},-};+use flowy_ot::core::Interval;#[test]fn delta_insert_text() {@@ -30,8 +27,27 @@ fn delta_insert_text_at_head() {fn delta_insert_text_at_middle() {let ops = vec![Insert(0, "123", 0),- Insert(0, "456", 2),- AssertOpsJson(0, r#"[{"insert":"124563"}]"#),+ Insert(0, "456", 1),+ AssertOpsJson(0, r#"[{"insert":"145623"}]"#),+ ];+ MergeTest::new().run_script(ops);+}++#[test]+fn delta_insert_text_with_attr() {+ let ops = vec![+ Insert(0, "145", 0),+ Insert(0, "23", 1),+ Bold(0, Interval::new(0, 2), true),+ AssertOpsJson(+ 0,+ r#"[{"insert":"12","attributes":{"bold":"true"}},{"insert":"345"}]"#,+ ),+ Insert(0, "abc", 1),+ AssertOpsJson(+ 0,+ r#"[{"insert":"1abc2","attributes":{"bold":"true"}},{"insert":"345"}]"#,+ ),];MergeTest::new().run_script(ops);}diff --git a/rust-lib/flowy-ot/tests/helper/mod.rs b/rust-lib/flowy-ot/tests/helper/mod.rsindex f1319fd418..3cd5df3c20 100644--- a/rust-lib/flowy-ot/tests/helper/mod.rs+++ b/rust-lib/flowy-ot/tests/helper/mod.rs@@ -1,9 +1,4 @@-use flowy_ot::{- attributes::{Attributes, AttributesData, AttrsBuilder},- delta::Delta,- interval::Interval,- operation::{OpBuilder, Operation},-};+use flowy_ot::core::*;use rand::{prelude::*, Rng as WrappedRng};use std::sync::Once;@@ -113,28 +108,7 @@ impl MergeTest {attributes = Attributes::Follow;}let insert = OpBuilder::insert(s).attributes(attributes).build();-- let mut new_delta = Delta::default();- let prefix = Interval::new(0, index);- let suffix = Interval::new(index, old_delta.target_len);-- split_interval_with_delta(old_delta, &prefix)- .into_iter()- .for_each(|interval| {- let attrs = attributes_in_delta(old_delta, &interval);- new_delta.retain(interval.size() as u64, attrs);- });-- new_delta.add(insert);-- split_interval_with_delta(old_delta, &suffix)- .into_iter()- .for_each(|interval| {- let attrs = attributes_in_delta(old_delta, &interval);- new_delta.retain(interval.size() as u64, attrs);- });-- new_delta = old_delta.compose(&new_delta).unwrap();+ let new_delta = new_delta_with_op(old_delta, insert, Interval::new(index, index));self.deltas[delta_index] = new_delta;}@@ -152,7 +126,7 @@ impl MergeTest {let attrs = attributes_in_delta(old_delta, &interval);retain.extend_attributes(attrs);- let new_delta = new_delta_with_op(old_delta, retain, interval);+ let new_delta = new_delta_with_op(old_delta, retain, *interval);self.deltas[delta_index] = new_delta;}@@ -162,14 +136,14 @@ impl MergeTest {let attrs = attributes_in_delta(old_delta, &interval);delete.extend_attributes(attrs);- let new_delta = new_delta_with_op(old_delta, delete, interval);+ let new_delta = new_delta_with_op(old_delta, delete, *interval);self.deltas[delta_index] = new_delta;}}-fn new_delta_with_op(delta: &Delta, op: Operation, interval: &Interval) -> Delta {+fn new_delta_with_op(delta: &Delta, op: Operation, interval: Interval) -> Delta {let mut new_delta = Delta::default();- let (prefix, interval, suffix) = target_length_split_with_interval(delta.target_len, *interval);+ let (prefix, interval, suffix) = target_length_split_with_interval(delta.target_len, interval);// prefixif prefix.is_empty() == false && prefix != interval {@@ -268,13 +242,6 @@ pub fn attributes_in_delta(delta: &Delta, interval: &Interval) -> Attributes {Attributes::Custom(attributes_data)}}-fn attributes_in_operation(op: &Operation, interval: &Interval) -> Attributes {- match op {- Operation::Delete(_) => Attributes::Empty,- Operation::Retain(retain) => Attributes::Empty,- Operation::Insert(insert) => Attributes::Empty,- }-}pub struct Rng(StdRng);diff --git a/rust-lib/flowy-ot/tests/op_test.rs b/rust-lib/flowy-ot/tests/op_test.rsindex a931b0e264..da43e74aae 100644--- a/rust-lib/flowy-ot/tests/op_test.rs+++ b/rust-lib/flowy-ot/tests/op_test.rs@@ -2,7 +2,7 @@ pub mod helper;use crate::helper::MergeTestOp::*;use bytecount::num_chars;-use flowy_ot::{attributes::*, delta::Delta, interval::Interval, operation::OpBuilder};+use flowy_ot::core::*;use helper::*;#[test]diff --git a/rust-lib/flowy-ot/tests/serde_test.rs b/rust-lib/flowy-ot/tests/serde_test.rsindex dba59e7875..2d821f4ead 100644--- a/rust-lib/flowy-ot/tests/serde_test.rs+++ b/rust-lib/flowy-ot/tests/serde_test.rs@@ -1,8 +1,4 @@-use flowy_ot::{- attributes::AttrsBuilder,- delta::Delta,- operation::{OpBuilder, Operation, Retain},-};+use flowy_ot::core::*;#[test]fn operation_insert_serialize_test() {