Debian Codegraph @

tests/common/mod.rs

raw symbols SCIP
1 // Copyright (c) 2023 Harry [Majored] [[email protected]]
2 // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
3
4 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::readrust-analyzer cargo async_zip 0.0.18 base/read/::memrust-analyzer cargo async_zip 0.0.18 base/read/mem/;
5 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::readrust-analyzer cargo async_zip 0.0.18 base/read/::seekrust-analyzer cargo async_zip 0.0.18 base/read/seek/;
6 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::writerust-analyzer cargo async_zip 0.0.18 base/write/::ZipFileWriterrust-analyzer cargo async_zip 0.0.18 base/write/ZipFileWriter#;
7 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#;
8 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#;
9 use futures_literust-analyzer cargo futures-lite 2.1.0 crate/::iorust-analyzer cargo futures-lite 2.1.0 io/::AsyncWriteExtrust-analyzer cargo futures-lite 2.1.0 io/AsyncWriteExt#;
10 use tokiorust-analyzer cargo tokio 1.25.0 crate/::fsrust-analyzer cargo tokio 1.25.0 fs/::Filerust-analyzer cargo tokio 1.25.0 fs/file/File#;
11 use tokiorust-analyzer cargo tokio 1.25.0 crate/::iorust-analyzer cargo tokio 1.25.0 io/::BufReaderrust-analyzer cargo tokio 1.25.0 io/util/buf_reader/BufReader#;
12 use tokio_utilrust-analyzer cargo tokio-util 0.7.4 crate/::compatrust-analyzer cargo tokio-util 0.7.4 compat/::TokioAsyncReadCompatExtrust-analyzer cargo tokio-util 0.7.4 compat/TokioAsyncReadCompatExt#;
13
14 const FOLDER_PREFIXrust-analyzer cargo async_zip 0.0.18 common/FOLDER_PREFIX.: &str = "tests/test_inputs";
15
16 const FILE_LISTrust-analyzer cargo async_zip 0.0.18 common/FILE_LIST.: &[&str] = &[
17 "sample_data/alpha/back_to_front.txt",
18 "sample_data/alpha/front_to_back.txt",
19 "sample_data/numeric/forward.txt",
20 "sample_data/numeric/reverse.txt",
21 ];
22
23 pub async fn compress_to_memrust-analyzer cargo async_zip 0.0.18 common/compress_to_mem().(compress: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
24 let mut bytes = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(10_000);
25 let mut writer = ZipFileWriterrust-analyzer cargo async_zip 0.0.18 base/write/ZipFileWriter#::newrust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]new().(&mut bytes);
26
27 for fname in FILE_LISTrust-analyzer cargo async_zip 0.0.18 common/FILE_LIST. {
28 let content = tokiorust-analyzer cargo tokio 1.25.0 crate/::fsrust-analyzer cargo tokio 1.25.0 fs/::readrust-analyzer cargo tokio 1.25.0 fs/read/read().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{FOLDER_PREFIX}/{fname}")).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
29 let opts = ZipEntryBuilderrust-analyzer cargo async_zip 0.0.18 entry/builder/ZipEntryBuilder#::newrust-analyzer cargo async_zip 0.0.18 entry/builder/impl#[ZipEntryBuilder]new().(fname.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), compress);
30
31 let mut entry_writer = writer.write_entry_streamrust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]write_entry_stream().(opts).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
32 entry_writer.write_allrust-analyzer cargo futures-lite 2.1.0 io/AsyncWriteExt#write_all().(&content).rust-analyzer cargo futures-lite 2.1.0 io/impl#[`WriteAllFuture<'_, W>`][Future]poll().awaitrust-analyzer cargo futures-lite 2.1.0 io/impl#[`WriteAllFuture<'_, W>`][Future]poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
33 entry_writer.closerust-analyzer cargo async_zip 0.0.18 base/write/entry_stream/impl#[`EntryStreamWriter<'b, W>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
34 }
35 writer.closerust-analyzer cargo async_zip 0.0.18 base/write/impl#[`ZipFileWriter<W>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
36 bytes
37 }
38
39 #[cfg(feature = "tokio-fs")]
40 pub async fn check_decompress_fsrust-analyzer cargo async_zip 0.0.18 common/check_decompress_fs().(fname: &str) {
41 use async_ziprust-analyzer cargo async_zip 0.0.18 crate/::tokiorust-analyzer cargo async_zip 0.0.18 tokio/::readrust-analyzer cargo async_zip 0.0.18 tokio/read/::fsrust-analyzer cargo async_zip 0.0.18 tokio/read/fs/;
42 let zip = fsrust-analyzer cargo async_zip 0.0.18 tokio/read/fs/::ZipFileReaderrust-analyzer cargo async_zip 0.0.18 tokio/read/fs/ZipFileReader#::newrust-analyzer cargo async_zip 0.0.18 tokio/read/fs/impl#[ZipFileReader]new().(fname).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
43 let zip_entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = zip.filerust-analyzer cargo async_zip 0.0.18 tokio/read/fs/impl#[ZipFileReader]file().().entriesrust-analyzer cargo async_zip 0.0.18 file/impl#[ZipFile]entries().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
44 for (idx, entry) in zip_entries.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().() {
45 // TODO: resolve unwrap usage
46 if entry.dirrust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]dir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() {
47 continue;
48 }
49 // TODO: resolve unwrap usage
50 let fname = entry.filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().as_strrust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]as_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
52 let mut reader = zip.reader_with_entryrust-analyzer cargo async_zip 0.0.18 tokio/read/fs/impl#[ZipFileReader]reader_with_entry().(idx).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
53 let _ = reader.read_to_string_checkedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]read_to_string_checked().(&mut output).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
54 let fs_file = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{FOLDER_PREFIX}/{fname}");
55 let expected = tokiorust-analyzer cargo tokio 1.25.0 crate/::fsrust-analyzer cargo tokio 1.25.0 fs/::read_to_stringrust-analyzer cargo tokio 1.25.0 fs/read_to_string/read_to_string().(fs_file).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
56 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, expected, "for {fname}, expect zip data to match file data");
57 }
58 }
59
60 pub async fn check_decompress_seekrust-analyzer cargo async_zip 0.0.18 common/check_decompress_seek().(fname: &str) {
61 let file = BufReaderrust-analyzer cargo tokio 1.25.0 io/util/buf_reader/BufReader#::newrust-analyzer cargo tokio 1.25.0 io/util/buf_reader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo tokio 1.25.0 fs/file/File#::openrust-analyzer cargo tokio 1.25.0 fs/file/impl#[File]open().(fname).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
62 let mut file_compat = file.compatrust-analyzer cargo tokio-util 0.7.4 compat/TokioAsyncReadCompatExt#compat().();
63 let mut zip = seekrust-analyzer cargo async_zip 0.0.18 base/read/seek/::ZipFileReaderrust-analyzer cargo async_zip 0.0.18 base/read/seek/ZipFileReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/seek/impl#[`ZipFileReader<R>`]new().(&mut file_compat).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
64 let zip_entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = zip.filerust-analyzer cargo async_zip 0.0.18 base/read/seek/impl#[`ZipFileReader<R>`]file().().entriesrust-analyzer cargo async_zip 0.0.18 file/impl#[ZipFile]entries().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
65 for (idx, entry) in zip_entries.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().() {
66 // TODO: resolve unwrap usage
67 if entry.dirrust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]dir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() {
68 continue;
69 }
70 // TODO: resolve unwrap usage
71 let fname = entry.filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().as_strrust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]as_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
72 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
73 let mut reader = zip.reader_with_entryrust-analyzer cargo async_zip 0.0.18 base/read/seek/impl#[`ZipFileReader<R>`]reader_with_entry().(idx).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
74 let _ = reader.read_to_string_checkedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]read_to_string_checked().(&mut output).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
75 let fs_file = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("tests/test_inputs/{fname}");
76 let expected = tokiorust-analyzer cargo tokio 1.25.0 crate/::fsrust-analyzer cargo tokio 1.25.0 fs/::read_to_stringrust-analyzer cargo tokio 1.25.0 fs/read_to_string/read_to_string().(fs_file).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, expected, "for {fname}, expect zip data to match file data");
78 }
79 }
80
81 pub async fn check_decompress_memrust-analyzer cargo async_zip 0.0.18 common/check_decompress_mem().(zip_data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) {
82 let zip = memrust-analyzer cargo async_zip 0.0.18 base/read/mem/::ZipFileReaderrust-analyzer cargo async_zip 0.0.18 base/read/mem/ZipFileReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]new().(zip_data).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
83 let zip_entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = zip.filerust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]file().().entriesrust-analyzer cargo async_zip 0.0.18 file/impl#[ZipFile]entries().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
84 for (idx, entry) in zip_entries.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().() {
85 // TODO: resolve unwrap usage
86 if entry.dirrust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]dir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() {
87 continue;
88 }
89 // TODO: resolve unwrap usage
90 let fname = entry.filenamerust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]filename().().as_strrust-analyzer cargo async_zip 0.0.18 string/impl#[ZipString]as_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
91 let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
92 let mut reader = zip.reader_with_entryrust-analyzer cargo async_zip 0.0.18 base/read/mem/impl#[ZipFileReader]reader_with_entry().(idx).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
93 let _ = reader.read_to_string_checkedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]read_to_string_checked().(&mut output).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
94 let fs_file = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{FOLDER_PREFIX}/{fname}");
95 let expected = tokiorust-analyzer cargo tokio 1.25.0 crate/::fsrust-analyzer cargo tokio 1.25.0 fs/::read_to_stringrust-analyzer cargo tokio 1.25.0 fs/read_to_string/read_to_string().(fs_file).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
96 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, expected, "for {fname}, expect zip data to match file data");
97 }
98 }