Unified · Split
| @@ -13,6 +13,8 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>( · 12 unmodified lines | ||
| 13 | 13 | #[cfg(all(feature = "async-io", not(feature = "blocking-io")))] |
| 14 | 14 | mod async_io; |
| 15 | 15 | #[cfg(all(feature = "async-io", not(feature = "blocking-io")))] |
| 16 | +mod decode; | |
| 17 | +#[cfg(all(feature = "async-io", not(feature = "blocking-io")))] | |
| 16 | 18 | mod encode; |
| 17 | 19 | #[cfg(all(feature = "async-io", not(feature = "blocking-io")))] |
| 18 | 20 | mod write; |
| @@ -13,6 +13,8 @@ pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>( · 12 unmodified lines | ||
| 13 | 13 | #[cfg(feature = "blocking-io")] |
| 14 | 14 | mod blocking; |
| 15 | 15 | #[cfg(feature = "blocking-io")] |
| 16 | +mod decode; | |
| 17 | +#[cfg(feature = "blocking-io")] | |
| 16 | 18 | mod encode; |
| 17 | 19 | #[cfg(feature = "blocking-io")] |
| 18 | 20 | mod write; |
| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | mod streaming { |
| 2 | − use crate::assert_err_display; | |
| 3 | 2 | use bstr::ByteSlice; |
| 4 | 3 | use git_packetline::{ |
| 5 | 4 | decode::{self, streaming, Stream}, |
| 6 | − immutable::Error, | |
| 7 | 5 | Channel, PacketLine, |
| 8 | 6 | }; |
| 9 | 7 | |
| @@ -22,16 +20,6 @@ mod streaming { · 12 unmodified lines | ||
| 22 | 20 | Ok(()) |
| 23 | 21 | } |
| 24 | 22 | |
| 25 | − #[test] | |
| 26 | − fn flush() -> crate::Result { | |
| 27 | − assert_complete(streaming(b"0000someotherstuff"), 4, PacketLine::Flush) | |
| 28 | − } | |
| 29 | − | |
| 30 | − #[test] | |
| 31 | − fn trailing_line_feeds_are_not_removed_automatically() -> crate::Result { | |
| 32 | − assert_complete(streaming(b"0006a\n"), 6, PacketLine::Data(b"a\n")) | |
| 33 | − } | |
| 34 | − | |
| 35 | 23 | #[test] |
| 36 | 24 | fn trailing_line_feeds_are_removed_explicitly_roundtrip() -> crate::Result { |
| 37 | 25 | let line = decode::all_at_once(b"0006a\n")?; |
| @@ -45,47 +33,6 @@ mod streaming { · 7 unmodified lines | ||
| 45 | 33 | Ok(()) |
| 46 | 34 | } |
| 47 | 35 | |
| 48 | − #[test] | |
| 49 | − fn ignore_extra_bytes() -> crate::Result { | |
| 50 | − assert_complete(streaming(b"0006a\nhello"), 6, PacketLine::Data(b"a\n")) | |
| 51 | − } | |
| 52 | − | |
| 53 | − #[test] | |
| 54 | − fn error_on_oversized_line() { | |
| 55 | − assert_err_display( | |
| 56 | − streaming(b"ffff"), | |
| 57 | − "The data received claims to be larger than than the maximum allowed size: got 65535, exceeds 65516", | |
| 58 | − ); | |
| 59 | − } | |
| 60 | − | |
| 61 | − #[test] | |
| 62 | − fn error_on_error_line() -> crate::Result { | |
| 63 | − let line = PacketLine::Data(b"ERR the error"); | |
| 64 | − assert_complete( | |
| 65 | − streaming(b"0011ERR the error-and just ignored because not part of the size"), | |
| 66 | − 17, | |
| 67 | − line, | |
| 68 | − )?; | |
| 69 | − assert_eq!( | |
| 70 | − line.check_error().expect("error to be parsed here"), | |
| 71 | − Error(b"the error") | |
| 72 | − ); | |
| 73 | − Ok(()) | |
| 74 | − } | |
| 75 | − | |
| 76 | − #[test] | |
| 77 | − fn error_on_invalid_hex() { | |
| 78 | − assert_err_display( | |
| 79 | − streaming(b"fooo"), | |
| 80 | − "Failed to decode the first four hex bytes indicating the line length: Invalid character 'o' at position 1", | |
| 81 | − ); | |
| 82 | − } | |
| 83 | − | |
| 84 | − #[test] | |
| 85 | − fn error_on_empty_line() { | |
| 86 | − assert_err_display(streaming(b"0004"), "Received an invalid empty line"); | |
| 87 | − } | |
| 88 | − | |
| 89 | 36 | #[test] |
| 90 | 37 | fn round_trips() -> crate::Result { |
| 91 | 38 | for (line, bytes) in &[ |
| @@ -126,34 +73,4 @@ mod streaming { · 34 unmodified lines | ||
| 126 | 73 | } |
| 127 | 74 | Ok(()) |
| 128 | 75 | } |
| 129 | − | |
| 130 | − mod incomplete { | |
| 131 | − use git_packetline::decode::{self, streaming, Stream}; | |
| 132 | − | |
| 133 | − fn assert_incomplete(res: Result<Stream, decode::Error>, expected_missing: usize) -> crate::Result { | |
| 134 | − match res? { | |
| 135 | − Stream::Complete { .. } => { | |
| 136 | − panic!("expected parsing to be partial, not complete"); | |
| 137 | − } | |
| 138 | − Stream::Incomplete { bytes_needed } => { | |
| 139 | − assert_eq!(bytes_needed, expected_missing); | |
| 140 | − } | |
| 141 | − } | |
| 142 | − Ok(()) | |
| 143 | − } | |
| 144 | − | |
| 145 | − #[test] | |
| 146 | − fn missing_hex_bytes() -> crate::Result { | |
| 147 | − assert_incomplete(streaming(b"0"), 3)?; | |
| 148 | − assert_incomplete(streaming(b"00"), 2)?; | |
| 149 | − Ok(()) | |
| 150 | − } | |
| 151 | − | |
| 152 | − #[test] | |
| 153 | − fn missing_data_bytes() -> crate::Result { | |
| 154 | − assert_incomplete(streaming(b"0005"), 1)?; | |
| 155 | − assert_incomplete(streaming(b"0006a"), 1)?; | |
| 156 | − Ok(()) | |
| 157 | − } | |
| 158 | − } | |
| 159 | 76 | } |
| @@ -0,0 +1,104 @@ | ||
| 1 | +mod streaming { | |
| 2 | + use crate::assert_err_display; | |
| 3 | + use git_packetline::{ | |
| 4 | + decode::{self, streaming, Stream}, | |
| 5 | + immutable::Error, | |
| 6 | + PacketLine, | |
| 7 | + }; | |
| 8 | + | |
| 9 | + fn assert_complete( | |
| 10 | + res: Result<Stream, decode::Error>, | |
| 11 | + expected_consumed: usize, | |
| 12 | + expected_value: PacketLine, | |
| 13 | + ) -> crate::Result { | |
| 14 | + match res? { | |
| 15 | + Stream::Complete { line, bytes_consumed } => { | |
| 16 | + assert_eq!(bytes_consumed, expected_consumed); | |
| 17 | + assert_eq!(line.as_bstr(), expected_value.as_bstr()); | |
| 18 | + } | |
| 19 | + Stream::Incomplete { .. } => panic!("expected parsing to be complete, not partial"), | |
| 20 | + } | |
| 21 | + Ok(()) | |
| 22 | + } | |
| 23 | + | |
| 24 | + #[test] | |
| 25 | + fn flush() -> crate::Result { | |
| 26 | + assert_complete(streaming(b"0000someotherstuff"), 4, PacketLine::Flush) | |
| 27 | + } | |
| 28 | + | |
| 29 | + #[test] | |
| 30 | + fn trailing_line_feeds_are_not_removed_automatically() -> crate::Result { | |
| 31 | + assert_complete(streaming(b"0006a\n"), 6, PacketLine::Data(b"a\n")) | |
| 32 | + } | |
| 33 | + | |
| 34 | + #[test] | |
| 35 | + fn ignore_extra_bytes() -> crate::Result { | |
| 36 | + assert_complete(streaming(b"0006a\nhello"), 6, PacketLine::Data(b"a\n")) | |
| 37 | + } | |
| 38 | + | |
| 39 | + #[test] | |
| 40 | + fn error_on_oversized_line() { | |
| 41 | + assert_err_display( | |
| 42 | + streaming(b"ffff"), | |
| 43 | + "The data received claims to be larger than than the maximum allowed size: got 65535, exceeds 65516", | |
| 44 | + ); | |
| 45 | + } | |
| 46 | + | |
| 47 | + #[test] | |
| 48 | + fn error_on_error_line() -> crate::Result { | |
| 49 | + let line = PacketLine::Data(b"ERR the error"); | |
| 50 | + assert_complete( | |
| 51 | + streaming(b"0011ERR the error-and just ignored because not part of the size"), | |
| 52 | + 17, | |
| 53 | + line, | |
| 54 | + )?; | |
| 55 | + assert_eq!( | |
| 56 | + line.check_error().expect("error to be parsed here"), | |
| 57 | + Error(b"the error") | |
| 58 | + ); | |
| 59 | + Ok(()) | |
| 60 | + } | |
| 61 | + | |
| 62 | + #[test] | |
| 63 | + fn error_on_invalid_hex() { | |
| 64 | + assert_err_display( | |
| 65 | + streaming(b"fooo"), | |
| 66 | + "Failed to decode the first four hex bytes indicating the line length: Invalid character 'o' at position 1", | |
| 67 | + ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + #[test] | |
| 71 | + fn error_on_empty_line() { | |
| 72 | + assert_err_display(streaming(b"0004"), "Received an invalid empty line"); | |
| 73 | + } | |
| 74 | + | |
| 75 | + mod incomplete { | |
| 76 | + use git_packetline::decode::{self, streaming, Stream}; | |
| 77 | + | |
| 78 | + fn assert_incomplete(res: Result<Stream, decode::Error>, expected_missing: usize) -> crate::Result { | |
| 79 | + match res? { | |
| 80 | + Stream::Complete { .. } => { | |
| 81 | + panic!("expected parsing to be partial, not complete"); | |
| 82 | + } | |
| 83 | + Stream::Incomplete { bytes_needed } => { | |
| 84 | + assert_eq!(bytes_needed, expected_missing); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + Ok(()) | |
| 88 | + } | |
| 89 | + | |
| 90 | + #[test] | |
| 91 | + fn missing_hex_bytes() -> crate::Result { | |
| 92 | + assert_incomplete(streaming(b"0"), 3)?; | |
| 93 | + assert_incomplete(streaming(b"00"), 2)?; | |
| 94 | + Ok(()) | |
| 95 | + } | |
| 96 | + | |
| 97 | + #[test] | |
| 98 | + fn missing_data_bytes() -> crate::Result { | |
| 99 | + assert_incomplete(streaming(b"0005"), 1)?; | |
| 100 | + assert_incomplete(streaming(b"0006a"), 1)?; | |
| 101 | + Ok(()) | |
| 102 | + } | |
| 103 | + } | |
| 104 | +} | |