🏡 index : ~doyle/packfile.git

author Jordan Doyle <jordan@doyle.la> 2023-07-04 20:29:43.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-07-04 20:29:43.0 +00:00:00
commit
4caaf60a7e74100bacf10953da312afb71e3d239 [patch]
tree
af9b5920919683ddc50517a738efdd7ad7d49d25
parent
33d76f2ceb837f673e2a74768c8cf2dc7032c072
download
4caaf60a7e74100bacf10953da312afb71e3d239.tar.gz

Cover remaining lines while we're at it



Diff

 src/codec.rs       | 13 ++++++++++++-
 src/packet_line.rs |  2 +-
 src/util.rs        | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/codec.rs b/src/codec.rs
index 78af676..244f660 100644
--- a/src/codec.rs
+++ b/src/codec.rs
@@ -94,9 +94,20 @@ impl codec::Decoder for GitCodec {

#[cfg(test)]
mod test {
    use crate::PktLine;
    use bytes::{Bytes, BytesMut};
    use std::fmt::Write;
    use tokio_util::codec::Decoder;
    use tokio_util::codec::{Decoder, Encoder};

    #[test]
    fn encode() {
        let mut bytes = BytesMut::new();
        super::Encoder
            .encode(PktLine::Data(&[1, 2, 3, 4]), &mut bytes)
            .unwrap();

        assert_eq!(bytes.to_vec(), b"0008\x01\x02\x03\x04");
    }

    #[test]
    fn decode() {
diff --git a/src/packet_line.rs b/src/packet_line.rs
index 1a37c10..40c8c9f 100644
--- a/src/packet_line.rs
+++ b/src/packet_line.rs
@@ -69,7 +69,7 @@ mod test {
    #[test]
    fn test_pkt_line() {
        let mut buffer = BytesMut::new();
        super::PktLine::Data(b"agent=git/2.32.0\n")
        super::PktLine::from("agent=git/2.32.0\n")
            .encode_to(&mut buffer)
            .unwrap();
        assert_eq!(buffer.as_ref(), b"0015agent=git/2.32.0\n");
diff --git a/src/util.rs b/src/util.rs
index 7375df2..6df9967 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -5,12 +5,18 @@ use std::{
    sync::Arc,
};

#[derive(Debug, Hash, PartialEq, Eq)]
#[derive(Debug, Hash, Eq)]
pub enum ArcOrCowStr {
    Arc(Arc<str>),
    Cow(Cow<'static, str>),
}

impl PartialEq<ArcOrCowStr> for ArcOrCowStr {
    fn eq(&self, other: &ArcOrCowStr) -> bool {
        **self == **other
    }
}

impl From<Arc<str>> for ArcOrCowStr {
    fn from(v: Arc<str>) -> Self {
        Self::Arc(v)
@@ -57,3 +63,36 @@ impl Display for ArcOrCowStr {
        std::fmt::Display::fmt(&**self, f)
    }
}

#[cfg(test)]
mod test {
    mod arc_or_cow_str {
        use crate::util::ArcOrCowStr;
        use std::borrow::Cow;
        use std::sync::Arc;

        #[test]
        fn from_arc() {
            assert_eq!(
                ArcOrCowStr::from(Arc::from("hello world".to_string())),
                "hello world".into()
            );
        }

        #[test]
        fn from_cow() {
            assert_eq!(
                ArcOrCowStr::from(Cow::Borrowed("hello world")),
                "hello world".into()
            );
        }

        #[test]
        fn from_string() {
            assert_eq!(
                ArcOrCowStr::from("hello world".to_string()),
                "hello world".into()
            );
        }
    }
}