Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xsd-parser/tests/attribute_group/example.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<exam:Foo exam:id="abcd" exam:aNumber="1234" xmlns:exam="http://example.com"/>
14 changes: 14 additions & 0 deletions xsd-parser/tests/attribute_group/expected.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
pub struct FooType {
#[yaserde(attribute, rename = "id")]
pub id: Option<String>,

#[yaserde(attribute, rename = "aNumber")]
pub a_number: Option<i32>,
}

impl Validate for FooType {}


// pub type Foo = FooType;
21 changes: 21 additions & 0 deletions xsd-parser/tests/attribute_group/input.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com"
targetNamespace="http://example.com"
elementFormDefault="qualified">

<xs:attributeGroup name="anAttrGroup">
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="aNumber" type="xs:int"/>
</xs:attributeGroup>

<xs:complexType name="FooType">
<xs:attributeGroup ref="tns:anAttrGroup" />
</xs:complexType>

<xs:element name="Foo" type="tns:FooType"/>
</xs:schema>
33 changes: 33 additions & 0 deletions xsd-parser/tests/attribute_group/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use super::utils;

#[test]
fn deserialization_works() {
mod expected {
use xsd_parser::generator::validator::Validate;
use yaserde_derive::{YaDeserialize, YaSerialize};

include!("expected.rs");
}

let ser = include_str!("example.xml");

let de: expected::FooType = yaserde::de::from_str(ser).unwrap();

assert_eq!(
de,
expected::FooType {
id: Some("abcd".to_string()),
a_number: Some(1234),
}
);
}

#[test]
fn generator_does_not_panic() {
println!("{}", utils::generate(include_str!("input.xsd")))
}

#[test]
fn generator_output_has_correct_ast() {
utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs"));
}
1 change: 1 addition & 0 deletions xsd-parser/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[macro_use]
mod utils;
mod any;
mod attribute_group;
mod choice;
mod complex_type;
mod complex_type_subtypes_clash;
Expand Down