Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deser on Delta #3

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/delta.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cmp::min, fmt::Display};

use serde_derive::Serialize;
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;

use crate::{
Expand All @@ -16,7 +16,7 @@ use crate::{
/// > Deltas are a simple, yet expressive format that can be used to describe Quill's contents and changes.
/// > The format is a strict subset of JSON, is human readable, and easily parsible by machines.
/// > Deltas can describe any Quill document, includes all text and formatting information, without the ambiguity and complexity of HTML.
#[derive(Default, Debug, Serialize, Clone, PartialEq)]
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Delta {
ops: Vec<Op>,
}
Expand Down Expand Up @@ -668,6 +668,23 @@ mod helpers_tests {

use super::Delta;

#[test]
fn deserialize() {
let mut exp = Delta::new();
exp.insert("Test", None)
.retain(4, Some(attributes!("bold" => true)))
.delete(2);
let input = json!({
"ops":[
{"insert": "Test"},
{"retain": 4, "attributes": {"bold": true}},
{"delete": 2}
]
});
let act: Delta = serde_json::from_value(input).unwrap();
assert_eq!(exp, act)
}

#[test]
fn retain() {
let mut delta = Delta::new();
Expand Down
Loading