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
|
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
struct MaybeFields {
f1: i64,
f2: Option<i64>,
f3: Option<Option<i64>>,
}
#[test]
fn test_recursive_implicit_some() {
// Test case provided by d86leader in
// https://github.com/ron-rs/ron/issues/367#issue-1147920589
let x1: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1)");
let x2: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1, f2: None, f3: None)");
let x3: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1, f2: 2, f3: 3)");
let x4: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1, f2: 2, f3: Some(3))");
let x5: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1, f2: 2, f3: Some(Some(3)))");
let x6: std::result::Result<MaybeFields, _> =
ron::from_str("#![enable(implicit_some)]\n(f1: 1, f2: 2, f3: Some(None))");
assert_eq!(
x1,
Ok(MaybeFields {
f1: 1,
f2: None,
f3: None
})
);
assert_eq!(
x2,
Ok(MaybeFields {
f1: 1,
f2: None,
f3: None
})
);
assert_eq!(
x3,
Ok(MaybeFields {
f1: 1,
f2: Some(2),
f3: Some(Some(3))
})
);
assert_eq!(
x4,
Ok(MaybeFields {
f1: 1,
f2: Some(2),
f3: Some(Some(3))
})
);
assert_eq!(
x5,
Ok(MaybeFields {
f1: 1,
f2: Some(2),
f3: Some(Some(3))
})
);
assert_eq!(
x6,
Ok(MaybeFields {
f1: 1,
f2: Some(2),
f3: Some(None)
})
);
}
#[test]
fn test_nested_implicit_some() {
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\n5"),
Ok(Some(Some(Some(5))))
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\nNone"),
Ok(None)
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\nSome(5)"),
Ok(Some(Some(Some(5))))
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\nSome(None)"),
Ok(Some(None))
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\nSome(Some(5))"),
Ok(Some(Some(Some(5))))
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>("#![enable(implicit_some)]\nSome(Some(None))"),
Ok(Some(Some(None)))
);
assert_eq!(
ron::from_str::<Option<Option<Option<u32>>>>(
"#![enable(implicit_some)]\nSome(Some(Some(5)))"
),
Ok(Some(Some(Some(5))))
);
}
|