Skip to content

Commit

Permalink
Add regression test for #655 - ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Oct 12, 2024
1 parent ec2471e commit c452b12
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/serde-issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -475,6 +475,53 @@ fn issue580() {
);
}

/// Regression test for https:/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<TextureCoordinates>,
}

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,
"\
<VertexBuffer>
<Positions>319.066 -881.28705 7.71589</Positions>
<Normals>-0.0195154 -0.21420999 0.976593</Normals>
<TextureCoordinates dimension=\"2D\" channel=\"0\">752494 0.201033,0.773967 0.201033</TextureCoordinates>
</VertexBuffer>"
);
}

/// Regression test for https:/tafia/quick-xml/issues/683.
#[test]
fn issue683() {
Expand Down

0 comments on commit c452b12

Please sign in to comment.