Debian Codegraph @

src/stream/write/tests.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/;
3
4 use craterust-analyzer cargo zstd 0.13.3 crate/::streamrust-analyzer cargo zstd 0.13.3 stream/::decode_allrust-analyzer cargo zstd 0.13.3 stream/functions/decode_all().;
5 use craterust-analyzer cargo zstd 0.13.3 crate/::streamrust-analyzer cargo zstd 0.13.3 stream/::writerust-analyzer cargo zstd 0.13.3 stream/write/::{Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#, Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#};
6
7 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
8 fn test_cyclerust-analyzer cargo zstd 0.13.3 stream/write/tests/test_cycle().() {
9 let input = b"Abcdefghabcdefgh";
10
11 let buffer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
12 let mut encoder = Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]new().(buffer, 1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
13 encoder.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
14 let encoded = encoder.finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]finish().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]into_inner().();
15
16 // println!("Encoded: {:?}", encoded);
17
18 let buffer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
19 let mut decoder = Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]new().(buffer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
20 decoder.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&encoded).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
21 decoder.flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]flush().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
22 let decoded = decoder.into_innerrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]into_inner().().into_innerrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]into_inner().();
23
24 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(input, &decoded[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
25 }
26
•27 /*
28 /// Test that flush after a partial write works successfully without
29 /// corrupting the frame. This test is in this module because it checks
30 /// internal implementation details.
31 #[test]
32 fn test_partial_write_flush() {
33 let input = vec![b'b'; 128 * 1024];
34 let mut z = setup_partial_write(&input);
35
36 // flush shouldn't corrupt the stream
37 z.flush().unwrap();
38
39 let buf = z.finish().unwrap().into_inner();
40 assert_eq!(&decode_all(&buf[..]).unwrap(), &input);
41 }
42
43 /// Test that finish after a partial write works successfully without
44 /// corrupting the frame. This test is in this module because it checks
45 /// internal implementation details.
46 #[test]
47 fn test_partial_write_finish() {
48 let input = vec![b'b'; 128 * 1024];
49 let z = setup_partial_write(&input);
50
51 // finish shouldn't corrupt the stream
52 let buf = z.finish().unwrap().into_inner();
53 assert_eq!(&decode_all(&buf[..]).unwrap(), &input);
54 }
55
56 fn setup_partial_write(input_data: &[u8]) -> Encoder<PartialWrite<Vec<u8>>> {
57 let buf =
58 PartialWrite::new(Vec::new(), iter::repeat(PartialOp::Limited(1)));
59 let mut z = Encoder::new(buf, 1).unwrap();
60
61 // Fill in enough data to make sure the buffer gets written out.
62 z.write(input_data).unwrap();
63
64 {
65 let inner = &mut z.writer;
66 // At this point, the internal buffer in z should have some data.
67 assert_ne!(inner.offset(), inner.buffer().len());
68 }
69
70 z
•71 }*/