1use mz_proto::{RustType, TryFromProtoError};
13use proptest::prelude::Strategy;
14use url::Url;
15
16include!(concat!(env!("OUT_DIR"), "/mz_repr.url.rs"));
17
18impl RustType<ProtoUrl> for Url {
19 fn into_proto(&self) -> ProtoUrl {
20 ProtoUrl {
21 url: self.to_string(),
22 }
23 }
24
25 fn from_proto(proto: ProtoUrl) -> Result<Self, TryFromProtoError> {
26 Ok(proto.url.parse()?)
27 }
28}
29
30pub fn any_url() -> impl Strategy<Value = Url> {
31 r"(http|https)://[a-z][a-z0-9]{0,10}/?([a-z0-9]{0,5}/?){0,3}".prop_map(|s| s.parse().unwrap())
32}
33
34#[cfg(test)]
35mod tests {
36 use mz_ore::assert_ok;
37 use mz_proto::protobuf_roundtrip;
38 use proptest::prelude::*;
39
40 use super::*;
41
42 proptest! {
43 #![proptest_config(ProptestConfig::with_cases(4096))]
44
45 #[mz_ore::test]
46 #[cfg_attr(miri, ignore)] fn url_protobuf_roundtrip(expect in any_url() ) {
48 let actual = protobuf_roundtrip::<_, ProtoUrl>(&expect);
49 assert_ok!(actual);
50 assert_eq!(actual.unwrap(), expect);
51 }
52 }
53}