Skip to content

Commit c8d797d

Browse files
committed
Added tests for xs:all element
1 parent 8898a07 commit c8d797d

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

xsd-parser/tests/all/example.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<exam:Foo xmlns:exam="http://example.com">
3+
<exam:TwiceOrMore>111</exam:TwiceOrMore>
4+
<exam:Once>222</exam:Once>
5+
<exam:TwiceOrMore>333</exam:TwiceOrMore>
6+
<exam:OnceSpecify>444</exam:OnceSpecify>
7+
<exam:TwiceOrMore>555</exam:TwiceOrMore>
8+
</exam:Foo>

xsd-parser/tests/all/expected.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
2+
#[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
3+
pub struct FooType {
4+
#[yaserde(prefix = "tns", rename = "Once")]
5+
pub once: i32,
6+
7+
#[yaserde(prefix = "tns", rename = "Optional")]
8+
pub optional: Option<i32>,
9+
10+
#[yaserde(prefix = "tns", rename = "OnceSpecify")]
11+
pub once_specify: i32,
12+
13+
#[yaserde(prefix = "tns", rename = "TwiceOrMore")]
14+
pub twice_or_more: Vec<i32>,
15+
}
16+
17+
impl Validate for FooType {}
18+
19+
// pub type Foo = FooType;

xsd-parser/tests/all/input.xsd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:tns="http://example.com"
4+
targetNamespace="http://example.com"
5+
elementFormDefault="qualified">
6+
<xs:complexType name="FooType">
7+
<xs:all>
8+
<xs:element name="Once" type="xs:int"/>
9+
<xs:element name="Optional" type="xs:int" minOccurs="0"/>
10+
<xs:element name="OnceSpecify" type="xs:int" minOccurs="1"/>
11+
<xs:element name="TwiceOrMore" type="xs:int" minOccurs="2" maxOccurs="unbounded"/>
12+
</xs:all>
13+
</xs:complexType>
14+
15+
<xs:element name="Foo" type="tns:FooType"/>
16+
</xs:schema>

xsd-parser/tests/all/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use super::utils;
2+
3+
#[test]
4+
fn deserialization_works() {
5+
mod expected {
6+
use xsd_parser::generator::validator::Validate;
7+
use yaserde_derive::{YaDeserialize, YaSerialize};
8+
9+
include!("expected.rs");
10+
}
11+
12+
let ser = include_str!("example.xml");
13+
14+
let de: expected::FooType = yaserde::de::from_str(ser).unwrap();
15+
16+
assert_eq!(
17+
de,
18+
expected::FooType {
19+
once: 222,
20+
optional: None,
21+
once_specify: 444,
22+
twice_or_more: vec![111, 333, 555]
23+
}
24+
);
25+
}
26+
27+
#[test]
28+
fn generator_does_not_panic() {
29+
println!("{}", utils::generate(include_str!("input.xsd")))
30+
}
31+
32+
#[test]
33+
fn generator_output_has_correct_ast() {
34+
utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs"));
35+
}

xsd-parser/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[macro_use]
22
mod utils;
3+
mod all;
34
mod any;
45
mod choice;
56
mod complex_type;

0 commit comments

Comments
 (0)