1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#![allow(missing_docs)]
#![cfg_attr(feature = "clippy", allow(cyclomatic_complexity))]
use serde::{Deserialize, Deserializer, Error as SerdeError};
use serde::de::{MapVisitor, SeqVisitor, Visitor};
use serde::de::impls::IgnoredAny;
use url::Url;
#[cfg(feature = "nightly")]
include!("model.in.rs");
#[cfg(feature = "with-syntex")]
include!(concat!(env!("OUT_DIR"), "/model.rs"));
#[cfg(test)]
mod tests {
use serde_xml::from_str;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use super::{Definitions, DidYouMean, DidYouMeans, Error, Img, Infos, LanguageMsg, Notes,
Plaintext, Pod, QueryResult, Spellcheck, State, Statelist, States, Subpod, Tips,
Warnings};
fn read_sample_data_from_path<P>(path: P) -> String
where P: AsRef<Path>,
{
let mut file = File::open(path).unwrap();
let mut body = String::new();
file.read_to_string(&mut body).unwrap();
body
}
#[test]
fn test_query_result_deserializer() {
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_1.xml"))
.unwrap();
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_2.xml"))
.unwrap();
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_3.xml"))
.unwrap();
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_4.xml"))
.unwrap();
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_5.xml"))
.unwrap();
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_6.xml"))
.unwrap();
}
#[test]
fn test_query_result_with_error_deserializer() {
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result-with-error.xml")).unwrap();
}
#[test]
fn test_notes_deserializer() {
from_str::<Notes>(&read_sample_data_from_path("tests/sample-data/notes.xml")).unwrap();
}
#[test]
fn test_languagemsg_deserializer() {
from_str::<LanguageMsg>(&read_sample_data_from_path("tests/sample-data/languagemsg.xml"))
.unwrap();
}
#[test]
fn test_definitions_deserializer() {
from_str::<Definitions>(&read_sample_data_from_path("tests/sample-data/definitions.xml"))
.unwrap();
}
#[test]
fn test_didyoumean_deserializer() {
from_str::<DidYouMean>(&read_sample_data_from_path("tests/sample-data/didyoumean.xml"))
.unwrap();
}
#[test]
fn test_didyoumeans_deserializer() {
from_str::<DidYouMeans>(&read_sample_data_from_path("tests/sample-data/didyoumeans.xml"))
.unwrap();
}
#[test]
fn test_warning_deserializer() {
from_str::<Spellcheck>(&read_sample_data_from_path("tests/sample-data/spellcheck.xml"))
.unwrap();
}
#[test]
fn test_warnings_deserializer() {
from_str::<Warnings>(&read_sample_data_from_path("tests/sample-data/warnings.xml"))
.unwrap();
}
#[test]
fn test_tips_deserializer() {
from_str::<Tips>(&read_sample_data_from_path("tests/sample-data/tips.xml")).unwrap();
}
#[test]
fn test_state_deserializer() {
from_str::<State>(&read_sample_data_from_path("tests/sample-data/state/state.xml"))
.unwrap();
}
#[test]
fn test_statelist_deserializer() {
from_str::<Statelist>(&read_sample_data_from_path("tests/sample-data/state/statelist.xml"))
.unwrap();
}
#[test]
fn test_states_deserializer() {
from_str::<States>(&read_sample_data_from_path("tests/sample-data/state/states.xml"))
.unwrap();
from_str::<States>(&read_sample_data_from_path("tests/sample-data/state/states-multiple-states.xml")).unwrap();
from_str::<States>(&read_sample_data_from_path("tests/sample-data/state/states-multiple-statelists.xml")).unwrap();
from_str::<States>(&read_sample_data_from_path("tests/sample-data/state/states-out-of-order.xml")).unwrap();
assert_eq!(
from_str::<States>(&read_sample_data_from_path("tests/sample-data/state/states-out-of-order-complex.xml")).unwrap(),
States {
count: 5,
state: vec![
State { name: 'a'.to_string(), input: 'a'.to_string(), },
State { name: 'c'.to_string(), input: 'c'.to_string(), },
State { name: 'f'.to_string(), input: 'f'.to_string(), },
],
statelist: Some(vec![
Statelist {
count: 2,
value: 'b'.to_string(),
state: vec![
State { name: "b1".to_owned(), input: "b1".to_owned(), },
State { name: "b2".to_owned(), input: "b2".to_owned(), },
],
},
Statelist {
count: 2,
value: 'd'.to_string(),
state: vec![
State { name: "d1".to_owned(), input: "d1".to_owned(), },
State { name: "d2".to_owned(), input: "d2".to_owned(), },
],
},
Statelist {
count: 2,
value: 'e'.to_string(),
state: vec![
State { name: "e1".to_owned(), input: "e1".to_owned(), },
State { name: "e2".to_owned(), input: "e2".to_owned(), },
],
},
]),
}
);
}
#[test]
fn test_pod_deserializer() {
from_str::<Pod>(&read_sample_data_from_path("tests/sample-data/pod.xml")).unwrap();
}
#[test]
fn test_subpod_deserializer() {
from_str::<Subpod>(&read_sample_data_from_path("tests/sample-data/subpod.xml")).unwrap();
}
#[test]
fn test_img_deserializer() {
from_str::<Img>(&read_sample_data_from_path("tests/sample-data/img.xml")).unwrap();
}
#[test]
fn test_plaintext_deserializer() {
from_str::<Plaintext>(&"<plaintext>pi</plaintext>".to_owned()).unwrap();
from_str::<Option<Plaintext>>(&"<plaintext/>".to_owned()).unwrap();
}
#[test]
fn test_infos_deserializer() {
from_str::<Infos>(&read_sample_data_from_path("tests/sample-data/infos.xml")).unwrap();
}
#[test]
fn test_error_deserializer() {
from_str::<Error>(&read_sample_data_from_path("tests/sample-data/error.xml")).unwrap();
}
}