1 #![allow(rustc::internal)]
3 use rustc_macros::{Decodable, Encodable};
4 use rustc_serialize::opaque::{MemDecoder, MemEncoder};
5 use rustc_serialize::{Decodable, Encodable};
8 #[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
32 T: Encodable<MemEncoder> + for<'a> Decodable<MemDecoder<'a>> + PartialEq + Debug,
36 let mut encoder = MemEncoder::new();
37 for value in &values {
38 Encodable::encode(value, &mut encoder);
41 let data = encoder.finish();
42 let mut decoder = MemDecoder::new(&data[..], 0);
45 let decoded = Decodable::decode(&mut decoder);
46 assert_eq!(value, decoded);
52 check_round_trip(vec![(), (), (), ()]);
58 for i in u8::MIN..u8::MAX {
61 check_round_trip(vec);
66 for i in u16::MIN..u16::MAX {
67 check_round_trip(vec![1, 2, 3, i, i, i]);
73 check_round_trip(vec![1, 2, 3, u32::MIN, 0, 1, u32::MAX, 2, 1]);
78 check_round_trip(vec![1, 2, 3, u64::MIN, 0, 1, u64::MAX, 2, 1]);
83 check_round_trip(vec![1, 2, 3, usize::MIN, 0, 1, usize::MAX, 2, 1]);
89 for i in i8::MIN..i8::MAX {
92 check_round_trip(vec);
97 for i in i16::MIN..i16::MAX {
98 check_round_trip(vec![-1, 2, -3, i, i, i, 2]);
104 check_round_trip(vec![-1, 2, -3, i32::MIN, 0, 1, i32::MAX, 2, 1]);
109 check_round_trip(vec![-1, 2, -3, i64::MIN, 0, 1, i64::MAX, 2, 1]);
114 check_round_trip(vec![-1, 2, -3, isize::MIN, 0, 1, isize::MAX, 2, 1]);
119 check_round_trip(vec![false, true, true, false, false]);
124 let mut vec = vec![];
126 vec.push((i as f32) / 3.0);
128 check_round_trip(vec);
133 let mut vec = vec![];
135 vec.push((i as f64) / 3.0);
137 check_round_trip(vec);
142 let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€'];
143 check_round_trip(vec);
149 "abcbuÖeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
150 "abcbuÖganeiovÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
151 "abcbuÖganeiovÄnameÜavmpßvmea€µsbpapmaebn".to_string(),
152 "abcbuÖganeiovÄnameÜavmpßvmeabpnvapeapmaebn".to_string(),
153 "abcbuÖganeiÄnameÜavmpßvmea€µsbpnvapeapmaebn".to_string(),
154 "abcbuÖganeiovÄnameÜavmpßvmea€µsbpmaebn".to_string(),
155 "abcbuÖganeiovÄnameÜavmpßvmea€µnvapeapmaebn".to_string(),
158 check_round_trip(vec);
163 check_round_trip(vec![Some(-1i8)]);
164 check_round_trip(vec![Some(-2i16)]);
165 check_round_trip(vec![Some(-3i32)]);
166 check_round_trip(vec![Some(-4i64)]);
167 check_round_trip(vec![Some(-5isize)]);
169 let none_i8: Option<i8> = None;
170 check_round_trip(vec![none_i8]);
172 let none_i16: Option<i16> = None;
173 check_round_trip(vec![none_i16]);
175 let none_i32: Option<i32> = None;
176 check_round_trip(vec![none_i32]);
178 let none_i64: Option<i64> = None;
179 check_round_trip(vec![none_i64]);
181 let none_isize: Option<isize> = None;
182 check_round_trip(vec![none_isize]);
187 check_round_trip(vec![Struct {
202 m: "abc".to_string(),
209 check_round_trip(vec![Struct {
224 m: "def".to_string(),
232 #[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
235 Variant2(usize, f32),
236 Variant3 { a: i32, b: char, c: bool },
241 check_round_trip(vec![
243 Enum::Variant2(1, 2.5),
244 Enum::Variant3 { a: 3, b: 'b', c: false },
245 Enum::Variant3 { a: -4, b: 'f', c: true },
251 let mut vec = vec![];
252 for i in -100i64..100i64 {
253 vec.push(i * 100000);
256 check_round_trip(vec![vec]);
261 use std::collections::HashMap;
262 let mut map = HashMap::new();
263 for i in -100i64..100i64 {
264 map.insert(i * 100000, i * 10000);
267 check_round_trip(vec![map]);
272 check_round_trip(vec![('x', (), false, 0.5f32)]);
273 check_round_trip(vec![(9i8, 10u16, 1.5f64)]);
274 check_round_trip(vec![(-12i16, 11u8, 12usize)]);
275 check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]);
276 check_round_trip(vec![(String::new(), "some string".to_string())]);