Debian Codegraph @

tests/117_untagged_tuple_variant.rs

raw symbols SCIP
1 use std::borrow::Cow;
2
3 use ron::{de::from_str, ser::to_string};
4 use serde::{Deserialize, Serialize};
5
6 #[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
7 pub struct BuildSystem<'m> {
8 version: Cow<'m, str>,
9 flags: Vec<Flag<'m>>,
10 }
11
12 #[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
13 #[serde(untagged)]
14 pub enum Flag<'m> {
15 Value(Cow<'m, str>),
16 If(Cow<'m, str>, Vec<Cow<'m, str>>),
17 }
18
19 #[test]
20 fn test_ebkalderon_case() {
21 let file = r#"BuildSystem(
22 version: "1.0.0",
23 flags: [
24 "--enable-thing",
25 "--enable-other-thing",
26 ("some-conditional", ["--enable-third-thing"]),
27 ]
28 )
29 "#;
30
31 assert_eq!(
32 from_str::<BuildSystem>(file).unwrap(),
33 BuildSystem {
34 version: "1.0.0".into(),
35 flags: vec![
36 Flag::Value("--enable-thing".into()),
37 Flag::Value("--enable-other-thing".into()),
38 Flag::If(
39 "some-conditional".into(),
40 vec!["--enable-third-thing".into()]
41 )
42 ]
43 },
44 );
45 }
46
47 #[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
48 #[serde(untagged)]
49 enum Foo {
50 Bar(usize),
51 }
52
53 #[test]
54 fn test_vessd_case() {
55 let foo_vec = vec![Foo::Bar(0); 5];
56 let foo_str = to_string(&foo_vec).unwrap();
57 assert_eq!(foo_str.as_str(), "[0,0,0,0,0]");
58 assert_eq!(from_str::<Vec<Foo>>(&foo_str).unwrap(), foo_vec);
59 }