Skip to content

Commit

Permalink
[git-packetline] the first very failing test…
Browse files Browse the repository at this point in the history
…and the beginning of something wonderful: implementations of poll_* of
futures.
  • Loading branch information
Byron committed May 14, 2021
1 parent 727ad97 commit 0220bca
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions git-packetline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ bstr = { version = "0.2.13", default-features = false, features = ["std"] }
futures-io = { version = "0.3.15", optional = true }

[dev-dependencies]
futures-lite = "1.11.3"
git-odb = { version = "^0.15.0", path = "../git-odb" }
33 changes: 33 additions & 0 deletions git-packetline/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ impl<T> Writer<T> {
self
}
}
// #[cfg(all(not(feature = "blocking-io"), feature = "async-io"))]
mod async_io {
use crate::{Writer, MAX_DATA_LEN, U16_HEX_BYTES};
use futures_io::AsyncWrite;
use std::{
io,
pin::Pin,
task::{Context, Poll},
};

impl<T: AsyncWrite> Writer<T> {
/// Create a new instance from the given `write`
pub fn new(write: T) -> Self {
Writer {
inner: write,
binary: true,
}
}
}
impl<T: AsyncWrite> AsyncWrite for Writer<T> {
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
todo!()
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
todo!()
}

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
todo!()
}
}
}

#[cfg(feature = "blocking-io")]
mod blocking_io {
Expand Down
5 changes: 1 addition & 4 deletions git-packetline/tests/async-packetline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#[cfg(all(feature = "async-io", not(feature = "blocking-io")))]
#[test]
fn to_be_done() {
assert!(true)
}
mod async_io;
1 change: 1 addition & 0 deletions git-packetline/tests/async_io/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod write;
56 changes: 56 additions & 0 deletions git-packetline/tests/async_io/write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use bstr::ByteSlice;
use futures_io::AsyncWrite;
use futures_lite::{future, prelude::*};
use git_packetline::Writer;

//
// const MAX_DATA_LEN: usize = 65516;
// const MAX_LINE_LEN: usize = 4 + MAX_DATA_LEN;
//
// #[test]
// fn each_write_results_in_one_line() -> crate::Result {
// let mut w = Writer::new(Vec::new());
// w.write_all(b"hello")?;
// w.write(b"world!")?;
// assert_eq!(w.inner.as_bstr(), b"0009hello000aworld!".as_bstr());
// Ok(())
// }
//
// #[test]
// fn write_text_and_write_binary() -> crate::Result {
// let mut w = Writer::new(Vec::new()).text_mode();
// w.write_all(b"hello")?;
// w = w.binary_mode();
// w.write(b"world")?;
// assert_eq!(w.inner.as_bstr(), b"000ahello\n0009world".as_bstr());
// Ok(())
// }
//
// #[test]
// fn huge_writes_are_split_into_lines() -> crate::Result {
// let data = {
// let mut v = Vec::new();
// v.resize(MAX_DATA_LEN * 2, 0);
// v
// };
// let mut w = Writer::new(Vec::new());
// w.write(&data)?;
// assert_eq!(w.inner.len(), MAX_LINE_LEN * 2);
// Ok(())
// }
//
#[test]
fn empty_writes_fail_with_error() {
assert_eq!(
future::block_on(async { Writer::new(Vec::new()).write(&[]).await.unwrap_err().to_string() }),
"empty packet lines are not permitted as '0004' is invalid"
);
}
//
// #[test]
// fn nothing_happens_on_into_read() {
// let mut out = Vec::new();
// let w = Writer::new(&mut out);
// drop(w);
// assert!(out.is_empty());
// }
File renamed without changes.

0 comments on commit 0220bca

Please sign in to comment.