Skip to content

Commit

Permalink
updated api and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Waidhoferj committed Apr 28, 2022
1 parent abf0800 commit e289e59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/y_text.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::rc::Rc;

use lib0::any::Any;
use pyo3::exceptions::PyTypeError;
Expand Down Expand Up @@ -228,7 +229,7 @@ impl YText {
attrs
.into_iter()
.map(|(k, v)| {
let key = k.into_boxed_str();
let key = Rc::from(k);
let value = py_into_any(v);
if let Some(value) = value {
Ok((key, value))
Expand Down
11 changes: 7 additions & 4 deletions tests/test_y_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def callback(e):
text.unobserve(sub)


# TODO: Fix final test
def test_formatting():
d1 = Y.YDoc()
text = d1.get_text("test")
Expand All @@ -182,14 +183,16 @@ def callback(e):

with d1.begin_transaction() as txn:
text.insert(txn, 0, "stylish")

with d1.begin_transaction() as txn:
text.format(txn, 0, 4, {"bold": True})

expected = [
assert delta == [
{"insert": "styl", "attributes": {"bold": True}},
{"insert": "ish"},
]
assert delta == expected

with d1.begin_transaction() as txn:
text.format(txn, 4, 7, {"bold": True})

assert delta == [{"retain": 4}, {"retain": 3, "attributes": {"bold": True}}]

text.unobserve(sub)

0 comments on commit e289e59

Please sign in to comment.