2021-11-03 14:04:45 +00:00
|
|
|
#![cfg_attr(rustfmt, rustfmt::skip)]
|
2021-09-22 15:21:44 +00:00
|
|
|
use crate::editor::{TestBuilder, TestOp::*};
|
2021-11-19 05:13:50 +00:00
|
|
|
use flowy_document_infra::core::{FlowyDoc, PlainDoc};
|
2021-11-12 13:44:26 +00:00
|
|
|
use flowy_ot::core::{Delta, Interval, OperationTransformable, NEW_LINE, WHITESPACE, FlowyStr};
|
|
|
|
use unicode_segmentation::UnicodeSegmentation;
|
2021-08-16 07:02:57 +00:00
|
|
|
|
2021-08-03 15:13:20 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added() {
|
2021-08-13 08:39:32 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Bold(0, Interval::new(3, 5), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-13 08:39:32 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"123"},
|
|
|
|
{"insert":"45","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"6"}
|
|
|
|
]"#,
|
|
|
|
),
|
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-13 08:39:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-01 08:39:32 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_and_invert_all() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "123", 0),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(0, 3), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(0, 3), false),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123"}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_and_invert_partial_suffix() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "1234", 0),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(0, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1234","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(2, 4), false),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12","attributes":{"bold":"true"}},{"insert":"34"}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_and_invert_partial_suffix2() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "1234", 0),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(0, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1234","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Bold(0, Interval::new(2, 4), false),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12","attributes":{"bold":"true"}},{"insert":"34"}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Bold(0, Interval::new(2, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1234","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 15:08:24 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_with_new_line() {
|
2021-08-15 13:11:48 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Bold(0, Interval::new(0, 6), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"123456","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
2021-08-15 13:11:48 +00:00
|
|
|
Insert(0, "\n", 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"bold":"true"}},{"insert":"\n"},{"insert":"456","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
Insert(0, "\n", 4),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"bold":"true"}},{"insert":"\n\n"},{"insert":"456","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
Insert(0, "a", 4),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"bold":"true"}},{"insert":"\na\n"},{"insert":"456","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-15 13:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_and_invert_partial_prefix() {
|
2021-08-02 15:08:24 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "1234", 0),
|
2021-08-02 15:08:24 +00:00
|
|
|
Bold(0, Interval::new(0, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1234","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Bold(0, Interval::new(0, 2), false),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12"},{"insert":"34","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 08:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_consecutive() {
|
2021-08-03 08:20:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "1234", 0),
|
2021-08-03 08:20:25 +00:00
|
|
|
Bold(0, Interval::new(0, 1), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1","attributes":{"bold":"true"}},{"insert":"234"}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Bold(0, Interval::new(1, 2), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12","attributes":{"bold":"true"}},{"insert":"34"}]"#),
|
2021-08-02 15:08:24 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 15:08:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 08:20:25 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_italic() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "1234", 0),
|
2021-08-02 10:35:25 +00:00
|
|
|
Bold(0, Interval::new(0, 4), true),
|
2021-08-03 08:20:25 +00:00
|
|
|
Italic(0, Interval::new(0, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-02 10:35:25 +00:00
|
|
|
0,
|
2021-08-15 13:11:48 +00:00
|
|
|
r#"[{"insert":"1234","attributes":{"italic":"true","bold":"true"}},{"insert":"\n"}]"#,
|
2021-08-03 08:20:25 +00:00
|
|
|
),
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "5678", 4),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 08:20:25 +00:00
|
|
|
0,
|
2021-08-15 13:11:48 +00:00
|
|
|
r#"[{"insert":"12345678","attributes":{"bold":"true","italic":"true"}},{"insert":"\n"}]"#,
|
2021-08-02 10:35:25 +00:00
|
|
|
),
|
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 15:13:20 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_italic2() {
|
2021-08-03 15:13:20 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Bold(0, Interval::new(0, 6), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 15:13:20 +00:00
|
|
|
Italic(0, Interval::new(0, 2), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"3456","attributes":{"bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
|
|
|
Italic(0, Interval::new(4, 6), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"34","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"56","attributes":{"italic":"true","bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 15:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_italic3() {
|
2021-08-03 15:13:20 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456789", 0),
|
|
|
|
Bold(0, Interval::new(0, 5), true),
|
|
|
|
Italic(0, Interval::new(0, 2), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"bold":"true","italic":"true"}},
|
|
|
|
{"insert":"345","attributes":{"bold":"true"}},{"insert":"6789"}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
|
|
|
Italic(0, Interval::new(2, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"1234","attributes":{"bold":"true","italic":"true"}},
|
|
|
|
{"insert":"5","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"6789"}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
|
|
|
Bold(0, Interval::new(7, 9), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"1234","attributes":{"bold":"true","italic":"true"}},
|
|
|
|
{"insert":"5","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"67"},
|
|
|
|
{"insert":"89","attributes":{"bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 15:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bold_added_italic_delete() {
|
2021-08-03 15:13:20 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456789", 0),
|
|
|
|
Bold(0, Interval::new(0, 5), true),
|
|
|
|
Italic(0, Interval::new(0, 2), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-09 03:29:37 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"345","attributes":{"bold":"true"}},{"insert":"6789"}]
|
|
|
|
"#,
|
|
|
|
),
|
2021-08-03 15:13:20 +00:00
|
|
|
Italic(0, Interval::new(2, 4), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"1234","attributes":{"bold":"true","italic":"true"}}
|
|
|
|
,{"insert":"5","attributes":{"bold":"true"}},{"insert":"6789"}]"#,
|
|
|
|
),
|
|
|
|
Bold(0, Interval::new(7, 9), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-09 03:29:37 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"1234","attributes":{"bold":"true","italic":"true"}},
|
|
|
|
{"insert":"5","attributes":{"bold":"true"}},{"insert":"67"},
|
|
|
|
{"insert":"89","attributes":{"bold":"true"}}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
Delete(0, Interval::new(0, 5)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"67"},{"insert":"89","attributes":{"bold":"true"}}]"#),
|
2021-08-03 15:13:20 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 15:13:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 10:35:25 +00:00
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_merge_inserted_text_with_same_attribute() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123", Interval::new(0, 3)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
InsertBold(0, "456", Interval::new(3, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_compose_attr_attributes_with_attr_attributes_test() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 15:13:20 +00:00
|
|
|
InsertBold(1, "7", Interval::new(0, 1)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(1, r#"[{"insert":"7","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
Transform(0, 1),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1234567","attributes":{"bold":"true"}}]"#),
|
|
|
|
AssertDocJson(1, r#"[{"insert":"1234567","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
2021-08-03 15:13:20 +00:00
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-02 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_compose_attr_attributes_with_attr_attributes_test2() {
|
2021-08-02 10:35:25 +00:00
|
|
|
let ops = vec![
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Bold(0, Interval::new(0, 6), true),
|
|
|
|
Italic(0, Interval::new(0, 2), true),
|
|
|
|
Italic(0, Interval::new(4, 6), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"bold":"true","italic":"true"}},
|
|
|
|
{"insert":"34","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"56","attributes":{"italic":"true","bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
2021-08-02 10:35:25 +00:00
|
|
|
InsertBold(1, "7", Interval::new(0, 1)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(1, r#"[{"insert":"7","attributes":{"bold":"true"}}]"#),
|
2021-08-02 10:35:25 +00:00
|
|
|
Transform(0, 1),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
0,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"34","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"56","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"7","attributes":{"bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-03 15:13:20 +00:00
|
|
|
1,
|
2021-08-09 03:29:37 +00:00
|
|
|
r#"[
|
|
|
|
{"insert":"12","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"34","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"56","attributes":{"italic":"true","bold":"true"}},
|
|
|
|
{"insert":"7","attributes":{"bold":"true"}}]
|
|
|
|
"#,
|
2021-08-03 15:13:20 +00:00
|
|
|
),
|
2021-08-02 10:35:25 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-01 08:39:32 +00:00
|
|
|
}
|
2021-08-03 08:20:25 +00:00
|
|
|
|
2021-08-03 15:13:20 +00:00
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_compose_attr_attributes_with_no_attr_attributes_test() {
|
2021-08-11 09:18:10 +00:00
|
|
|
let expected = r#"[{"insert":"123456","attributes":{"bold":"true"}},{"insert":"7"}]"#;
|
2021-08-04 08:59:21 +00:00
|
|
|
|
2021-08-03 15:13:20 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 15:13:20 +00:00
|
|
|
Insert(1, "7", 0),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(1, r#"[{"insert":"7"}]"#),
|
2021-08-03 15:13:20 +00:00
|
|
|
Transform(0, 1),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, expected),
|
|
|
|
AssertDocJson(1, expected),
|
2021-08-03 15:13:20 +00:00
|
|
|
];
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 15:13:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 08:20:25 +00:00
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_replace_heading() {
|
2021-08-03 08:20:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Delete(0, Interval::new(0, 2)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"3456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 08:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_replace_trailing() {
|
2021-08-03 08:20:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Delete(0, Interval::new(5, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12345","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 08:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_replace_middle() {
|
2021-08-03 08:20:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Delete(0, Interval::new(0, 2)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"3456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Delete(0, Interval::new(2, 4)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"34","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 08:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_replace_all() {
|
2021-08-03 08:20:25 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
Delete(0, Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[]"#),
|
2021-08-03 08:20:25 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-03 08:20:25 +00:00
|
|
|
}
|
2021-08-10 03:22:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-15 13:11:48 +00:00
|
|
|
fn attributes_replace_with_text() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
InsertBold(0, "123456", Interval::new(0, 6)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456","attributes":{"bold":"true"}}]"#),
|
2021-08-10 03:22:57 +00:00
|
|
|
Replace(0, Interval::new(0, 3), "ab"),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"ab"},{"insert":"456","attributes":{"bold":"true"}}]"#),
|
2021-08-10 03:22:57 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<PlainDoc>(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
2021-08-15 13:11:48 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn attributes_header_insert_newline_at_middle() {
|
2021-08-15 13:11:48 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Header(0, Interval::new(0, 6), 1),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456"},{"insert":"\n","attributes":{"header":1}}]"#),
|
2021-08-15 13:11:48 +00:00
|
|
|
Insert(0, "\n", 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n","attributes":{"header":1}},{"insert":"456"},{"insert":"\n","attributes":{"header":1}}]"#,
|
2021-08-15 13:11:48 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-15 13:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_header_insert_double_newline_at_middle() {
|
2021-08-16 07:02:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Header(0, Interval::new(0, 6), 1),
|
2021-08-16 07:02:57 +00:00
|
|
|
Insert(0, "\n", 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n","attributes":{"header":1}},{"insert":"456"},{"insert":"\n","attributes":{"header":1}}]"#,
|
2021-08-16 07:02:57 +00:00
|
|
|
),
|
|
|
|
Insert(0, "\n", 4),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n\n","attributes":{"header":1}},{"insert":"456"},{"insert":"\n","attributes":{"header":1}}]"#,
|
2021-08-16 07:02:57 +00:00
|
|
|
),
|
|
|
|
Insert(0, "\n", 4),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n\n","attributes":{"header":1}},{"insert":"\n456"},{"insert":"\n","attributes":{"header":1}}]"#,
|
2021-08-16 07:02:57 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 07:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_header_insert_newline_at_trailing() {
|
2021-08-15 13:11:48 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Header(0, Interval::new(0, 6), 1),
|
2021-08-15 13:11:48 +00:00
|
|
|
Insert(0, "\n", 6),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123456"},{"insert":"\n","attributes":{"header":1}},{"insert":"\n"}]"#,
|
2021-08-15 13:11:48 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-15 13:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 06:14:09 +00:00
|
|
|
#[test]
|
|
|
|
fn attributes_header_insert_double_newline_at_trailing() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Header(0, Interval::new(0, 6), 1),
|
2021-08-17 06:14:09 +00:00
|
|
|
Insert(0, "\n", 6),
|
|
|
|
Insert(0, "\n", 7),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-17 06:14:09 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123456"},{"insert":"\n","attributes":{"header":1}},{"insert":"\n\n"}]"#,
|
2021-08-17 06:14:09 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-17 06:14:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 13:11:48 +00:00
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_link_added() {
|
2021-08-15 13:11:48 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 6), "https://appflowy.io"),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
2021-08-16 07:02:57 +00:00
|
|
|
r#"[{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
2021-08-15 13:11:48 +00:00
|
|
|
),
|
2021-08-16 07:02:57 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 07:02:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 05:12:45 +00:00
|
|
|
#[test]
|
|
|
|
fn attributes_link_format_with_bold() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 6), "https://appflowy.io"),
|
2021-08-18 05:12:45 +00:00
|
|
|
Bold(0, Interval::new(0, 3), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-18 05:12:45 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"123","attributes":{"bold":"true","link":"https://appflowy.io"}},
|
|
|
|
{"insert":"456","attributes":{"link":"https://appflowy.io"}},
|
|
|
|
{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-18 05:12:45 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 07:02:57 +00:00
|
|
|
#[test]
|
|
|
|
fn attributes_link_insert_char_at_head() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 6), "https://appflowy.io"),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
2021-08-16 07:02:57 +00:00
|
|
|
r#"[{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
2021-08-15 13:11:48 +00:00
|
|
|
),
|
2021-08-16 07:02:57 +00:00
|
|
|
Insert(0, "a", 0),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-15 13:11:48 +00:00
|
|
|
0,
|
2021-08-16 07:02:57 +00:00
|
|
|
r#"[{"insert":"a"},{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 07:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_link_insert_char_at_middle() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "1256", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 4), "https://appflowy.io"),
|
2021-08-16 07:02:57 +00:00
|
|
|
Insert(0, "34", 2),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 07:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_link_insert_char_at_trailing() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 6), "https://appflowy.io"),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
Insert(0, "a", 6),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123456","attributes":{"link":"https://appflowy.io"}},{"insert":"a\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 07:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_link_insert_newline_at_middle() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, 6), "https://appflowy.io"),
|
2021-08-16 07:02:57 +00:00
|
|
|
Insert(0, NEW_LINE, 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 07:02:57 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"},{"insert":"456","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
2021-08-15 13:11:48 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-15 13:11:48 +00:00
|
|
|
}
|
2021-08-16 09:00:39 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_link_auto_format() {
|
2021-08-16 09:00:39 +00:00
|
|
|
let site = "https://appflowy.io";
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, site, 0),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"https://appflowy.io\n"}]"#),
|
2021-08-16 09:00:39 +00:00
|
|
|
Insert(0, WHITESPACE, site.len()),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 09:00:39 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"https://appflowy.io","attributes":{"link":"https://appflowy.io/"}},{"insert":" \n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 09:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_link_auto_format_exist() {
|
2021-08-16 09:00:39 +00:00
|
|
|
let site = "https://appflowy.io";
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, site, 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, site.len()), site),
|
2021-08-16 09:00:39 +00:00
|
|
|
Insert(0, WHITESPACE, site.len()),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 09:00:39 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"https://appflowy.io","attributes":{"link":"https://appflowy.io/"}},{"insert":" \n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 09:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_link_auto_format_exist2() {
|
2021-08-16 09:00:39 +00:00
|
|
|
let site = "https://appflowy.io";
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, site, 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Link(0, Interval::new(0, site.len() / 2), site),
|
2021-08-16 09:00:39 +00:00
|
|
|
Insert(0, WHITESPACE, site.len()),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 09:00:39 +00:00
|
|
|
0,
|
|
|
|
r#"[{"insert":"https://a","attributes":{"link":"https://appflowy.io"}},{"insert":"ppflowy.io \n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 09:00:39 +00:00
|
|
|
}
|
2021-08-16 15:07:40 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bullet_added() {
|
2021-08-17 06:14:09 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "12", 0),
|
|
|
|
Bullet(0, Interval::new(0, 1), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"12"},{"insert":"\n","attributes":{"list":"bullet"}}]"#),
|
2021-08-17 06:14:09 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-17 06:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bullet_added_2() {
|
2021-08-16 15:07:40 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "1", 0),
|
|
|
|
Bullet(0, Interval::new(0, 1), true),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"1"},{"insert":"\n","attributes":{"list":"bullet"}}]"#),
|
2021-08-16 15:07:40 +00:00
|
|
|
Insert(0, NEW_LINE, 1),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"1"},{"insert":"\n\n","attributes":{"list":"bullet"}}]"#,
|
|
|
|
),
|
2021-08-16 15:07:40 +00:00
|
|
|
Insert(0, "2", 2),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 15:07:40 +00:00
|
|
|
0,
|
2021-09-15 12:19:16 +00:00
|
|
|
r#"[{"insert":"1"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"2"},{"insert":"\n","attributes":{"list":"bullet"}}]"#,
|
2021-08-16 15:07:40 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bullet_remove_partial() {
|
2021-08-16 15:07:40 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "1", 0),
|
|
|
|
Bullet(0, Interval::new(0, 1), true),
|
|
|
|
Insert(0, NEW_LINE, 1),
|
|
|
|
Insert(0, "2", 2),
|
|
|
|
Bullet(0, Interval::new(2, 3), false),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-16 15:07:40 +00:00
|
|
|
0,
|
2021-09-15 12:19:16 +00:00
|
|
|
r#"[{"insert":"1"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"2\n"}]"#,
|
2021-08-16 15:07:40 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-16 15:07:40 +00:00
|
|
|
}
|
2021-08-17 03:23:28 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_bullet_auto_exit() {
|
2021-08-17 03:23:28 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "1", 0),
|
|
|
|
Bullet(0, Interval::new(0, 1), true),
|
|
|
|
Insert(0, NEW_LINE, 1),
|
|
|
|
Insert(0, NEW_LINE, 2),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-17 03:23:28 +00:00
|
|
|
0,
|
2021-09-15 12:19:16 +00:00
|
|
|
r#"[{"insert":"1"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"\n"}]"#,
|
2021-08-17 03:23:28 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-17 03:23:28 +00:00
|
|
|
}
|
2021-08-17 06:14:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_preserve_block_when_insert_newline_inside() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "12", 0),
|
|
|
|
Bullet(0, Interval::new(0, 2), true),
|
|
|
|
Insert(0, NEW_LINE, 2),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"12"},{"insert":"\n\n","attributes":{"list":"bullet"}}]"#,
|
|
|
|
),
|
2021-08-17 06:14:09 +00:00
|
|
|
Insert(0, "34", 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-17 06:14:09 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
2021-09-15 12:19:16 +00:00
|
|
|
{"insert":"12"},{"insert":"\n","attributes":{"list":"bullet"}},
|
|
|
|
{"insert":"34"},{"insert":"\n","attributes":{"list":"bullet"}}
|
2021-08-17 06:14:09 +00:00
|
|
|
]"#,
|
|
|
|
),
|
|
|
|
Insert(0, NEW_LINE, 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-17 06:14:09 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
2021-09-15 12:19:16 +00:00
|
|
|
{"insert":"12"},{"insert":"\n\n","attributes":{"list":"bullet"}},
|
|
|
|
{"insert":"34"},{"insert":"\n","attributes":{"list":"bullet"}}
|
2021-08-17 06:14:09 +00:00
|
|
|
]"#,
|
|
|
|
),
|
|
|
|
Insert(0, "ab", 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-17 06:14:09 +00:00
|
|
|
0,
|
|
|
|
r#"[
|
2021-09-15 12:19:16 +00:00
|
|
|
{"insert":"12"},{"insert":"\n","attributes":{"list":"bullet"}},
|
|
|
|
{"insert":"ab"},{"insert":"\n","attributes":{"list":"bullet"}},
|
|
|
|
{"insert":"34"},{"insert":"\n","attributes":{"list":"bullet"}}
|
2021-08-17 06:14:09 +00:00
|
|
|
]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-17 06:14:09 +00:00
|
|
|
}
|
2021-08-18 03:26:52 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-18 05:12:45 +00:00
|
|
|
fn attributes_preserve_header_format_on_merge() {
|
2021-08-18 03:26:52 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
2021-09-13 07:51:13 +00:00
|
|
|
Header(0, Interval::new(0, 6), 1),
|
2021-08-18 03:26:52 +00:00
|
|
|
Insert(0, NEW_LINE, 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-18 03:26:52 +00:00
|
|
|
0,
|
2021-09-22 06:42:14 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n","attributes":{"header":1}},{"insert":"456"},{"insert":"\n","attributes":{"header":1}}]"#,
|
2021-08-18 03:26:52 +00:00
|
|
|
),
|
|
|
|
Delete(0, Interval::new(3, 4)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(0, r#"[{"insert":"123456"},{"insert":"\n","attributes":{"header":1}}]"#),
|
2021-08-18 03:26:52 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-11-12 13:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_format_emoji() {
|
|
|
|
let emoji_s = "👋 ";
|
|
|
|
let s: FlowyStr = emoji_s.into();
|
|
|
|
let len = s.count_utf16_code_units();
|
|
|
|
assert_eq!(3, len);
|
|
|
|
assert_eq!(2, s.graphemes(true).count());
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, emoji_s, 0),
|
|
|
|
AssertDocJson(0, r#"[{"insert":"👋 \n"}]"#),
|
|
|
|
Header(0, Interval::new(0, len), 1),
|
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"👋 "},{"insert":"\n","attributes":{"header":1}}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-18 03:26:52 +00:00
|
|
|
}
|
2021-08-18 05:12:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attributes_preserve_list_format_on_merge() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Bullet(0, Interval::new(0, 6), true),
|
|
|
|
Insert(0, NEW_LINE, 3),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
2021-08-18 05:12:45 +00:00
|
|
|
0,
|
2021-09-15 12:19:16 +00:00
|
|
|
r#"[{"insert":"123"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"456"},{"insert":"\n","attributes":{"list":"bullet"}}]"#,
|
2021-08-18 05:12:45 +00:00
|
|
|
),
|
|
|
|
Delete(0, Interval::new(3, 4)),
|
2021-09-26 08:39:57 +00:00
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"123456"},{"insert":"\n","attributes":{"list":"bullet"}}]"#,
|
|
|
|
),
|
2021-08-18 05:12:45 +00:00
|
|
|
];
|
|
|
|
|
2021-09-13 08:45:36 +00:00
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
2021-08-18 05:12:45 +00:00
|
|
|
}
|
2021-11-03 05:52:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn delta_compose() {
|
|
|
|
let mut delta = Delta::from_json(r#"[{"insert":"\n"}]"#).unwrap();
|
|
|
|
let deltas = vec![
|
|
|
|
Delta::from_json(r#"[{"retain":1,"attributes":{"list":"unchecked"}}]"#).unwrap(),
|
|
|
|
Delta::from_json(r#"[{"insert":"a"}]"#).unwrap(),
|
|
|
|
Delta::from_json(r#"[{"retain":1},{"insert":"\n","attributes":{"list":"unchecked"}}]"#).unwrap(),
|
|
|
|
Delta::from_json(r#"[{"retain":2},{"retain":1,"attributes":{"list":""}}]"#).unwrap(),
|
|
|
|
];
|
|
|
|
|
|
|
|
for d in deltas {
|
|
|
|
delta = delta.compose(&d).unwrap();
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
delta.to_json(),
|
|
|
|
r#"[{"insert":"a"},{"insert":"\n","attributes":{"list":"unchecked"}},{"insert":"\n"}]"#
|
|
|
|
);
|
|
|
|
|
|
|
|
let ops = vec![
|
|
|
|
AssertDocJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
Insert(0, "a", 0),
|
|
|
|
AssertDocJson(0, r#"[{"insert":"a\n"}]"#),
|
|
|
|
Bullet(0, Interval::new(0, 1), true),
|
|
|
|
AssertDocJson(0, r#"[{"insert":"a"},{"insert":"\n","attributes":{"list":"bullet"}}]"#),
|
|
|
|
Insert(0, NEW_LINE, 1),
|
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"a"},{"insert":"\n\n","attributes":{"list":"bullet"}}]"#,
|
|
|
|
),
|
|
|
|
Insert(0, NEW_LINE, 2),
|
|
|
|
AssertDocJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"a"},{"insert":"\n","attributes":{"list":"bullet"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
TestBuilder::new().run_script::<FlowyDoc>(ops);
|
|
|
|
}
|