operation_attribute_test.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. use crate::node::script::NodeScript::*;
  2. use crate::node::script::NodeTest;
  3. use lib_ot::core::{AttributeEntry, AttributeValue, Changeset, NodeData};
  4. #[test]
  5. fn operation_update_attribute_with_float_value_test() {
  6. let mut test = NodeTest::new();
  7. let text_node = NodeData::new("text");
  8. let scripts = vec![
  9. InsertNode {
  10. path: 0.into(),
  11. node_data: text_node,
  12. rev_id: 1,
  13. },
  14. UpdateBody {
  15. path: 0.into(),
  16. changeset: Changeset::Attributes {
  17. new: AttributeEntry::new("value", 12.2).into(),
  18. old: Default::default(),
  19. },
  20. },
  21. AssertNodeAttributes {
  22. path: 0.into(),
  23. expected: r#"{"value":12.2}"#,
  24. },
  25. ];
  26. test.run_scripts(scripts);
  27. }
  28. #[test]
  29. fn operation_update_attribute_with_negative_value_test() {
  30. let mut test = NodeTest::new();
  31. let text_node = NodeData::new("text");
  32. let scripts = vec![
  33. InsertNode {
  34. path: 0.into(),
  35. node_data: text_node,
  36. rev_id: 1,
  37. },
  38. UpdateBody {
  39. path: 0.into(),
  40. changeset: Changeset::Attributes {
  41. new: AttributeEntry::new("value", -12.2).into(),
  42. old: Default::default(),
  43. },
  44. },
  45. AssertNodeAttributes {
  46. path: 0.into(),
  47. expected: r#"{"value":-12.2}"#,
  48. },
  49. UpdateBody {
  50. path: 0.into(),
  51. changeset: Changeset::Attributes {
  52. new: AttributeEntry::new("value", AttributeValue::from_int(-12)).into(),
  53. old: Default::default(),
  54. },
  55. },
  56. AssertNodeAttributes {
  57. path: 0.into(),
  58. expected: r#"{"value":-12}"#,
  59. },
  60. ];
  61. test.run_scripts(scripts);
  62. }