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(-)
@@ -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() {
@@ -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");
@@ -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()
);
}
}
}