use jmbl::{OpOutput, TextNode, JMBL};
use litl::Val;
#[test]
fn simple_text_ranges() {
let mut jmbl =
JMBL::new_from_root(|view| view.create_plain_text("Hello"), OpOutput::new_dummy());
assert_eq!(
jmbl.get_root().if_text().unwrap().val_to_litl(),
Val::object([
("ranges", Val::array::<Val, _>([])),
(
"graphemes",
Val::array([
Val::str("H"),
Val::str("e"),
Val::str("l"),
Val::str("l"),
Val::str("o")
])
)
])
);
jmbl.change(|root, _| {
let text = root.if_text_mut().unwrap();
text.add_range(2, 3, Val::str("bold"));
});
assert_eq!(
jmbl.get_root().if_text().unwrap().to_tree(),
TextNode::Node {
tag: Val::str("root"),
certain: true,
start: 0,
end: 5,
children: vec![
TextNode::Leaf {
graphemes: vec![Val::str("H"), Val::str("e")]
},
TextNode::Node {
tag: Val::str("bold"),
certain: true,
start: 2,
end: 3,
children: vec![TextNode::Leaf {
graphemes: vec![Val::str("l"),]
}]
},
TextNode::Leaf {
graphemes: vec![Val::str("l"), Val::str("o")]
}
]
}
);
jmbl.change(|root, _| {
let text = root.if_text_mut().unwrap();
text.add_range(0, 1, Val::str("bold"));
});
println!("{:?}", jmbl.get_root().if_text().unwrap().val());
assert_eq!(
jmbl.get_root().if_text().unwrap().to_tree(),
TextNode::Node {
tag: Val::str("root"),
certain: true,
start: 0,
end: 5,
children: vec![
TextNode::Node {
tag: Val::str("bold"),
certain: true,
start: 0,
end: 1,
children: vec![TextNode::Leaf {
graphemes: vec![Val::str("H"),]
}]
},
TextNode::Leaf {
graphemes: vec![Val::str("e")]
},
TextNode::Node {
tag: Val::str("bold"),
certain: true,
start: 2,
end: 3,
children: vec![TextNode::Leaf {
graphemes: vec![Val::str("l"),]
}]
},
TextNode::Leaf {
graphemes: vec![Val::str("l"), Val::str("o")]
}
]
}
);
}