use yaserde_derive::{YaDeserialize, YaSerialize}; fn init() { let _ = env_logger::builder().is_test(true).try_init(); } #[derive(YaSerialize, YaDeserialize, PartialEq, Debug)] #[yaserde(rename = "teststruct")] struct TestStruct { #[yaserde(cdata = true)] pub msgdata: String, } #[test] fn test_cdata_serialization() { init(); let test_data = TestStruct { msgdata: "Some unescaped content".to_string(), }; let xml_output = yaserde::ser::to_string(&test_data).expect("Serialization failed"); let expected_output = r#"Some unescaped content]]>"#; assert_eq!(xml_output, expected_output); } #[test] fn test_cdata_deserialization() { init(); let xml = r#"Some unescaped content]]>"#; let r: TestStruct = yaserde::de::from_str(xml).unwrap(); let expected_output = TestStruct { msgdata: "Some unescaped content".to_string(), }; assert_eq!(r, expected_output); }