|
impl Arbitrary for Proto { |
|
fn arbitrary<G: Gen>(g: &mut G) -> Self { |
|
use Protocol::*; |
|
match u8::arbitrary(g) % 26 { |
|
// TODO: Add Protocol::Quic |
|
0 => Proto(Dccp(Arbitrary::arbitrary(g))), |
|
1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))), |
|
2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))), |
|
3 => Proto(Dns6(Cow::Owned(SubString::arbitrary(g).0))), |
|
4 => Proto(Http), |
|
5 => Proto(Https), |
|
6 => Proto(Ip4(Ipv4Addr::arbitrary(g))), |
|
7 => Proto(Ip6(Ipv6Addr::arbitrary(g))), |
|
8 => Proto(P2pWebRtcDirect), |
|
9 => Proto(P2pWebRtcStar), |
|
10 => Proto(P2pWebSocketStar), |
|
11 => Proto(Memory(Arbitrary::arbitrary(g))), |
|
// TODO: impl Arbitrary for Multihash: |
|
12 => Proto(P2p(multihash( |
|
"QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", |
|
))), |
|
13 => Proto(P2pCircuit), |
|
14 => Proto(Quic), |
|
15 => Proto(Sctp(Arbitrary::arbitrary(g))), |
|
16 => Proto(Tcp(Arbitrary::arbitrary(g))), |
|
17 => Proto(Udp(Arbitrary::arbitrary(g))), |
|
18 => Proto(Udt), |
|
19 => Proto(Unix(Cow::Owned(SubString::arbitrary(g).0))), |
|
20 => Proto(Utp), |
|
21 => Proto(Ws("/".into())), |
|
22 => Proto(Wss("/".into())), |
|
23 => { |
|
let a = iter::repeat_with(|| u8::arbitrary(g)) |
|
.take(10) |
|
.collect::<Vec<_>>() |
|
.try_into() |
|
.unwrap(); |
|
Proto(Onion(Cow::Owned(a), std::cmp::max(1, u16::arbitrary(g)))) |
|
} |
|
24 => { |
|
let a: [u8; 35] = iter::repeat_with(|| u8::arbitrary(g)) |
|
.take(35) |
|
.collect::<Vec<_>>() |
|
.try_into() |
|
.unwrap(); |
|
Proto(Onion3((a, std::cmp::max(1, u16::arbitrary(g))).into())) |
|
} |
|
25 => Proto(Tls), |
|
_ => panic!("outside range"), |
|
} |
|
} |
|
} |
Arbitraryimplementation seems to be missing some enum variants.Protocolhas30variants.Arbitraryimplementation generates25.Ideally this would be fixed by removing the need to list every
Protocolvariant. Though I can not think of a clean way of doing that. Simply updating theArbitraryimplementation seems fine for now.rust-multiaddr/tests/lib.rs
Lines 88 to 139 in 1cfb923