Skip to content

Commit

Permalink
Added tuple_with_vec_string
Browse files Browse the repository at this point in the history
  • Loading branch information
lkirkwood committed Apr 20, 2024
1 parent 134fed9 commit edd3a93
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions xsd-parser/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod simple_type;
mod tuple_with_integer;
mod tuple_with_string;
mod tuple_with_vec_int;
mod tuple_with_vec_string;
mod type_name_clash;
mod union;
mod xsd_string;
1 change: 1 addition & 0 deletions xsd-parser/tests/tuple_with_vec_string/example.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><exam:Foo xmlns:exam="http://example.com">1 2 3</exam:Foo>
5 changes: 5 additions & 0 deletions xsd-parser/tests/tuple_with_vec_string/expected.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)]
pub struct FooType(pub Vec<String>);

impl Validate for FooType {}
// pub type Foo = FooType;
11 changes: 11 additions & 0 deletions xsd-parser/tests/tuple_with_vec_string/input.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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:simpleType name="FooType">
<xs:list itemType="xs:string"/>
</xs:simpleType>

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

#[test]
fn deserialization_works() {
mod expected {
use std::str::FromStr;
use xsd_parser::generator::validator::Validate;

use xsd_macro_utils::*;

include!("expected.rs");
}

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

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

assert_eq!(de, expected::FooType(vec!["1".to_string(), "2".to_string(), "3".to_string()]));

assert_eq!(
r#"<?xml version="1.0" encoding="utf-8"?><FooType>1 2 3</FooType>"#,
yaserde::ser::to_string(&de).unwrap()
);
}

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

#[test]
#[ignore] // Validation is not needed in this case
fn generator_output_has_correct_ast() {
utils::ast_test(include_str!("input.xsd"), include_str!("expected.rs"));
}

0 comments on commit edd3a93

Please sign in to comment.