From da88af2c8d293c65ef9751a38cab6f1f27d2204a Mon Sep 17 00:00:00 2001 From: Mingun Date: Thu, 10 Oct 2024 19:58:25 +0500 Subject: [PATCH] Add regression test for #655 - ok --- tests/serde-issues.rs | 49 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/serde-issues.rs b/tests/serde-issues.rs index 9781ae72..bac7d416 100644 --- a/tests/serde-issues.rs +++ b/tests/serde-issues.rs @@ -4,7 +4,7 @@ use pretty_assertions::assert_eq; use quick_xml::de::{from_reader, from_str}; -use quick_xml::se::{to_string, to_string_with_root}; +use quick_xml::se::{to_string, to_string_with_root, Serializer}; use serde::de::{Deserializer, IgnoredAny}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -475,6 +475,53 @@ fn issue580() { ); } +/// Regression test for https://github.com/tafia/quick-xml/issues/655 +#[test] +fn issue655() { + #[derive(Deserialize, Serialize, Debug)] + pub struct TextureCoordinates { + #[serde(rename = "@dimension")] + pub dimension: String, + #[serde(rename = "@channel")] + pub channel: String, + #[serde(rename = "$value")] + pub elements: String, + } + #[derive(Deserialize, Serialize, Debug)] + #[serde(rename_all = "PascalCase")] + pub struct VertexBuffer { + pub positions: String, + pub normals: String, + #[serde(skip_serializing_if = "Option::is_none", default)] + pub texture_coordinates: Option, + } + + let mut buffer = String::new(); + let mut ser = Serializer::with_root(&mut buffer, None).unwrap(); + ser.indent(' ', 2); + ser.expand_empty_elements(true); + + let obj = VertexBuffer { + positions: "319.066 -881.28705 7.71589".into(), + normals: "-0.0195154 -0.21420999 0.976593".into(), + texture_coordinates: Some(TextureCoordinates { + dimension: "2D".into(), + channel: "0".into(), + elements: "752494 0.201033,0.773967 0.201033".into(), + }), + }; + obj.serialize(ser).unwrap(); + assert_eq!( + buffer, + "\ + + 319.066 -881.28705 7.71589 + -0.0195154 -0.21420999 0.976593 + 752494 0.201033,0.773967 0.201033 +" + ); +} + /// Regression test for https://github.com/tafia/quick-xml/issues/683. #[test] fn issue683() {