forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderive_protobuf_eq.rs
88 lines (76 loc) · 1.96 KB
/
derive_protobuf_eq.rs
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
#![recursion_limit = "512"]
use asn1rs::prelude::*;
#[derive(ProtobufEq)]
pub struct SimpleStruct {
maybe_some_number: Option<u64>,
}
#[test]
pub fn test_none_is_eq_to_zero() {
assert!(SimpleStruct {
maybe_some_number: None,
}
.protobuf_eq(&SimpleStruct {
maybe_some_number: Some(0),
}))
}
#[test]
pub fn test_none_is_non_eq_to_one() {
assert!(!SimpleStruct {
maybe_some_number: None,
}
.protobuf_eq(&SimpleStruct {
maybe_some_number: Some(1),
}))
}
#[test]
pub fn test_one_is_eq_to_one() {
assert!(SimpleStruct {
maybe_some_number: Some(1),
}
.protobuf_eq(&SimpleStruct {
maybe_some_number: Some(1),
}))
}
#[test]
pub fn test_two_is_non_eq_to_one() {
assert!(!SimpleStruct {
maybe_some_number: Some(2),
}
.protobuf_eq(&SimpleStruct {
maybe_some_number: Some(1),
}))
}
#[derive(ProtobufEq)]
pub struct TupleStruct(Option<u64>);
#[test]
pub fn test_tuple_struct() {
assert!(TupleStruct(None).protobuf_eq(&TupleStruct(Some(0))));
assert!(TupleStruct(Some(0)).protobuf_eq(&TupleStruct(Some(0))));
assert!(!TupleStruct(Some(1)).protobuf_eq(&TupleStruct(Some(0))));
}
#[derive(ProtobufEq)]
pub enum DataEnum {
Abc(u64),
Def(Option<u64>),
Ghi(TupleStruct),
}
#[test]
pub fn test_data_enum() {
assert!(DataEnum::Def(None).protobuf_eq(&DataEnum::Def(Some(0))));
assert!(DataEnum::Def(Some(0)).protobuf_eq(&DataEnum::Def(Some(0))));
assert!(!DataEnum::Def(Some(1)).protobuf_eq(&DataEnum::Def(Some(0))));
assert!(!DataEnum::Abc(1).protobuf_eq(&DataEnum::Ghi(TupleStruct(None))));
}
#[derive(ProtobufEq)]
pub enum SimpleEnum {
Abc,
Def,
Ghi,
}
#[test]
pub fn test_simple_enum() {
assert!(SimpleEnum::Abc.protobuf_eq(&SimpleEnum::Abc));
assert!(SimpleEnum::Def.protobuf_eq(&SimpleEnum::Def));
assert!(SimpleEnum::Ghi.protobuf_eq(&SimpleEnum::Ghi));
assert!(!SimpleEnum::Abc.protobuf_eq(&SimpleEnum::Ghi));
}