-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexpose.rs
More file actions
93 lines (76 loc) · 1.93 KB
/
expose.rs
File metadata and controls
93 lines (76 loc) · 1.93 KB
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
#![allow(unused_imports)]
use assert_unordered::{assert_eq_unordered, assert_eq_unordered_sort};
use std::f64::consts::PI;
use std::hash::Hash;
use std::{
collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList},
fmt::Debug,
num::Wrapping,
};
use structdiff::{Difference, StructDiff};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "nanoserde")]
use nanoserde::{DeBin, SerBin};
#[test]
fn test_expose() {
#[derive(Debug, PartialEq, Clone, Difference)]
#[difference(expose)]
struct Example {
field1: f64,
}
let first = Example { field1: 0.0 };
let second = Example { field1: PI };
for diff in first.diff(&second) {
match diff {
ExampleStructDiffEnum::field1(v) => {
dbg!(&v);
}
}
}
for diff in first.diff_ref(&second) {
match diff {
ExampleStructDiffEnumRef::field1(v) => {
dbg!(&v);
}
}
}
}
#[test]
fn test_expose_rename() {
#[derive(Debug, PartialEq, Clone, Difference)]
#[difference(expose = "Cheese")]
struct Example {
field1: f64,
}
let first = Example { field1: 0.0 };
let second = Example { field1: PI };
for diff in first.diff(&second) {
match diff {
Cheese::field1(_v) => {}
}
}
for diff in first.diff_ref(&second) {
match diff {
CheeseRef::field1(_v) => {}
}
}
}
#[test]
fn test_expose_enum() {
#[derive(Debug, Clone, PartialEq, Difference)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "nanoserde", derive(SerBin, DeBin))]
#[difference(expose)]
pub enum Test {
A,
B(u32),
}
let first = Test::A;
let second = Test::B(1);
for diff in first.diff(&second) {
match diff {
TestStructDiffEnum::Replace(_) => {}
}
}
}