• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use log::info;
2 use serde_derive::Deserialize;
3 use serde_xml_rs::from_str;
4 use simple_logger::SimpleLogger;
5 
init_logger()6 fn init_logger() {
7     let _ = SimpleLogger::new().init();
8 }
9 
10 #[derive(Debug, Deserialize, PartialEq)]
11 struct Item {
12     name: String,
13     source: String,
14 }
15 
16 #[test]
simple_struct_from_attributes_should_fail()17 fn simple_struct_from_attributes_should_fail() {
18     init_logger();
19 
20     let s = r##"
21         <item name="hello" source="world.rs />
22     "##;
23 
24     let item: Result<Item, _> = from_str(s);
25     match item {
26         Ok(_) => assert!(false),
27         Err(e) => {
28             info!("simple_struct_from_attributes_should_fail(): {}", e);
29             assert!(true)
30         }
31     }
32 }
33 
34 #[test]
multiple_roots_attributes_should_fail()35 fn multiple_roots_attributes_should_fail() {
36     init_logger();
37 
38     let s = r##"
39         <item name="hello" source="world.rs" />
40         <item name="hello source="world.rs" />
41     "##;
42 
43     let item: Result<Vec<Item>, _> = from_str(s);
44     match item {
45         Ok(_) => assert!(false),
46         Err(e) => {
47             info!("multiple_roots_attributes_should_fail(): {}", e);
48             assert!(true)
49         }
50     }
51 }
52