With this, the derives should work with most of the crates and types the generated code refers to being aliased. Notably, methods are still mostly invoked using regular method syntax so those coming from trait could still be aliased by outside code.
51 lines
965 B
Rust
51 lines
965 B
Rust
#[macro_use]
|
|
extern crate yaserde_derive;
|
|
|
|
use yaserde::de::from_str;
|
|
|
|
fn init() {
|
|
let _ = env_logger::builder().is_test(true).try_init();
|
|
}
|
|
|
|
#[test]
|
|
fn de_no_content() {
|
|
init();
|
|
|
|
#[derive(YaDeserialize, PartialEq, Debug)]
|
|
#[yaserde(root = "book")]
|
|
pub struct Book {
|
|
author: String,
|
|
title: String,
|
|
}
|
|
|
|
let content = "";
|
|
let loaded: Result<Book, String> = from_str(content);
|
|
assert_eq!(
|
|
loaded,
|
|
Err(String::from(
|
|
"Unexpected end of stream: no root element found"
|
|
))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn de_wrong_end_balise() {
|
|
init();
|
|
|
|
#[derive(YaDeserialize, PartialEq, Debug)]
|
|
#[yaserde(root = "book")]
|
|
pub struct Book {
|
|
author: String,
|
|
title: String,
|
|
}
|
|
|
|
let content = "<book><author>Antoine de Saint-Exupéry<title>Little prince</title></book>";
|
|
let loaded: Result<Book, String> = from_str(content);
|
|
assert_eq!(
|
|
loaded,
|
|
Err(String::from(
|
|
"Unexpected closing tag: book, expected author"
|
|
))
|
|
);
|
|
}
|