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
109
110
111
112
113
//! Test which ensures that compatible types can be decoded.
use musli::{Decode, Encode};
#[derive(Debug, PartialEq, Encode, Decode)]
#[allow(dead_code)]
struct SignedIntegers {
a: i8,
b: i16,
c: i32,
d: i64,
e: i128,
f: isize,
}
#[derive(Debug, PartialEq, Encode, Decode)]
#[allow(dead_code)]
struct UnsignedIntegers {
a: u8,
b: u16,
c: u32,
d: u64,
e: u128,
f: usize,
}
#[test]
fn signed_to_unsigned() {
macro_rules! test_case {
($ty:ty) => {{
#[derive(Debug, PartialEq, Encode, Decode)]
struct UnsignedIntegers {
a: $ty,
b: $ty,
c: $ty,
d: $ty,
e: $ty,
f: $ty,
}
musli::macros::assert_decode_eq! {
descriptive,
SignedIntegers {
a: 2,
b: 3,
c: 4,
d: 5,
e: 6,
f: 7,
},
UnsignedIntegers {
a: 2,
b: 3,
c: 4,
d: 5,
e: 6,
f: 7,
}
};
}};
}
test_case!(u8);
test_case!(u16);
test_case!(u32);
test_case!(u64);
test_case!(u128);
test_case!(usize);
}
#[test]
fn unsigned_to_signed() {
macro_rules! test_case {
($ty:ty) => {{
#[derive(Debug, PartialEq, Encode, Decode)]
struct UnsignedIntegers {
a: $ty,
b: $ty,
c: $ty,
d: $ty,
e: $ty,
f: $ty,
}
musli::macros::assert_decode_eq! {
descriptive,
UnsignedIntegers {
a: 2,
b: 3,
c: 4,
d: 5,
e: 6,
f: 7,
},
SignedIntegers {
a: 2,
b: 3,
c: 4,
d: 5,
e: 6,
f: 7,
}
};
}};
}
test_case!(i8);
test_case!(i16);
test_case!(i32);
test_case!(i64);
test_case!(i128);
test_case!(isize);
}