Debian Codegraph @

tests/deserialize.rs

raw symbols SCIP
1 #![allow(clippy::unreadable_literal, dead_code)]
2
3 use serderust-analyzer cargo serde 1.0.222 crate/::Deserializerust-analyzer cargo serde_core 1.0.222 de/Deserialize#;
4 use serde_deriverust-analyzer cargo serde_derive 1.0.222 crate/::Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap# as Maprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
7
8 fn testrust-analyzer cargo serde_path_to_error 0.1.20 test().<'de, T>(json: &'de str, expected: &str)
9 where
10 T: Deserializerust-analyzer cargo serde_core 1.0.222 de/Deserialize#<'de> + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#,
11 {
12 let de = &mut serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Deserializerrust-analyzer cargo serde_json 1.0.145 de/Deserializer#::from_strrust-analyzer cargo serde_json 1.0.145 de/impl#[`Deserializer<StrRead<'a>>`]from_str().(json);
13 let result: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, _> = serde_path_to_errorrust-analyzer cargo serde_path_to_error 0.1.20 crate/::deserializerust-analyzer cargo serde_path_to_error 0.1.20 de/deserialize().(de);
14 let path = result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().().pathrust-analyzer cargo serde_path_to_error 0.1.20 impl#[`Error<E>`]path().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
15 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(path, expected);
16 }
17
18 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
19 fn test_structrust-analyzer cargo serde_path_to_error 0.1.20 test_struct().() {
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
21 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
22 namerust-analyzer cargo serde_path_to_error 0.1.20 Package#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
23 dependenciesrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependencies.: Maprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#>,
24 }
25
26 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
27 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
28 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
29 }
30
31 let j = r#"{
32 "name": "demo",
33 "dependencies": {
34 "serde": {
35 "version": 1
36 }
37 }
38 }"#;
39
40 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependencies.serde.version");
41 }
42
43 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
44 fn test_vecrust-analyzer cargo serde_path_to_error 0.1.20 test_vec().() {
45 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
46 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
47 dependenciesrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependencies.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#>,
48 }
49
50 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
51 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
52 namerust-analyzer cargo serde_path_to_error 0.1.20 Dependency#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
53 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
54 }
55
56 let j = r#"{
57 "dependencies": [
58 {
59 "name": "serde",
60 "version": "1.0"
61 },
62 {
63 "name": "serde_json",
64 "version": 1
65 }
66 }
67 }"#;
68
69 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependencies[1].version");
70 }
71
72 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
73 fn test_optionrust-analyzer cargo serde_path_to_error 0.1.20 test_option().() {
74 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
75 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
76 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#>,
77 }
78
79 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
80 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
81 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
82 }
83
84 let j = r#"{
85 "dependency": {
86 "version": 1
87 }
88 }"#;
89
90 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency.version");
91 }
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn test_struct_variantrust-analyzer cargo serde_path_to_error 0.1.20 test_struct_variant().() {
95 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
96 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
97 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#,
98 }
99
100 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
101 enum Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
102 Structrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#Struct# { versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#Struct#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
103 }
104
105 let j = r#"{
106 "dependency": {
107 "Struct": {
108 "version": 1
109 }
110 }
111 }"#;
112
113 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency.Struct.version");
114 }
115
116 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
117 fn test_tuple_variantrust-analyzer cargo serde_path_to_error 0.1.20 test_tuple_variant().() {
118 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
119 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
120 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#,
121 }
122
123 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
124 enum Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
125 Tuplerust-analyzer cargo serde_path_to_error 0.1.20 Dependency#Tuple#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
126 }
127
128 let j = r#"{
129 "dependency": {
130 "Tuple": ["serde", 1]
131 }
132 }"#;
133
134 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency.Tuple[1]");
135 }
136
137 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
138 fn test_unknown_fieldrust-analyzer cargo serde_path_to_error 0.1.20 test_unknown_field().() {
139 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
140 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
141 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#,
142 }
143
144 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
145 #[serde(deny_unknown_fields)]
146 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
147 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
148 }
149
150 let j = r#"{
151 "dependency": {
152 "version": "1.0",
153 "name": "serde"
154 }
155 }"#;
156
157 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency.name");
158 }
159
160 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
161 fn test_invalid_lengthrust-analyzer cargo serde_path_to_error 0.1.20 test_invalid_length().() {
162 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
163 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
164 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#,
165 }
166
167 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
168 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#);
169
170 let j = r#"{
171 "dependency": ["serde"]
172 }"#;
173
174 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency");
175 }
176
177 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
178 fn test_syntax_errorrust-analyzer cargo serde_path_to_error 0.1.20 test_syntax_error().() {
179 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
180 struct Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package# {
181 dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Package#dependency.: Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#,
182 }
183
184 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
185 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
186 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
187 }
188
189 let j = r#"{
190 "dependency": {
191 "error": *
192 }"#;
193
194 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Packagerust-analyzer cargo serde_path_to_error 0.1.20 Package#>(j, "dependency.error");
195 }
196
197 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
198 fn test_u128rust-analyzer cargo serde_path_to_error 0.1.20 test_u128().() {
199 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
200 struct Containerrust-analyzer cargo serde_path_to_error 0.1.20 Container# {
201 nrust-analyzer cargo serde_path_to_error 0.1.20 Container#n.: u128,
202 }
203
204 let j = r#"{
205 "n": 130033514578017493995102500318550798591
206 }"#;
207
208 let de = &mut serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Deserializerrust-analyzer cargo serde_json 1.0.145 de/Deserializer#::from_strrust-analyzer cargo serde_json 1.0.145 de/impl#[`Deserializer<StrRead<'a>>`]from_str().(j);
209 let container: Containerrust-analyzer cargo serde_path_to_error 0.1.20 Container# = serde_path_to_errorrust-analyzer cargo serde_path_to_error 0.1.20 crate/::deserializerust-analyzer cargo serde_path_to_error 0.1.20 de/deserialize().(de).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to deserialize");
210
211 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(container.nrust-analyzer cargo serde_path_to_error 0.1.20 Container#n., 130033514578017493995102500318550798591u128);
212 }
213
214 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
215 fn test_map_nonstring_keyrust-analyzer cargo serde_path_to_error 0.1.20 test_map_nonstring_key().() {
216 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.222 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
217 struct Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency# {
218 versionrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#version.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
219 }
220
221 let j = r#"{
222 "100": {
223 "version": false
224 }
225 }"#;
226
227 testrust-analyzer cargo serde_path_to_error 0.1.20 test().::<Maprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<i32, Dependencyrust-analyzer cargo serde_path_to_error 0.1.20 Dependency#>>(j, "100.version");
228 }