-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dj8yf0μl
committed
Oct 8, 2024
1 parent
8c9124d
commit e70919c
Showing
6 changed files
with
163 additions
and
28 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipaddr_vec_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
3, | ||
0, | ||
0, | ||
0, | ||
0, | ||
192, | ||
168, | ||
0, | ||
1, | ||
1, | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
1, | ||
254, | ||
128, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
10 changes: 10 additions & 0 deletions
10
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv4_addr_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
192, | ||
168, | ||
0, | ||
1, | ||
] |
11 changes: 11 additions & 0 deletions
11
...h/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv4_addr_roundtrip_enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
0, | ||
192, | ||
168, | ||
0, | ||
1, | ||
] |
22 changes: 22 additions & 0 deletions
22
borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv6_addr_roundtrip.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
23 changes: 23 additions & 0 deletions
23
...h/tests/roundtrip/snapshots/tests__roundtrip__test_ip_addr__ipv6_addr_roundtrip_enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
source: borsh/tests/roundtrip/test_ip_addr.rs | ||
expression: encoded | ||
--- | ||
[ | ||
1, | ||
32, | ||
1, | ||
13, | ||
184, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
0, | ||
1, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,55 @@ | ||
|
||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; | ||
|
||
macro_rules! test_ip_roundtrip { | ||
($test_name:ident, $original:expr) => { | ||
#[test] | ||
fn $test_name() { | ||
let original = $original; | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
let decoded = borsh::from_slice::<IpAddr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
}; | ||
#[test] | ||
fn test_ipv4_addr_roundtrip_enum() { | ||
let original = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<IpAddr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
test_ip_roundtrip!(test_ipv4_addr_roundtrip, IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1))); | ||
test_ip_roundtrip!(test_ipv6_addr_roundtrip, IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1))); | ||
#[test] | ||
fn test_ipv4_addr_roundtrip() { | ||
let original = Ipv4Addr::new(192, 168, 0, 1); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Ipv4Addr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
macro_rules! test_ipaddr_vec_roundtrip { | ||
($test_name:ident, $original:expr) => { | ||
#[test] | ||
fn $test_name() { | ||
let original = $original; | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
let decoded = borsh::from_slice::<Vec<IpAddr>>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
}; | ||
#[test] | ||
fn test_ipv6_addr_roundtrip_enum() { | ||
let original = IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<IpAddr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
test_ipaddr_vec_roundtrip!(test_ip_addr_vec_roundtrip, vec![ | ||
IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)), | ||
]); | ||
#[test] | ||
fn test_ipv6_addr_roundtrip() { | ||
let original = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1); | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Ipv6Addr>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} | ||
|
||
#[test] | ||
fn test_ipaddr_vec_roundtrip() { | ||
let original = vec![ | ||
IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)), | ||
IpAddr::V6(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)), | ||
]; | ||
let encoded = borsh::to_vec(&original).expect("Serialization failed"); | ||
#[cfg(feature = "std")] | ||
insta::assert_debug_snapshot!(encoded); | ||
let decoded = borsh::from_slice::<Vec<IpAddr>>(&encoded).expect("Deserialization failed"); | ||
assert_eq!(original, decoded); | ||
} |