| 1 | // Copyright (c) The buf-list Contributors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | // Property-based tests for Cursor. |
| 5 | |
| 6 | use craterust-analyzer cargo buf-list 1.1.2 crate/::BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#; |
| 7 | use anyhowrust-analyzer cargo anyhow 1.0.70 crate/::{Contextrust-analyzer cargo anyhow 1.0.70 Context#, Resultrust-analyzer cargo anyhow 1.0.70 Result#, bailrust-analyzer cargo anyhow 1.0.70 macros/bail!, ensurerust-analyzer cargo anyhow 1.0.70 ensure/}; |
| 8 | use bytesrust-analyzer cargo bytes 1.3.0 crate/::{Bufrust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#, Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#}; |
| 9 | use proptestrust-analyzer cargo proptest 1.1.0 crate/::preluderust-analyzer cargo proptest 1.1.0 prelude/::*; |
| 10 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 11 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, |
| 12 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#}, |
| 13 | }; |
| 14 | use test_strategyrust-analyzer cargo test-strategy 0.3.0 crate/::{Arbitraryrust-analyzer cargo test-strategy 0.3.0 Arbitrary:, proptestrust-analyzer cargo test-strategy 0.3.0 proptest:}; |
| 15 | |
| 16 | /// Assert that buf_list's cursor behaves identically to std::io::Cursor. |
| 17 | #[proptestrust-analyzer cargo test-strategy 0.3.0 proptest:] |
| 18 | fn proptest_cursor_opsrust-analyzer cargo buf-list 1.1.2 cursor/tests/proptest_cursor_ops().( |
| 19 | #[strategyrust-analyzer cargo test-strategy 0.3.0 strategy:(buf_list_strategyrust-analyzer cargo buf-list 1.1.2 cursor/tests/buf_list_strategy().())] buf_listrust-analyzer cargo buf-list 1.1.2 cursor/tests/_ProptestCursorOpsArgs#buf_list.: BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#, |
| 20 | #[strategyrust-analyzer cargo test-strategy 0.3.0 strategy:(cursor_ops_strategyrust-analyzer cargo buf-list 1.1.2 cursor/tests/cursor_ops_strategy().())] opsrust-analyzer cargo buf-list 1.1.2 cursor/tests/_ProptestCursorOpsArgs#ops.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CursorOprust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#>, |
| 21 | ) { |
| 22 | let bytes = buf_list.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Clone]clone().().copy_to_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]copy_to_bytes().(buf_list.remainingrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Buf]remaining().()); |
| 23 | let mut buf_list_cursor = craterust-analyzer cargo buf-list 1.1.2 crate/::Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#::newrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]new().(&buf_list); |
| 24 | let mut oracle_cursor = 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#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(bytes.as_refrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes][`AsRef<[u8]>`]as_ref().()); |
| 25 | |
| 26 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("\n**** start!"); |
| 27 | |
| 28 | for (index, cursor_op) in ops.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 29 | // apply_and_compare prints out the rest of the line. |
| 30 | eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!("** index {}, operation {:?}: ", index, cursor_op); |
| 31 | cursor_op |
| 32 | .apply_and_comparerust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]apply_and_compare().(&mut buf_list_cursor, &mut oracle_cursor) |
| 33 | .with_contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().(|| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("for index {}", index)) |
| 34 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 35 | } |
| 36 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("**** success"); |
| 37 | } |
| 38 | |
| 39 | fn buf_list_strategyrust-analyzer cargo buf-list 1.1.2 cursor/tests/buf_list_strategy().() -> impl Strategyrust-analyzer cargo proptest 1.1.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.1.0 strategy/traits/Strategy#Value# = BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#> { |
| 40 | proprust-analyzer cargo proptest 1.1.0 prelude/prop/::collectionrust-analyzer cargo proptest 1.1.0 collection/::vecrust-analyzer cargo proptest 1.1.0 collection/vec().(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::collectionrust-analyzer cargo proptest 1.1.0 collection/::vecrust-analyzer cargo proptest 1.1.0 collection/vec().(anyrust-analyzer cargo proptest 1.1.0 arbitrary/traits/any().::<u8>(), 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#128), 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#32) |
| 41 | .prop_maprust-analyzer cargo proptest 1.1.0 strategy/traits/Strategy#prop_map().(|chunks| chunks.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Bytesrust-analyzer cargo bytes 1.3.0 bytes/Bytes#::fromrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes][`From<Vec<u8>>`]from().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 42 | } |
| 43 | |
| 44 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Arbitraryrust-analyzer cargo test-strategy 0.3.0 Arbitrary:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 45 | enum CursorOprust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp# { |
| 46 | SetPositionrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SetPosition#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 47 | SeekStartrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekStart#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 48 | SeekEndrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekEnd#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 49 | SeekCurrentrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekCurrent#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 50 | Readrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#Read#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 51 | ReadVectoredrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#ReadVectored#( |
| 52 | #[strategy(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::collectionrust-analyzer cargo proptest 1.1.0 collection/::vecrust-analyzer cargo proptest 1.1.0 collection/vec().(anyrust-analyzer cargo proptest 1.1.0 arbitrary/traits/any().::<proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#>(), 0..8))] |
| 53 | Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#>, |
| 54 | ), |
| 55 | ReadExactrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#ReadExact#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 56 | // fill_buf can't be tested here because oracle is a contiguous block. Instead, we check its |
| 57 | // return value separately. |
| 58 | Consumerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#Consume#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 59 | // Buf trait operations |
| 60 | BufChunkrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufChunk#, |
| 61 | BufAdvancerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufAdvance#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 62 | BufChunksVectoredrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufChunksVectored#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 63 | BufCopyToBytesrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufCopyToBytes#(proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#), |
| 64 | BufGetU8rust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU8#, |
| 65 | BufGetU64rust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU64#, |
| 66 | BufGetU64Lerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU64Le#, |
| 67 | // No need to test futures03 imps since they're simple wrappers around the main imps. |
| 68 | #[cfg(feature = "tokio1")] |
| 69 | PollReadrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead# { |
| 70 | capacityrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead#capacity.: proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#, |
| 71 | filledrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead#filled.: proprust-analyzer cargo proptest 1.1.0 prelude/prop/::samplerust-analyzer cargo proptest 1.1.0 sample/::Indexrust-analyzer cargo proptest 1.1.0 sample/Index#, |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | impl CursorOprust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp# { |
| 76 | fn apply_and_comparerust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]apply_and_compare().( |
| 77 | self, |
| 78 | // The "mut" here is used in the branches corresponding to optional features. |
| 79 | #[allow(unused_mut)] mut buf_list: &mut craterust-analyzer cargo buf-list 1.1.2 crate/::Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#<&BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#>, |
| 80 | #[allow(unused_mut)] mut oracle: &mut 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#<&[u8]>, |
| 81 | ) -> Resultrust-analyzer cargo anyhow 1.0.70 Result#<()> { |
| 82 | let num_bytes = buf_list.get_refrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]get_ref().().num_bytesrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]num_bytes().(); |
| 83 | match self { |
| 84 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::SetPositionrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SetPosition#(index) => { |
| 85 | // Allow going past the end of the list a bit. |
| 86 | let index = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4) as u64; |
| 87 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("set position: {}", index); |
| 88 | |
| 89 | buf_list.set_positionrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]set_position().(index); |
| 90 | oracle.set_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]set_position().(index); |
| 91 | } |
| 92 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::SeekStartrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekStart#(index) => { |
| 93 | // Allow going past the end of the list a bit. |
| 94 | let style = SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4) as u64); |
| 95 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("style: {:?}", style); |
| 96 | |
| 97 | let buf_list_res = buf_list.seekrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 98 | let oracle_res = oracle.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 99 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 100 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 101 | } |
| 102 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::SeekEndrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekEnd#(index) => { |
| 103 | // Allow going past the beginning and end of the list a bit. |
| 104 | let index = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2) as i64; |
| 105 | let style = SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#End#(index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4) as i64); |
| 106 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("style: {:?}", style); |
| 107 | |
| 108 | let buf_list_res = buf_list.seekrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 109 | let oracle_res = oracle.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 110 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 111 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 112 | } |
| 113 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::SeekCurrentrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#SeekCurrent#(index) => { |
| 114 | let index = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2) as i64; |
| 115 | // Center the index at roughly 0. |
| 116 | let style = SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().(num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4) as i64); |
| 117 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("style: {:?}", style); |
| 118 | |
| 119 | let buf_list_res = buf_list.seekrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 120 | let oracle_res = oracle.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Seek]seek().(style); |
| 121 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 122 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 123 | } |
| 124 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::Readrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#Read#(index) => { |
| 125 | let buf_size = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 126 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_size: {}", buf_size); |
| 127 | |
| 128 | // Must initialize the whole vec here so &mut returns the whole buffer -- can't use |
| 129 | // with_capacity! |
| 130 | let mut buf_list_buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; buf_size]; |
| 131 | let mut oracle_buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; buf_size]; |
| 132 | |
| 133 | let buf_list_res = buf_list.readrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Read]read().(&mut buf_list_buf); |
| 134 | let oracle_res = oracle.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Read]read().(&mut oracle_buf); |
| 135 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 136 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 137 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!(buf_list_buf == oracle_buf, "read buffer matches"); |
| 138 | } |
| 139 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::ReadVectoredrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#ReadVectored#(indexes) => { |
| 140 | // Build a bunch of IoSliceMuts. |
| 141 | let mut buf_list_vecs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = indexes |
| 142 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 143 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| { |
| 144 | // Must initialize the whole vec here so &mut returns the whole buffer -- can't |
| 145 | // use with_capacity! |
| 146 | let buf_size = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes); |
| 147 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; buf_size] |
| 148 | }) |
| 149 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 150 | let mut oracle_vecs = buf_list_vecs.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 151 | |
| 152 | let mut buf_list_slices: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = buf_list_vecs |
| 153 | .iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() |
| 154 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSliceMut<'a>`]new().(v)) |
| 155 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 156 | let mut oracle_slices: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = |
| 157 | oracle_vecs.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSliceMut<'a>`]new().(v)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 158 | |
| 159 | let buf_list_res = buf_list.read_vectoredrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Read]read_vectored().(&mut buf_list_slices); |
| 160 | let oracle_res = oracle.read_vectoredrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Read]read_vectored().(&mut oracle_slices); |
| 161 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 162 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 163 | |
| 164 | // Also check that the slices read match exactly. |
| 165 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 166 | buf_list_vecs == oracle_vecs, |
| 167 | "read vecs didn't match: buf_list: {:?} == oracle: {:?}", |
| 168 | buf_list_vecs, |
| 169 | oracle_vecs |
| 170 | ); |
| 171 | } |
| 172 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::ReadExactrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#ReadExact#(index) => { |
| 173 | let buf_size = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 174 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_size: {}", buf_size); |
| 175 | |
| 176 | // Must initialize the whole vec here so &mut returns the whole buffer -- can't use |
| 177 | // with_capacity! |
| 178 | let mut buf_list_buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; buf_size]; |
| 179 | let mut oracle_buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; buf_size]; |
| 180 | |
| 181 | let buf_list_res = buf_list.read_exactrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Read]read_exact().(&mut buf_list_buf); |
| 182 | let oracle_res = oracle.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Read]read_exact().(&mut oracle_buf); |
| 183 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 184 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("operation result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 185 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!(buf_list_buf == oracle_buf, "read buffer matches"); |
| 186 | } |
| 187 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::Consumerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#Consume#(index) => { |
| 188 | let amt = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 189 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("amt: {}", amt); |
| 190 | |
| 191 | buf_list.consumerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][BufRead]consume().(amt); |
| 192 | oracle.consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][BufRead]consume().(amt); |
| 193 | } |
| 194 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufChunkrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufChunk# => { |
| 195 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_chunk"); |
| 196 | |
| 197 | let buf_list_chunk = buf_list.chunkrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]chunk().(); |
| 198 | let oracle_chunk = oracle.chunkrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]chunk().(); |
| 199 | |
| 200 | // We can't directly compare chunks because BufList returns one |
| 201 | // segment at a time while oracle returns the entire remaining |
| 202 | // buffer. Instead, verify that: |
| 203 | // |
| 204 | // 1. is_empty matches for both chunks. |
| 205 | // 2. Both start with the same data (buf_list's chunk is a prefix of oracle's) |
| 206 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 207 | buf_list_chunk.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() == oracle_chunk.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 208 | "chunk emptiness didn't match: buf_list is_empty {} == oracle is_empty {}", |
| 209 | buf_list_chunk.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 210 | oracle_chunk.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() |
| 211 | ); |
| 212 | |
| 213 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buf_list_chunk.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 214 | // Verify buf_list's chunk is a prefix of oracle's chunk |
| 215 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 216 | oracle_chunk.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(buf_list_chunk), |
| 217 | "buf_list chunk is not a prefix of oracle chunk" |
| 218 | ); |
| 219 | } |
| 220 | } |
| 221 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufAdvancerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufAdvance#(index) => { |
| 222 | let amt = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 223 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_advance: {}", amt); |
| 224 | |
| 225 | // Skip if already past the end, as the oracle's Buf impl has a debug assertion |
| 226 | // that checks position even when advancing by 0 |
| 227 | if buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 || amt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 && oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 228 | // Cap the advance amount to the remaining bytes to avoid |
| 229 | // hitting the debug assertion in std::io::Cursor's Buf |
| 230 | // impl. While the Buf trait doesn't require this, the |
| 231 | // oracle has a debug_assert that panics if we try to |
| 232 | // advance past the end. |
| 233 | let amt = amt.minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().()); |
| 234 | buf_list.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(amt); |
| 235 | oracle.advancerust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`std::io::Cursor<T>`][Buf]advance().(amt); |
| 236 | } else { |
| 237 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" skipping: cursor past end"); |
| 238 | } |
| 239 | } |
| 240 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufChunksVectoredrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufChunksVectored#(index) => { |
| 241 | let num_iovs = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes); |
| 242 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_chunks_vectored: {} iovs", num_iovs); |
| 243 | |
| 244 | // First verify remaining() matches |
| 245 | let buf_list_remaining = buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 246 | let oracle_remaining = oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 247 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 248 | buf_list_remaining == oracle_remaining, |
| 249 | "chunks_vectored: remaining didn't match before \ |
| 250 | calling chunks_vectored: buf_list {} == oracle {}", |
| 251 | buf_list_remaining, |
| 252 | oracle_remaining |
| 253 | ); |
| 254 | |
| 255 | let mut buf_list_iovs = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); num_iovs]; |
| 256 | let mut oracle_iovs = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); num_iovs]; |
| 257 | |
| 258 | let buf_list_filled = buf_list.chunks_vectoredrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]chunks_vectored().(&mut buf_list_iovs); |
| 259 | let oracle_filled = oracle.chunks_vectoredrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]chunks_vectored().(&mut oracle_iovs); |
| 260 | |
| 261 | // We can't directly compare filled counts or total bytes |
| 262 | // because BufList may have multiple chunks while the oracle |
| 263 | // (std::io::Cursor) is contiguous. When there are fewer iovs |
| 264 | // than chunks, BufList will only fill what it can, while oracle |
| 265 | // fills everything into one iov. |
| 266 | // |
| 267 | // Instead, we verify that: |
| 268 | // 1. Both returned at least some data if there are bytes |
| 269 | // remaining |
| 270 | // 2. The data that was returned matches (buf_list's data is a |
| 271 | // prefix of oracle's data) |
| 272 | let buf_list_bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = buf_list_iovs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#buf_list_filled]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 273 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 274 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|iov| iov.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().().iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().()) |
| 275 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 276 | let oracle_bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = oracle_iovs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#oracle_filled]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 277 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 278 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|iov| iov.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().().iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().()) |
| 279 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 280 | |
| 281 | if buf_list_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && num_iovs rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 282 | // If there are bytes remaining and iovs available, should |
| 283 | // return some data. |
| 284 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 285 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buf_list_bytes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 286 | "chunks_vectored should return some data \ |
| 287 | when remaining = {buf_list_remaining} > 0 \ |
| 288 | and num_iovs = {num_iovs} > 0" |
| 289 | ); |
| 290 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 291 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().oracle_bytes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 292 | "oracle chunks_vectored should return some data \ |
| 293 | when remaining > 0 and num_iovs > 0" |
| 294 | ); |
| 295 | |
| 296 | // Verify that buf_list's data matches the beginning of |
| 297 | // oracle's data. |
| 298 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 299 | oracle_bytes.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(&buf_list_bytes), |
| 300 | "buf_list chunks_vectored data should match beginning \ |
| 301 | of oracle data" |
| 302 | ); |
| 303 | |
| 304 | // Verify that all iovs up to buf_list_filled are non-empty. |
| 305 | for (i, iov) in buf_list_iovs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#buf_list_filled]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 306 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 307 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().iov.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 308 | "buf_list iov at index {i} should be non-empty", |
| 309 | ); |
| 310 | } |
| 311 | } else if buf_list_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 312 | // If no bytes remaining, should return no data |
| 313 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 314 | buf_list_bytes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && oracle_bytes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 315 | "chunks_vectored should return no data when \ |
| 316 | remaining == 0" |
| 317 | ); |
| 318 | } |
| 319 | // If num_iovs == 0, we can't check anything since no iovs were |
| 320 | // provided. All we're doing is ensuring that buf_list doesn't |
| 321 | // panic. |
| 322 | } |
| 323 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufCopyToBytesrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufCopyToBytes#(index) => { |
| 324 | let len = index.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 325 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_copy_to_bytes: {}", len); |
| 326 | |
| 327 | // copy_to_bytes can panic if len > remaining, so check first |
| 328 | let buf_list_remaining = buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 329 | let oracle_remaining = oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 330 | |
| 331 | if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().buf_list_remaining && len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().oracle_remaining { |
| 332 | let buf_list_bytes = buf_list.copy_to_bytesrust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#copy_to_bytes().(len); |
| 333 | let oracle_bytes = oracle.copy_to_bytesrust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#copy_to_bytes().(len); |
| 334 | |
| 335 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!(buf_list_bytes == oracle_bytes, "copy_to_bytes didn't match"); |
| 336 | } else { |
| 337 | // Both should panic, so just skip this operation |
| 338 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" skipping: len {} > remaining {}", len, buf_list_remaining); |
| 339 | } |
| 340 | } |
| 341 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufGetU8rust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU8# => { |
| 342 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_get_u8"); |
| 343 | |
| 344 | if buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 && oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 { |
| 345 | let buf_list_val = buf_list.get_u8rust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u8().(); |
| 346 | let oracle_val = oracle.get_u8rust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u8().(); |
| 347 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 348 | buf_list_val == oracle_val, |
| 349 | "get_u8 didn't match: buf_list {} == oracle {}", |
| 350 | buf_list_val, |
| 351 | oracle_val |
| 352 | ); |
| 353 | } else { |
| 354 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" skipping: not enough bytes remaining"); |
| 355 | } |
| 356 | } |
| 357 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufGetU64rust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU64# => { |
| 358 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_get_u64"); |
| 359 | |
| 360 | if buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 && oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 { |
| 361 | let buf_list_val = buf_list.get_u64rust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u64().(); |
| 362 | let oracle_val = oracle.get_u64rust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u64().(); |
| 363 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 364 | buf_list_val == oracle_val, |
| 365 | "get_u64 didn't match: buf_list {} == oracle {}", |
| 366 | buf_list_val, |
| 367 | oracle_val |
| 368 | ); |
| 369 | } else { |
| 370 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" skipping: not enough bytes remaining"); |
| 371 | } |
| 372 | } |
| 373 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::BufGetU64Lerust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#BufGetU64Le# => { |
| 374 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("buf_get_u64_le"); |
| 375 | |
| 376 | if buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 && oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 { |
| 377 | let buf_list_val = buf_list.get_u64_lerust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u64_le().(); |
| 378 | let oracle_val = oracle.get_u64_lerust-analyzer cargo bytes 1.3.0 buf/buf_impl/Buf#get_u64_le().(); |
| 379 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 380 | buf_list_val == oracle_val, |
| 381 | "get_u64_le didn't match: buf_list {} == oracle {}", |
| 382 | buf_list_val, |
| 383 | oracle_val |
| 384 | ); |
| 385 | } else { |
| 386 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" skipping: not enough bytes remaining"); |
| 387 | } |
| 388 | } |
| 389 | #[cfg(feature = "tokio1")] |
| 390 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::PollReadrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead# { capacityrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead#capacity., filledrust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#PollRead#filled. } => { |
| 391 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#, pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#, taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#}; |
| 392 | use tokiorust-analyzer cargo tokio 1.6.1 crate/::iorust-analyzer cargo tokio 1.6.1 io/::{AsyncReadrust-analyzer cargo tokio 1.6.1 io/async_read/AsyncRead#, ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#}; |
| 393 | |
| 394 | let capacity = capacity.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().num_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().4); |
| 395 | let mut buf_list_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().(); capacity]; |
| 396 | let mut oracle_vec = buf_list_vec.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().(); |
| 397 | |
| 398 | let mut buf_list_buf = ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#::uninitrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]uninit().(&mut buf_list_vec); |
| 399 | |
| 400 | // Fill up the first bytes of the vector. This uses capacity + 1 so that we can |
| 401 | // sometimes fill up the whole buffer. |
| 402 | let filled_index = filled.indexrust-analyzer cargo proptest 1.1.0 sample/impl#[Index]index().(capacity rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 403 | let fill_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; filled_index]; |
| 404 | buf_list_buf.put_slicerust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]put_slice().(&fill_vec); |
| 405 | |
| 406 | let mut oracle_buf = ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#::uninitrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]uninit().(&mut oracle_vec); |
| 407 | oracle_buf.put_slicerust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]put_slice().(&fill_vec); |
| 408 | |
| 409 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("capacity: {}, filled_index: {}", capacity, filled_index); |
| 410 | |
| 411 | let waker = dummy_wakerrust-analyzer cargo dummy-waker 1.1.0 crate/::dummy_wakerrust-analyzer cargo dummy-waker 1.1.0 dummy_waker().(); |
| 412 | let mut context = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#::from_wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]from_waker().(&waker); |
| 413 | let mut buf_list_pinned = Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(buf_list); |
| 414 | let buf_list_res = match buf_list_pinned |
| 415 | .as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]as_mut().() |
| 416 | .poll_readrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncRead]poll_read().(&mut context, &mut buf_list_buf) |
| 417 | { |
| 418 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(res) => res, |
| 419 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("buf_list never returns pending"), |
| 420 | }; |
| 421 | |
| 422 | let mut oracle_pinned = Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(oracle); |
| 423 | let oracle_res = match oracle_pinned |
| 424 | .as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]as_mut().() |
| 425 | .poll_readrust-analyzer cargo tokio 1.6.1 io/async_read/impl#[`io::Cursor<T>`][AsyncRead]poll_read().(&mut context, &mut oracle_buf) |
| 426 | { |
| 427 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(res) => res, |
| 428 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("oracle cursor never returns pending"), |
| 429 | }; |
| 430 | |
| 431 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list_res, oracle_res) |
| 432 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("result didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 433 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 434 | buf_list_buf.filledrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]filled().() == oracle_buf.filledrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]filled().(), |
| 435 | "filled section didn't match" |
| 436 | ); |
| 437 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 438 | buf_list_buf.remainingrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]remaining().() == oracle_buf.remainingrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]remaining().(), |
| 439 | "remaining count didn't match" |
| 440 | ); |
| 441 | |
| 442 | // Put buf_list and oracle back into their original places. |
| 443 | buf_list = buf_list_pinned.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<&'a mut T>`]get_mut().(); |
| 444 | oracle = oracle_pinned.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<&'a mut T>`]get_mut().(); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // Check general properties: remaining and has_remaining are the same. |
| 449 | let buf_list_remaining = buf_list.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 450 | let oracle_remaining = oracle.remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]remaining().(); |
| 451 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 452 | buf_list_remaining == oracle_remaining, |
| 453 | "remaining didn't match: buf_list {} == oracle {}", |
| 454 | buf_list_remaining, |
| 455 | oracle_remaining |
| 456 | ); |
| 457 | |
| 458 | let buf_list_has_remaining = buf_list.has_remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]has_remaining().(); |
| 459 | let oracle_has_remaining = oracle.has_remainingrust-analyzer cargo bytes 1.3.0 buf/buf_impl/impl#[`&mut T`][Buf]has_remaining().(); |
| 460 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 461 | buf_list_has_remaining == oracle_has_remaining, |
| 462 | "has_remaining didn't match: buf_list {} == oracle {}", |
| 463 | buf_list_has_remaining, |
| 464 | oracle_has_remaining |
| 465 | ); |
| 466 | |
| 467 | // Also check that the position is the same. |
| 468 | let buf_list_position = buf_list.positionrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]position().(); |
| 469 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 470 | buf_list_position == oracle.positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]position().(), |
| 471 | "position didn't match: buf_list position {} == oracle position {}", |
| 472 | buf_list_position, |
| 473 | oracle.positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]position().(), |
| 474 | ); |
| 475 | Selfrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]::assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().(buf_list.stream_positionrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Seek]stream_position().(), oracle.stream_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Seek]stream_position().()) |
| 476 | .contextrust-analyzer cargo anyhow 1.0.70 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("stream position didn't match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 477 | |
| 478 | // Check that fill_buf returns an empty slice iff it is actually empty. |
| 479 | let fill_buf = buf_list.fill_bufrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][BufRead]fill_buf().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("fill_buf never errors"); |
| 480 | if buf_list_position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().num_bytes as u64 { |
| 481 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 482 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fill_buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 483 | "fill_buf cannot be empty since buf_list.position {} < num_bytes {}", |
| 484 | buf_list_position, |
| 485 | num_bytes, |
| 486 | ); |
| 487 | } else { |
| 488 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 489 | fill_buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().(), |
| 490 | "fill_buf must be empty since buf_list.position {} >= num_bytes {}", |
| 491 | buf_list_position, |
| 492 | num_bytes, |
| 493 | ) |
| 494 | } |
| 495 | |
| 496 | // Finally, check that the internal invariants are upheld. |
| 497 | buf_list.assert_invariantsrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]assert_invariants().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 498 | |
| 499 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 500 | } |
| 501 | |
| 502 | fn assert_io_result_eqrust-analyzer cargo buf-list 1.1.2 cursor/tests/impl#[CursorOp]assert_io_result_eq().<T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#>( |
| 503 | buf_list_res: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<T>, |
| 504 | oracle_res: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<T>, |
| 505 | ) -> Resultrust-analyzer cargo anyhow 1.0.70 Result#<()> { |
| 506 | match (buf_list_res, oracle_res) { |
| 507 | (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf_list_value), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(oracle_value)) => { |
| 508 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 509 | buf_list_value == oracle_value, |
| 510 | "value didn't match: buf_list value {:?} == oracle value {:?}", |
| 511 | buf_list_value, |
| 512 | oracle_value |
| 513 | ); |
| 514 | } |
| 515 | (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf_list_value), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(oracle_err)) => { |
| 516 | bailrust-analyzer cargo anyhow 1.0.70 macros/bail!!( |
| 517 | "BufList value Ok({:?}) is not the same as oracle error Err({})", |
| 518 | buf_list_value, |
| 519 | oracle_err, |
| 520 | ); |
| 521 | } |
| 522 | (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(buf_list_err), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(oracle_value)) => { |
| 523 | bailrust-analyzer cargo anyhow 1.0.70 macros/bail!!( |
| 524 | "BufList error ({}) is not the same as oracle value ({:?})", |
| 525 | buf_list_err, |
| 526 | oracle_value |
| 527 | ) |
| 528 | } |
| 529 | (Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(buf_list_err), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(oracle_err)) => { |
| 530 | // The kinds should match. |
| 531 | ensurerust-analyzer cargo anyhow 1.0.70 macros/ensure!!( |
| 532 | buf_list_err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() == oracle_err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), |
| 533 | "error kind didn't match: buf_list {:?} == oracle {:?}", |
| 534 | buf_list_err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), |
| 535 | oracle_err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() |
| 536 | ); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | fn cursor_ops_strategyrust-analyzer cargo buf-list 1.1.2 cursor/tests/cursor_ops_strategy().() -> impl Strategyrust-analyzer cargo proptest 1.1.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.1.0 strategy/traits/Strategy#Value# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<CursorOprust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#>> { |
| 545 | proprust-analyzer cargo proptest 1.1.0 prelude/prop/::collectionrust-analyzer cargo proptest 1.1.0 collection/::vecrust-analyzer cargo proptest 1.1.0 collection/vec().(anyrust-analyzer cargo proptest 1.1.0 arbitrary/traits/any().::<CursorOprust-analyzer cargo buf-list 1.1.2 cursor/tests/CursorOp#>(), 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#256) |
| 546 | } |
| 547 | |
| 548 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 549 | fn test_cursor_buf_traitrust-analyzer cargo buf-list 1.1.2 cursor/tests/test_cursor_buf_trait().() { |
| 550 | // Create a BufList with multiple chunks |
| 551 | let mut buf_list = BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#::newrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]new().(); |
| 552 | buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&b"hello "[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 553 | buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&b"world"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 554 | buf_list.push_chunkrust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList]push_chunk().(&b"!"[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 555 | |
| 556 | let mut cursor = craterust-analyzer cargo buf-list 1.1.2 crate/::Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#::newrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]new().(buf_list.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Clone]clone().()); |
| 557 | |
| 558 | // Test remaining() |
| 559 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.remainingrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]remaining().(), 12); |
| 560 | |
| 561 | // Test chunk() |
| 562 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.chunkrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunk().(), b"hello "); |
| 563 | |
| 564 | // Test advance() |
| 565 | cursor.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(6); |
| 566 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.remainingrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]remaining().(), 6); |
| 567 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.chunkrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunk().(), b"world"); |
| 568 | |
| 569 | // Advance within the same chunk |
| 570 | cursor.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(3); |
| 571 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.remainingrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]remaining().(), 3); |
| 572 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.chunkrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunk().(), b"ld"); |
| 573 | |
| 574 | // Advance to the next chunk |
| 575 | cursor.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(2); |
| 576 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.remainingrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]remaining().(), 1); |
| 577 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.chunkrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunk().(), b"!"); |
| 578 | |
| 579 | // Advance to the end |
| 580 | cursor.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(1); |
| 581 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.remainingrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]remaining().(), 0); |
| 582 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cursor.chunkrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunk().(), b""); |
| 583 | |
| 584 | // Test chunks_vectored |
| 585 | let mut cursor = craterust-analyzer cargo buf-list 1.1.2 crate/::Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#::newrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]new().(buf_list.clonerust-analyzer cargo buf-list 1.1.2 imp/impl#[BufList][Clone]clone().()); |
| 586 | let mut iovs = [iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); 3]; |
| 587 | let filled = cursor.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunks_vectored().(&mut iovs); |
| 588 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filled, 3); |
| 589 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iovs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().(), b"hello "); |
| 590 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iovs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().(), b"world"); |
| 591 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iovs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().(), b"!"); |
| 592 | |
| 593 | // Test chunks_vectored after advancing |
| 594 | cursor.advancerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]advance().(6); |
| 595 | let mut iovs = [iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); 3]; |
| 596 | let filled = cursor.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunks_vectored().(&mut iovs); |
| 597 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filled, 2); |
| 598 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iovs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().(), b"world"); |
| 599 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(iovs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`[T]`][`AsRef<Self>`]as_ref().(), b"!"); |
| 600 | |
| 601 | // Test chunks_vectored with more iovs than remaining chunks |
| 602 | let cursor2 = craterust-analyzer cargo buf-list 1.1.2 crate/::Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#::newrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]new().(&buf_list); |
| 603 | let mut iovs2 = [iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSlicerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSlice#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSlice<'a>`]new().(&[]); 10]; |
| 604 | let filled2 = cursor2.chunks_vectoredrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Buf]chunks_vectored().(&mut iovs2); |
| 605 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filled2, 3, "Should only fill 3 iovs for 3 chunks"); |
| 606 | let total_bytes: usize = iovs2[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#filled2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|iov| iov.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(); |
| 607 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(total_bytes, 12, "Total bytes should be 12"); |
| 608 | } |